How will use return conditions in solve function
Show older comments
Hi,
I didnt get the answer for this solution. I get the message "Solutions are only valid under certain conditions.
To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'."while running the program.
can anyone help to get the solution?
clear all
clc
p=3200; Av=400;Ab=25;hv=4;hb=5;a=1500;c=5;
syms d1 d0;
for b=10:10:100
d0=(-8+4*sqrt(2))*(b/a)^2;
d1=(12-7*sqrt(2))*(b/a);
x=((a+b*c)-sqrt(2*hb*Ab*a)*d1)/(2*b+2*sqrt(2*Ab*hb*a)*d0)
Q=sqrt((b*(a-b*c)*Ab+sqrt(2*Ab*hb*a)*Ab*(2*a*d0+b*d1))/(hb*(b+sqrt(2*Ab*hb*a)*d0)))
syms M
m1=((a-b*x)*Av*2*p)/(hv*Q^2*(p-a+b*x));
M=m1;
for n = 2:1:6
if n*(n-1)<=M && n*(n+1)>=M;
x1=n
end
end
Pb=((a-b*x)*(x-c))-(((a-b*x)*Ab)/Q)-((hb*Q)/2)
TPv=(a*c)-(b*c*x)-(((a-b*x)*Av)/(x1*Q))-(((hv*Q)/2)*(x1*(1-(a-b*x)/p)-1+(((2*(a-b*x))/p))))
TPi=(a*x)-(b*(x^2))-(((a-b*x)*(Av+n*Ab)/(n*Q))-((hb*Q)/2)-(((hv*Q)/2)*(n*(1-(a-b*x)/p)-1+((2*(a-b*x))/p))));
TPj=0;
nmin=max(ceil(sqrt((Av*(hb-hv))/(Ab*hv))),1);
nmax=ceil(sqrt((Av*p*(hb-hv)+2*Av*hv*a)/(Ab*hv*(p-a))));
n=nmin
if n>=1
m1=a/b;
m2=-1/b;
m3=2*(Ab+Av/n)*(hb+(n-a)*hv);
m4=2*hv*(Ab+Av/n)*((2-n)*hv)/p;
syms D
S=(m1+2*m2*D-((m3+2*m4*D)/(2*sqrt(m3*D+m4*D^2))));
solve(S,D);
LO=solve(subs(S),'returnconditions', true);
LO=subs(LO);
LO1=LO(1);
if LO1 < a
D1=LO1;
else
D1=a;
end
x=(a-D1)/b
Q= sqrt((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-1)*hv);
m4=2*hv*(Ab+Av/n)*((2-n)*hv)/p;
syms D
S=(m1+2*m2*D-((m3+2*m4*D)/(2*sqrt(m3*D+m4*D^2))));
solve(S,D);
LO=solve(subs(S));
LO=subs(LO);
LO1=LO(1);
if LO1 < a
D1=LO1;
else
D1=a;
end
x=(a-D1)/b
Q=sqrt((2*(a-b*x)*(Ab+Av/n))/(hb+hv*(n*(1-((a-b*x)/p))-1+((2*(a-b*x))/p))))
TPb=((a-b*x)*(x-c))-(((a-b*x)*Ab)/Q)-((hb*Q)/2);
TPv=(a*c)-(b*c*x)-(((a-b*x)*Av)/(n*Q))-(((hv*Q)/2)*(n*(1-(a-b*x)/p))-1+((2*(a-b*x))/p));
TP1=(a*x)-(b*(x^2))-(((a-b*x)*(Av+n*Ab)/(n*Q))-((hb*Q)/2)-(((hv*Q)/2)*(n*(1-(a-b*x)/p)-1+((2*(a-b*x))/p))));
if TP1>TPj
TPj=TP1
TPvj=(TPv/TPi)*TPj
TPbj=(TPb/TPi)*TPj
P1=(TPj-TPi)/TPi*100
else
n=n+1
end
end
end
end
end
end
end
3 Comments
Rik
on 29 Dec 2022
I'm not going to touch barely formatted code that lacks comments. Especially if all variable names are so cryptic the longest one is 3 characters long.
This question also isn't clear to me. What return value should be true? You don't even have a function here.
M
on 29 Dec 2022
Rik
on 29 Dec 2022
Feel free to edit your question to solve these issues.
Answers (1)
Sulaymon Eshkabilov
on 30 Dec 2022
(1) You have employed the solve() fcn for a few times and no output variable was assigned. It is better to use this syntax:
[SOL_D, Params, Conds] = solve(S,D,'ReturnConditions',true);
(2) Yoy are assigning a non-numeric value to a new variable and comparing against numerical value 'a':
LO=subs(LO); % Makes no sense here as "LO" defined above
LO1=LO(1); % Wrong: LO(1) does not exist. LO is a structure variable.
if LO1 < a % Wrong:
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!