필터 지우기
필터 지우기

Problem with fsolve?

조회 수: 2 (최근 30일)
Domenico Fazzari
Domenico Fazzari 2017년 2월 8일
댓글: Domenico Fazzari 2017년 2월 10일
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

답변 (2개)

John D'Errico
John D'Errico 2017년 2월 8일
편집: John D'Errico 2017년 2월 8일
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.
  댓글 수: 1
Domenico Fazzari
Domenico Fazzari 2017년 2월 10일
Hi John, thanks for the quick reply! I understand your point, but my main question is : why fsolve didn't solve it? I mean, if i change a little my initial guess of the two variables i have total different result! And obviously i don't know what are the most correct initial guess.

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


Torsten
Torsten 2017년 2월 8일
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.
  댓글 수: 1
Domenico Fazzari
Domenico Fazzari 2017년 2월 10일
Hi torsten Since this is taken from an exam, i can't really know what is the best choices for initial guess.That'my problem: fsolve gives me back to total different results by only changing a little the initial guess! I can't understand why.

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

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by