"Unable to perform assignment because the left and right sides have a different number of elements"

조회 수: 16 (최근 30일)
Hi, my code has the following error:
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in sym/privsubsasgn (line 1126)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 963)
C = privsubsasgn(L,R,inds{:});
Error in main (line 49)
S(j) = solve(eqn, DegU, 'Real', true);"
My code is as follows:
x = ones(1,26);
alpha = (4*10^-3)/(4.8*10^-2);
[phos_rate] = (0.01:0.001:0.035);
for i = 1:26
inv_phos_rate(i) = x(i)/phos_rate(i);
inv_phos_rate;
end
for i = 1:length(phos_rate)
c1(i) = sqrt(7*(0.1/0.025)*(inv_phos_rate(i))^2);
c2(i) = (((4*10^-4)*((10^-2)/(4.8*(10^-2)*4*(10^-2))))*(1+phos_rate(i)))^-1;
c1;
c2;
end
for j = 1:26
syms DegU
eqn = ((alpha*((c1(j))^2) + DegU^2)/((c1(j))^2 + DegU^2)) - (DegU)/(c2(j)) ==0;
S(j) = solve(eqn, DegU, 'Real', true);
S;
end
plot(phos_rate, S)
Could anybody explain what is going wrong?

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 22일
Hi Ellen,
The issue comes because for one of the equation, there are three roots, but till that iteration, only single root is present in S. To observe the different roots, you can make the following modifications
S{j} = solve(eqn, DegU, 'Real', true); % Replace S(j) with S{j}
S1(j) = S{j}(1);
Placing these lines in the code and then while plotting use S1 instead of S
plot(phos_rate, S1)
Look that S will have one of the roots as 3 x 1 and due to this the error.
Hope this helps.
Regards,
Sriram
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yineth Fernanda Olaya Sedano
Yineth Fernanda Olaya Sedano 2022년 2월 4일
Hi, my code has the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in sym/privsubsasgn (line 1229)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 1060)
C = privsubsasgn(L,R,inds{:});
Error in aa (line 35)
Tdet(i) = solve ((-a(i)/X^2)+((D*h(i))/2)+ ...
My code is as follows:
clc ; clear ; close
format long
% REAPROVISIONAMIENTO CONJUNTO
a = xlsread('Ejemplo_numerico.xlsx','C6:C11') ; %Costo de pedir producto unid
h = xlsread('Ejemplo_numerico.xlsx','D6:D11') ; %Costo de matener inventario
D = xlsread('Ejemplo_numerico.xlsx','E6:E11') ; % Demanda
sg = xlsread('Ejemplo_numerico.xlsx','F6:F11') ; %Desviacion durante el tiempo de entrega
L = xlsread('Ejemplo_numerico.xlsx','G6:G11') ; %Duración del tiempo de entrega
B = xlsread('Ejemplo_numerico.xlsx','H6:H11') ; %Costo de pedido pendiente
A = xlsread('Ejemplo_numerico.xlsx','C12:C12') ; %Costo de pedir
M = xlsread('Ejemplo_numerico.xlsx','I6:I11') ; % Demanda promedio durante el tiempo de entrega
Y = xlsread('Ejemplo_numerico.xlsx','J6:J11') ; % Requerimiento de espacio del producto CT
bn = xlsread('Ejemplo_numerico.xlsx','C30:C30') ; %Costo fijo de almacenamento por adquirir el espacio Sn
cn = xlsread('Ejemplo_numerico.xlsx','C31:C31') ;% Costo variable de almacenamiento%
sn = xlsread('Ejemplo_numerico.xlsx','C29:C29') ;%Espacios de almacenamiento disponible%
%Y2 = xlsread('Ejemplo_numerico.xlsx','F19:F24') ; % Requerimiento de espacio del producto CO
%Q2 = xlsread('Ejemplo_numerico.xlsx','Q25:Q36') ; % Cantidad de pedido CO
%R = xlsread('Ejemplo_numerico.xlsx','S25:S36') ; % Punto de reorden en CO
Zalfha = (-1.3);
syms X;
n = length(a) ;
for i=1:n
Tdet1(i) = sqrt(2*a(i)/D(i)*h(i));
FZ(i) = 1-((Tdet1(i).*((cn.*Y(i))+h(i)))./(B(i))); %((cn.*Y(i).+h(i)).*(Tdet(i)./B(i))) ; % Acumulado
alfa(i) = 1-FZ(i) ; % Nivel de Servicio con Tdet
Z(i) = (norminv(1-alfa(i)/2)) ;
fz(i) = normpdf(Z(i)) ; %%abs(0.5-alfa(i)) ; % Función de densidad normal con Z(Tdet)
Tdet(i) = solve ((-a(i)/X^2)+((D*h(i))/2)+ ...
((Z(i)*sg(i))/(2*sqrt(X+L(i))))+ ...
(sg(i)*fz(i))*((((-B(i))*X^2)- ...
(2*X*B(i)*L(i)))/((2*X^3)*sqrt(X+L(i))))- ...
((sg(i)*Z(i))*(((2*L(i)-X)*(((X)*(cn(i)))*Y(i))+ ...
((X)*h(i))))/(2*sqrt(X+L(i))))+((((cn(i))*Y(i))*sqrt(X+L(i)))/X))== 0,X;
b(i) = sqrt ( Tdet(i) + L(i))* fz(i) ;
b_der_1(i) = fz(i)/(2*sqrt(Tdet(i)+L(i))) + sqrt(Tdet(i) + L(i))*Z(i)*((((cn.*Y(i))+h(i)))./(B(i))) ;
b_der_2(i) = ((Z(i).*((cn.*Y(i))+h(i)))./(B(i).*sqrt(Tdet(i) + L(i)))) - (fz(i))/(4*(Tdet(i)+L(i))^(3/2)) - ((sqrt(Tdet(i) + L(i))*(((cn.*Y(i))+h(i)))^(2))./(((B(i)^(2))*fz(i))));%((sqrt(Tdet(i) + L(i))*(cn.*Y(i)+h(i))^2)/((B(i)^2)*fz(i)));
u(i) = a(i) + B(i)*sg(i)*(b(i)-b_der_1(i)*Tdet(i)+b_der_2(i)*(Tdet(i)^2)/2);
v(i) = D(i)*h(i) + B(i)*sg(i)*b_der_2(i) ;
w(i) = B(i)*sg(i)*(b_der_1(i)-b_der_2(i)*Tdet(i)) ;
T_opt(i) = (sqrt((2*u(i))/v(i))) ;
TC_opt(i) = sqrt(2*u(i)*v(i)) + w(i) ;
Zreal(i) = (h(i)/B(i))*T_opt(i) ;
end
T_orden = sort(T_opt) ; % 'sort' Ordenar los elementos en orden creciente
for i = 1:n
Pos(i) =find(T_orden==T_opt(i)) ;
end
Tj = 0 ;
stop = 0 ;
i = 1 ;
while i <= n % && stop==0
u_orden(i) = (u(Pos(i))) ;
v_orden(i) = (v(Pos(i))) ;
Tj (i) = sqrt((2*(A + sum(u_orden) ))/(sum(v_orden))) ;
if i == 1 && Tj(i) < 0
alerta = 1 ;
else
if i>1 && Tj(i) > Tj(i - 1)
stop = i ;
end
end
i = i + 1 ; % Contador de iteración
end
% stop = n % por si no sirve
Ts = min(Tj) ; % T's
s = find(Ts==Tj) ; % Posicion del Ts
for m = 1 : s
ki(m) = 1 ;
end
for m = s+1 : n
ki(m) = 1 ;
cond1 = 0 ;
cond2 = 0 ;
cond = Tj(m)/ Ts ;
while cond1==0 && cond2==0
Band1 = sqrt((ki(m) - 1)*ki(m)) ;
Band2 = sqrt((ki(m) + 1)*ki(m)) ;
if Band1 <= cond
cond1 = 1 ;
if Band2 >= cond
cond2 = 1 ;
else
cond1 = 0 ;
ki(m) = ki(m) + 1 ;
end
else
ki(m) = ki(m) + 1 ;
end
end
end
SumUK= (sum(u./ki));
SumKV= (sum(ki.*v));
SumW = (sum(w)) ;
T = sqrt(2*(A + SumUK)/SumKV) ;
TC = A./T + SumUK./T +(T./2).*SumKV + SumW + bn + sum(sum(cn*(Y.*((D.*T)+(Z.*sg.*sqrt(T+L))))));
Q1 = (D.*(ki').*T);
costodepedir= A./T ;
costodemantenerinventario= (SumUK./T) +((T./2).*SumKV);
costodepedidopendiente=SumW ;
costofijodealmacenamiento=bn ;
costovariabledealmacenamiento= sum(sum(cn*(Y.*((D.*T)+(Z.*sg.*sqrt(T+L))))));
%uno=sum(sum((Y(i).*Q(i))));
%dos=sum(sum(Y(i).*Z(i).*sg(i)));
%tres=sum(sum(Y(i).*M(i)));
%cuatro=sum(sum(Y2(i).*Q2(i)));
%cinco=sum(sum(Y2(i).*R(i)));
%Respacio= sum(uno)+sum(dos)+sum(cuatro)+sum(cinco)-sum(tres)-Sn-Zalfha;
%Esp1= sum(uno)+sum(dos);

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by