Problem with fsolve?
3 views (last 30 days)
Show older comments
Hi everyone! I'm trying to solve a non linear system of 2eqs,but i can't really find the exact results! (lambda=0.4 Tout=1100) I tried to change options related to intervals, but didn't received good news. I don'r really know where's the mistake,is there someone that can help me? Here's the code:
global P R P=30; %bar R=1.98; %cal/mol*K a0=[0.2,700]; a=fsolve('composizionemarzosistemaletterale',a0); lambdafin=a(1) Toutfin=a(2)
function reattoremarzo=composizionemarzosistemaletterale(a) global P R lambda=a(1); Tout=a(2);
GR1=(-8514+7.71*Tout); % WGS
GR2=(53717-60.25*Tout); % SR
Keq1=exp((-GR1)/(R*Tout));
Keq2=exp((-GR2)/(R*Tout));
reattoremarzo(1)=(P^(2) * (0.8-lambda)*(2.40+lambda)^(3) )/((6.60^(2) * 0.2*(3.20-lambda)))-Keq2; %SR
reattoremarzo(2)=(lambda*(2.40+lambda))/((0.8-lambda)*(3.2-lambda)) - Keq1; %WGS
end
Thanks in advance
0 Comments
Answers (2)
John D'Errico
on 8 Feb 2017
Edited: John D'Errico
on 8 Feb 2017
The answer is that
lambda=0.4, Tout=1100
is NOT the true solution to your equations. You may think it is. But that is wrong. Lets see what happens. I'll use the symbolic toolbox so that I won't need to worry about convergence.
P=30;R=1.98;
syms lambda Tout
GR1=(-8514+7.71*Tout); % WGS
GR2=(53717-60.25*Tout); % SR
Keq1=exp((-GR1)/(R*Tout));
Keq2=exp((-GR2)/(R*Tout));
E1=(P^(2) * (0.8-lambda)*(2.40+lambda)^(3) )/((6.60^(2) * 0.2*(3.20-lambda)))-Keq2; %SR
E2=(lambda*(2.40+lambda))/((0.8-lambda)*(3.2-lambda)) - Keq1; %WGS
result = solve(E1,E2,lambda,Tout)
Warning: Cannot solve symbolically. Returning a numeric approximation instead.
> In solve (line 303)
result =
struct with fields:
lambda: [1×1 sym]
Tout: [1×1 sym]
result.lambda
ans =
0.4023100845011317337437541837291
result.Tout
ans =
1100.5492492829987172462281406487
So 0.4 and 1100 are CLOSE. But the exact solution is not what you think it is. So fsolve is probably working just fine. It is your expected result that is incorrect.
My guess is that you are running afoul of approximate values reported to the command window, but then assuming they were exact.
Torsten
on 8 Feb 2017
The "mistake" is that your initial guess (0.2,700) is too far away from the solution you search for (0.4,1100).
Try an improved initial guess.
Best wishes
Torsten.
See Also
Categories
Find more on Surrogate Optimization 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!