Solution is not unique because the system is rank-deficient | Solve Function | Syms Variable | Will be very helpful, if you can resolve this pleaseeee
4 次查看(过去 30 天)
显示 更早的评论
I have been trying to resolve this error by using multiple methods but I'm unable to, please help. I have attached the relevant code and the data base. The first part of the code is the one in which I'm trying to collect data, the rest three parts are the supportin functions.
load X
Result = zeros(105,6);
e = 0;
for i = 1:1:105
try
[K1,K2,K3,K4,K5,K6] = Lead_Time(X(i,1),X(i,2),X(i,3),X(i,4),X(i,5),X(i,6),X(i,7));
Result(i,1:6) = [K1,K2,K3,K4,K5,K6];
catch
e = e+1;
error1(e) = i;
end
end
function [Y,Ft1,Ft2,Ft3,Ra2,Ra3] = Lead_Time(Ra1,CVa1,CVa2,CVa3,m1,m2,m3)
[Ra2,Ra3] = Arr_rt(m2,m3,Ra1,CVa1,CVa2,CVa3);
Ft1 = Wait_Time(m1,CVa1,0,0.0625,Ra1,0.4);
Ft2 = Wait_Time(m2,CVa2,0,0.02,Ra2+Ra1,0);
Ft3 = Wait_Time(m3,CVa3,1,0.002,Ra3,1.5);
Is = (Ra1*Ft1) + ((Ra2+Ra1)*Ft2) + (Ra3*Ft3);
Ft = max([Ft1,Ft2,Ft3]);
Y = Is*Ft;
end
function [Ra2,Ra3] = Arr_rt(m2,m3,Ra1,CVa1,CVa2,CVa3)
syms Ra
%CVa2 = CVa1;
%CVa3 = CVa1;
eqn1 = (Wait_Time(m3,CVa3,1,0.002,((Ra1/(Ra+Ra1))*(1/Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0))),1.5))*Ra == 1;
eqn2 = Ra < (m2/(0.05));
eqn3 = ((Ra1+Ra)*(Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0))) > ((Ra1*0.0675)/m3);
eqns = [eqn1 eqn2 eqn3];
Ra = solve(eqns,Ra,'Real',true);
%Ra = vpasolve(eqns,Ra);
Ra2= Ra;
Ra3 = 1/Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0);
Ra3 = (Ra1/(Ra1+Ra))*Ra3;
end
function [Ts] = Wait_Time(m,CVa,CVp,p,Ra,s)
global u pf
pf = ((p.*60) + s)/24;
u = Ra.*pf./m;
Tq = (((CVp^2)+(CVa^2))/2)*pf.*((u.^(sqrt(2*(m+1))-1))/(m*(1-u)));
Ts = Tq+pf;
end
0 个评论
回答(1 个)
Walter Roberson
2024-2-29
You are trying to solve three equations for one variable. Although two of the equations are inequalities, solve() simply gives up when asked to handle more equations than variables.
1 个评论
Walter Roberson
2024-2-29
You can solve the equality and then test whether the solution satisfies the inequalities
load X
Result = zeros(105,6);
e = 0;
for i = 1:1:105
try
[K1,K2,K3,K4,K5,K6] = Lead_Time(X(i,1),X(i,2),X(i,3),X(i,4),X(i,5),X(i,6),X(i,7));
Result(i,1:6) = [K1,K2,K3,K4,K5,K6];
catch ME
e = e+1;
error1(e) = i;
Result(i,1:6) = nan;
disp(ME.message)
end
end
function [Y,Ft1,Ft2,Ft3,Ra2,Ra3] = Lead_Time(Ra1,CVa1,CVa2,CVa3,m1,m2,m3)
[Ra2,Ra3] = Arr_rt(m2,m3,Ra1,CVa1,CVa2,CVa3);
Ft1 = Wait_Time(m1,CVa1,0,0.0625,Ra1,0.4);
Ft2 = Wait_Time(m2,CVa2,0,0.02,Ra2+Ra1,0);
Ft3 = Wait_Time(m3,CVa3,1,0.002,Ra3,1.5);
Is = (Ra1*Ft1) + ((Ra2+Ra1)*Ft2) + (Ra3*Ft3);
Ft = max([Ft1,Ft2,Ft3]);
Y = Is*Ft;
end
function [Ra2,Ra3] = Arr_rt(m2,m3,Ra1,CVa1,CVa2,CVa3)
syms Ra
%CVa2 = CVa1;
%CVa3 = CVa1;
eqn1 = (Wait_Time(m3,CVa3,1,0.002,((Ra1/(Ra+Ra1))*(1/Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0))),1.5))*Ra == 1;
eqn2 = Ra < (m2/(0.05));
eqn3 = ((Ra1+Ra)*(Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0))) > ((Ra1*0.0675)/m3);
eqns = [eqn1 eqn2 eqn3];
Rasol = vpasolve(eqns(1),Ra); % solve(eqns(1),Ra,'Real',true);
Rasol = Rasol(imag(Rasol) == 0);
if isempty(Rasol)
Ra2 = sym(nan);
Ra3 = sym(nan);
fprintf('no real roots\n');
else
successes = [];
for Ra_ = Rasol(:).'
test = vpa(subs(eqns(2:end), Ra, Ra_));
if all(isAlways(test, Unknown="false"))
successes(end+1) = Ra_;
end
end
if isempty(successes)
Ra2 = sym(nan);
Ra3 = sym(nan);
else
if length(successes) > 1
fprintf('got %d successful roots, using first of them\n', length(successes));
successes
else
fprintf('got 1 real root: %g\n', successes);
end
Ra = successes(1);
Ra2 = Ra;
Ra3 = 1/Wait_Time(m2,CVa2,0,0.02,Ra+Ra1,0);
Ra3 = (Ra1/(Ra1+Ra))*Ra3;
end
end
end
function [Ts] = Wait_Time(m,CVa,CVp,p,Ra,s)
global u pf
pf = ((p.*60) + s)/24;
u = Ra.*pf./m;
Tq = (((CVp^2)+(CVa^2))/2)*pf.*((u.^(sqrt(2*(m+1))-1))/(m*(1-u)));
Ts = Tq+pf;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!