hello, my code has the following error
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)+ ...
the code is the following:
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);
0 commentaires
Réponses (1)
Walter Roberson
le 4 Fév 2022
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;
You would have a problem if solve() does not return exactly one solution, since your destination Tdet(i) requires exactly one solution.
Caution: your solve() call runs to the last ) . You are pasing in an expression to solve() rather than an equation. And then when solve returns, you compare that result to 0, and try to store the result into Tdet(i) . If that worked, you would display the result, after which you would evaluate the symbolic variable X and throw away the result of the evaluation because of the semi-colon. You probably intended solve(expression == 0, X)
4 commentaires
Walter Roberson
le 4 Fév 2022
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
Now at this point, you have a problem. What you expected before to be a numeric vector, T_opt, has had to turn into a cell array T_opt_ . Any given position T_opt_{i} might be 0, 1, 2, or even more values. Testing with other software, I see that solve() should be producing 8 solutions each time -- the equation can be rewritten as the roots of a degree 8 polynomial. You should probably assume that at least half of those solutions will be complex-valued. As the coefficients are entirely real, there will always be an even number of real-valued solutions for the degree 8 polynomial, so even if you were to constrain to eliminate complex-valued solutions, you are going to either get 0 real-valued solutions (which you cannot proceed with) or you are going to get at least 2 real-valued solutions
T_orden = sort(T_opt) ; % 'sort' Ordenar los elementos en orden creciente
And now you want to sort the entries. But complex values cannot really be sorted, and you will have an even number of real-valued solutions per position; how is the code intended to sort lists of values compared to other lists of values?
for i = 1:n
Pos(i) =find(T_orden==T_opt(i)) ;
end
T_order is the sorted result (under some definition of sorting.) If there happen to be no duplicate entries, then the output of that loop and the find() would be the same as what you would get if you took the second element of sort() (which would be less work.) But if there might possibly be duplicate values, then the find() might return more than one value, which would mess up because Pos(i) only has room for one value.
You need to define what you want the outcome of your solve() to be, understanding that solve() will either find 8 solutions or will give up and find no solutions.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!