solve function solution question

18 views (last 30 days)
Max Bernstein
Max Bernstein on 19 Nov 2013
Edited: Walter Roberson on 19 Nov 2013
Hello,
I'm trying to learn how to use the solve function in Matlab to solve a set of chemical equations. The script I have is:
%--------------------------Methane/Air Flame--------------------------%
clear
clc
format short
%Equilibrium Eq.:
%a1CH4+a2(O2+3.76N2)-->b1CH4+b2O2+b3H2O+b4CO2+b5CO+b6N2+b7NO
a1= 1; a2= 2; %Stoich. reactant coefficients
P = 1 ;%Reaction pressure (atm)
T_f = 300;%Temp of reactants (K)
%Define Cp data for each species
R = 8.314; %kJ/(kmol*K);
syms b1 b2 b3 b4 b5 b6 b7 %Assign symbols and species balance
C_bal = b1+b4+b5-a1;
O_bal = 2*b2+b3+2*b4+b5+b7-2*a2;
H_bal = 4*b1+2*b3-4*a1;
N_bal = 2*b6+b7-2*3.76*a2;
T_guess = 2230; %Guess a flame temp (Kelvin)
T_ref = 278; %Reference temp
%Temp in col 1 (K), Kp in col 2
%Define a matrix containing Kp values at 1atm for CO+(1/2)O2-->CO2
Kp_data1 = [1000,1.668E10;1200,5.819E7;1400,1.039E6;1600,5.091E4;...
1800,4.931E3;2000,767.3;2200,168.4;2400,47.82;2600,16.55;...
2800,6.686;3000,3.058;3200,1.546;3400,.847;3600,.4991];
%Define a matrix containing Kp values at 1atm for CH4+2O2-->2H2O+CO2
Kp_data2 = [1000,6.605E41;1200,7.011E34;1400,7.192E29;1600,1.285E26;...
1800,1.545E23;2000,7.06E20;2200,8.523E18;2400,2.134E17;...
2600,9.367E15;2800,6.396E14;3000,6.22E13;3200,8.065E12;...
3400,1.325E12;3600,2.655E11];
%Define a matrix containing Kp values at 1atm for 1/2N2+1/2O2-->NO
Kp_data3 = [1000,0.000086526;1200,0.00053055;1400,0.001938848;...
1600,0.005126104;1800,0.010919411;2000,0.019994129;...
2200,0.03279039;2400,0.049500456;2600,0.070115471;...
2800,0.09445232;3000,0.122221972;3200,0.153067028;...
3400,0.186595428;3600,0.222412657];
%Interpolate to get Kp's @ T_guess
Kp1 = interp1(Kp_data1(:,1),Kp_data1(:,2),T_guess);
Kp2 = interp1(Kp_data2(:,1),Kp_data2(:,2),T_guess);
Kp3 = interp1(Kp_data3(:,1),Kp_data3(:,2),T_guess);
%Now write the Kp equation for the given value of T_guess:
Kp_eqn1=P^(1/2)*(b1/(b5*(b2/(b1+b2+b3+b4+b5+b6))^(1/2)))-Kp1;
Kp_eqn2=(b3^2*b4)/(b1*b2^2)-Kp2;
Kp_eqn3=b7/(b6^(1/2)*b2^(1/2))-Kp3;
%Solves for product composition
[b1a,b2a,b3a,b4a,b5a,b6a,b7a]=solve(C_bal,O_bal,H_bal,N_bal,Kp_eqn1,Kp_eqn2,Kp_eqn3)
%----------------------------------------------------------------------------------------------------------------------------------------%
The results I get for [b1a,b2a,b3a,b4a,b5a,b6a,b7a] are shown:
%----------------------------------------------------%
Warning: Possibly spurious solutions. [solvelib::checkVectorSolutions]
b1a =
0
0.0000024179144550258166102232947681133
0.0000020702194441842669567167335220851
5.2589823796718665112744539449127
-0.00000000000363797880709171295166015625
5.2589787477880096667094925096064
- 0.00000095007025268391503331721850014591 + 0.0000019170204125994420472764169392376*i
- 0.00000095007025268391503331721850014591 - 0.0000019170204125994420472764169392376*i
- 0.0000011038309250021979106933004276048 - 0.0000021612956769096263577713298027198*i
5.2610199126318649658192855896309 - 0.0000018190666552527766027716996418904*i
0.0000022104735132573356016629247004258 - 0.00000021422085039394986536243725435524*i
- 0.0000012936718565036919216087739639832 + 0.0000019146849341027197984834468527285*i
- 0.0000011063184902059169206885839946716 - 0.0000017285911592822624801916573609925*i
- 0.0000011063184902059169206885839946716 + 0.0000017285911592822624801916573609925*i
5.2610199126318649658192855896309 + 0.0000018190666552527766027716996418904*i
- 0.0000011038309250021979106933004276048 + 0.0000021612956769096263577713298027198*i
- 0.0000012936718565036919216087739639832 - 0.0000019146849341027197984834468527285*i
0.0000022104735132573356016629247004258 + 0.00000021422085039394986536243725435524*i
b2a =
0.0023429675073416422748096010764129
0.00000047682751012674399457026721783442
0.00000051528070973011774177824553432772
0.0000000056399919714920373107520076669884
0.0023429675072522693213272759749088
0.0000000056399848343117046408042047165368
- 0.00000026722698066588442361574040065431 + 0.00000043070998053248485498965098651163*i
- 0.00000026722698066588442361574040065431 - 0.00000043070998053248485498965098651163*i
0.00000024848007607467935472904215356049 + 0.00000040590044101935032444095029579792*i
- 0.0000000056426238425021273182729242222762 + 0.0000000000000035730277806046760258750584358438*i
- 0.00000049693784002517627399043733194122 - 0.00000002404024000310309146326015492207*i
- 0.00000022882730904869375246997723536879 + 0.00000043074105317441600692584286835056*i
0.00000024845753953336947373705039807213 + 0.00000045402012994543573397039094845376*i
0.00000024845753953336947373705039807213 - 0.00000045402012994543573397039094845376*i
- 0.0000000056426238425021273182729242222762 - 0.0000000000000035730277806046760258750584358438*i
0.00000024848007607467935472904215356049 - 0.00000040590044101935032444095029579792*i
- 0.00000022882730904869375246997723536879 - 0.00000043074105317441600692584286835056*i
- 0.00000049693784002517627399043733194122 + 0.00000002404024000310309146326015492207*i
b3a =
2.0
1.9999951641710899483667795534105
1.999995859561111631466086566533
-8.5179647593437330225489078898254
2.0000000000072759576141834259033
-8.5179574955760193334189850192129
2.000001900140505367830066634437 - 0.0000038340408251988840945528338784752*i
2.000001900140505367830066634437 + 0.0000038340408251988840945528338784752*i
2.0000022076618500043958213866009 + 0.0000043225913538192527155426596054395*i
- 8.5220398252637299316385711792618 + 0.0000036381333105055532055433992837809*i
1.9999955790529734853287966741506 + 0.00000042844170078789973072487450871048*i
2.0000025873437130073838432175479 - 0.000003829369868205439596966893705457*i
2.000002212636980411833841377168 + 0.0000034571823185645249603833147219851*i
2.000002212636980411833841377168 - 0.0000034571823185645249603833147219851*i
- 8.5220398252637299316385711792618 - 0.0000036381333105055532055433992837809*i
2.0000022076618500043958213866009 - 0.0000043225913538192527155426596054395*i
2.0000025873437130073838432175479 + 0.000003829369868205439596966893705457*i
1.9999955790529734853287966741506 - 0.00000042844170078789973072487450871048*i
b4a =
1.0
1.0000731386507714062576303915577
0.99993569903896144545015571490218
16.776954396905713698590610370693
1.0
16.776928962922073992973100990675
0.99996417862271012516243442662993 - 0.000055328639634179228035642562515252*i
0.99996417862271012516243442662993 + 0.000055328639634179228035642562515252*i
0.9999379385306627352856460191388 - 0.000039936414455866661315229637816986*i
16.783059749176783055042983198954 - 0.000012728064175086274872531004651508*i
1.0000059751704195074092854132101 + 0.000067658679033858609903180895502259*i
1.0000314035071100506460138696212 + 0.00006282049718062092493591246220139*i
1.0000560872714540439533430257735 + 0.000029411125084148070582836201308838*i
1.0000560872714540439533430257735 - 0.000029411125084148070582836201308838*i
16.783059749176783055042983198954 + 0.000012728064175086274872531004651508*i
0.9999379385306627352856460191388 + 0.000039936414455866661315229637816986*i
1.0000314035071100506460138696212 - 0.00006282049718062092493591246220139*i
1.0000059751704195074092854132101 - 0.000067658679033858609903180895502259*i
b5a =
0
-0.00007555656522643207424061485251766
0.000062230741594370282887568364301102
-21.03593677657758020986506431601
0.000000000014551915228366851806640625
-21.035907710710083659682593526736
0.000036771447542558752598890588570648 + 0.000053411619221579785988366145576016*i
0.000036771447542558752598890588570648 - 0.000053411619221579785988366145576016*i
0.000063165300262266912264674161630965 + 0.000042097710132776287673000967619705*i
- 21.044079661808648020862268555738 + 0.000014547130830339051475302703402848*i
- 0.0000081856439327647448870761347889572 - 0.000067444458183464660037818458247904*i
- 0.000030109835253546954092260847196294 - 0.000064735182114723644734395909054118*i
- 0.000054980952963838036422337189496828 - 0.000027682533924865808102644543947845*i
- 0.000054980952963838036422337189496828 + 0.000027682533924865808102644543947845*i
- 21.044079661808648020862268555738 - 0.000014547130830339051475302703402848*i
0.000063165300262266912264674161630965 - 0.000042097710132776287673000967619705*i
- 0.000030109835253546954092260847196294 + 0.000064735182114723644734395909054118*i
- 0.0000081856439327647448870761347889572 + 0.000067444458183464660037818458247904*i
b6a =
7.5223429675071198374780578888021
7.5200334192812132911478944311039
7.5199652594710241764423845605963
7.520003634585049053875661682644
7.5223429675070745403786531824153
7.5199963654190073307340165161686
7.5199832471897534225693435734023 - 0.000030109140455456292233746255679971*i
7.5199832471897534225693435734023 + 0.000030109140455456292233746255679971*i
7.5199708734917949456190437785622 - 0.000016320363271549540796516873908616*i
7.5199999999979702362904358255346 - 0.0000036354321010909447515032769931096*i
7.5199991749370998425249662217807 + 0.000034126630552517126658170843477741*i
7.5200174134340307321671368779943 + 0.000028968962242330798777156903689953*i
7.5200299515710018642215262828131 + 0.000017752469410942864745675977644361*i
7.5200299515710018642215262828131 - 0.000017752469410942864745675977644361*i
7.5199999999979702362904358255346 + 0.0000036354321010909447515032769931096*i
7.5199708734917949456190437785622 + 0.000016320363271549540796516873908616*i
7.5200174134340307321671368779943 - 0.000028968962242330798777156903689953*i
7.5199991749370998425249662217807 - 0.000034126630552517126658170843477741*i
b7a =
-0.0046859350142387512505592894740403
-0.000066838562426582295788862207880872
0.000069481057951647115230878807320785
-0.0000072691700981077513233652880918905
-0.0046859350141481570517498767003417
0.0000072691619853385319669676628626568
0.000033505620493154861312853195371374 + 0.000060218280910912584467492511359942*i
0.000033505620493154861312853195371374 - 0.000060218280910912584467492511359942*i
0.000058253016410108761912442875613427 + 0.000032640726543099081593033747817231*i
0.0000000000040595274191283489308078114742421 + 0.0000072708642021818895030065539862192*i
0.0000016501258003149500675564386766288 - 0.000068253261105034253316341686955481*i
- 0.000034826868061464334273755988581488 - 0.000057937924484661597554313807379905*i
- 0.000059903142003728443052565626271658 - 0.000035504938821885729491351955288722*i
- 0.000059903142003728443052565626271658 + 0.000035504938821885729491351955288722*i
0.0000000000040595274191283489308078114742421 - 0.0000072708642021818895030065539862192*i
0.000058253016410108761912442875613427 - 0.000032640726543099081593033747817231*i
- 0.000034826868061464334273755988581488 + 0.000057937924484661597554313807379905*i
0.0000016501258003149500675564386766288 + 0.000068253261105034253316341686955481*i
%-----------------------------------------------------------------------------------------
I'm just wondering why it says spurious solutions and does this means
[b1a,b2a,b3a,b4a,b5a,b6a,b7a] = [0,0,2,1,0,7.5,0] ??
Why does it have all the decimals and imaginary parts in the solutions?
Thank you.

Answers (1)

Walter Roberson
Walter Roberson on 19 Nov 2013
Edited: Walter Roberson on 19 Nov 2013
[b1a,b2a,b3a,b4a,b5a,b6a,b7a] as [0,0,2,1,0,7.5,0] would mean that there is a likely solution to the equation in which b1 was 0, b2 was 0, b3 was 2, b4 was 1, b5 was 0, b6 was 7.5, and b7 was 0.
The "spurious solutions" is a warning that the symbolic engine recognized that there are round-off difficulties in the calculation that might have led to false solutions being found. You need to substitute the values back into the equations to verify that they really are solutions.
The decimal and imaginary part combinations are algebraic solutions to the question. You did not restrict any variable to being real-valued only.

Community Treasure Hunt

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

Start Hunting!