How do I use fsolve to solve five linear and two non linear equations
5 views (last 30 days)
Show older comments
Hi all, thanks for taking a look at my problem.
I am working on a bio-energy project and looking to predict the composition of gas leaving my reaction system by solving simultaneous equation, but I'm stuck!
My research so far has led me to using the fsolve function but unfortunately it is unable to provide me with a solution. Any help anybody could give me would be very much appreciated! Sam
syms F Vco Vc Vch Vh Vho Vn;
eq1 = 0== Vco + Vc + Vch - 0.93*F;
eq2 = 0==Vh + Vho + 2*Vch -0.78*F;
eq3 = 0==0.5*Vco + Vc +0.5*Vho -3.82*F;
eq4 = 0==Vn - 5.53*F;
eq5 = 0==Vco + Vc + Vch + Vh + Vho + Vn -1;
eq6 = 0==1.9*Vc - (Vco*Vco);
eq7 = 0==2.617*Vho -(Vh*Vco);
fsolve([eq1,eq2,eq3,eq4,eq5,eq6,eq7],[F==0..100, Vco==0..1, Vc==0..1, Vch==0..1, Vh==0..1, Vho==0..1, Vn==0..1])
0 Comments
Answers (1)
Walter Roberson
on 17 Apr 2016
fsolve() is not for symbolic expressions.
With fsolve() you cannot give ranges of values.
The syntax you use for ranges is not valid anywhere in MATLAB. It is closest to what would be used inside MuPAD (the symbolic engine), but MuPAD would use "=" rather than "==".
You could switch to the symbolic solver:
syms F Vco Vc Vch Vh Vho Vn;
eq1 = 0== Vco + Vc + Vch - 0.93*F;
eq2 = 0==Vh + Vho + 2*Vch -0.78*F;
eq3 = 0==0.5*Vco + Vc +0.5*Vho -3.82*F;
eq4 = 0==Vn - 5.53*F;
eq5 = 0==Vco + Vc + Vch + Vh + Vho + Vn -1;
eq6 = 0==1.9*Vc - (Vco*Vco);
eq7 = 0==2.617*Vho -(Vh*Vco);
vpasolve([eq1,eq2,eq3,eq4,eq5,eq6,eq7], [F, Vco, Vc, Vch, Vh, Vho, Vn], [0, 100; 0, 1; 0, 1; 0, 1; 0, 1; 0, 1; 0, 1])
However, it turns out that there is no solution for that range of values. If you
solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7], [F, Vco, Vc, Vch, Vh, Vho, Vn])
then you can get the exact solutions in terms of roots of a cubic. If you look at the three sets of roots then you will find that in two of the sets, the values of several of the V* have magnitude greater than 1. The third of the solutions almost works, with everything nicely in range except that Vch is negative. It turns out that Vch is negative in two of the three sets of roots, and in the third set of roots Vco and Vh are negative. If we guess that the values must all be positive but that perhaps you were mistaken on limiting them to [0, 1] then it turns out that does not work because there are some negative V* in all three sets.
Possibly if one of the floating point constants were slightly different something consistent could be come up with.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!