How to solve 4 equations with 4 unknowns using matlab

27 views (last 30 days)
Josh
Josh on 21 Nov 2013
Answered: Alex Sha on 12 Oct 2019
I'm attempting to use matlab to solve a set of 4 nonlinear equations with 4 unknowns. This is what I've entered so far, but it keeps saying it cant find a solution. Any suggestions?
mf=.12;
Yfin=.0826;
Kg=(6.19*10^9)*exp(-15098/298);
MW=29;
V=.000268;
P=101325;
R=8315;
M=.1;
N=1.65;
Yoxin=.9174;
AF=16;
Hf=40000000;
Cp=1200;
Tin=298;
eqn1='mf*(Yfin-R1)-Kg*MW*V*((P/R*R2)^(M+N))*(((R1^M)*((.233*R3)^N))/1)'
eqn2='mf*(Yoxin-R1)-(AF)*Kg*MW*V*((P/R*R2)^(M+N))*(((R1^M)*((.233*R3)^N))/1)'
eqn3='1-R1-R3-R4'
eqn4='(R1-Yfin)*Hf+Cp*(R2-Tin)'
sol=fsolve(eqn1,eqn2,eqn3,eqn4,'R1','R2','R3','R4')
  3 Comments
Walter Roberson
Walter Roberson on 21 Nov 2013
The fsolve() syntax you are using would be the syntax for solve(), a symbolic solver, rather than fsolve(), a numeric solver. If you want to use the symbolic solver, you should use
syms R1 R2 R3 R4
and then when you define your equations, do not put in the quotation marks,
eqn1 = mf*(Yfin-R1)-Kg*MW*V*((P/R*R2)^(M+N))*(((R1^M)*((.233*R3)^N))/1);
and so on. And change to solve()

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 21 Nov 2013
I suggest you try to solve it numerically using 'fsolve' rather than symbolically.
  3 Comments
Josh
Josh on 21 Nov 2013
I think I've managed to do it , can you please check ? Thank you very much for your time!!!

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 21 Nov 2013
You will probably not be able to find a meaningful numeric solution. The gradient of the function is very very steep, and outside a very narrow valley of R3 values it goes complex. The width of the range of R3 values that lead to non-complex values is less than eps() of the representable value, so numerically you are always going to end up with complex results if you using "double". You can get meaningful results if you work symbolically with more than 150 digits of precision.
R1 is on the order of 8 * 10^(-12), R2 is on the order of 3051 1/3, R3 is on the order of 8336.5; and because of the constraint that 1-R1-R3-R4 = 0, R4 comes out approximately -8335.5

Alex Sha
Alex Sha on 12 Oct 2019
r1: 0.0269466666666667
r2: 2153.11111111111
r3: 2523.94560037811
r4: -2522.97254704477

Community Treasure Hunt

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

Start Hunting!