Two equations two unknowns, non-linear Mathematica

399 views Asked by At

I am having trouble obtaining values using the NSolve or Solve features in Mathematica for two non-linear equations in two unknowns. I am sure there must be a method to go about this, but am not sure what it is. Here is where I encounter the problem:

bco2=29.6833
bdec=209.891
aco2=2.75447*10^6
bco2=7.94935*10^7
P=41.4
T=411
R=83.1446

Solve[{P = (R*T)/(vliq - (xco2*bco2 + (1 - xco2)*bdec)) 
- (xco2^2*aco2 + 2*xco2*(1 - xco2)*0.87*Sqrt[aco2*adec] 
+ (1 - xco2)^2*adec)/(vliq*(vliq + (xco2*bco2 + (1 - xco2)*bdec))), 
xco2 = yco2*phivap/(Exp[Log[vliq/(vliq - (xco2*bco2 + (1 - xco2)*bdec))] 
+ bco2/(vliq - (xco2*bco2 + (1 - xco2)*bdec)) 
- (2*(xco2*(aco2 + (1 - 0.13) Sqrt[aco2 + adec])))/(R*T*(xco2*bco2 + (1 - xco2)*bdec))*
Log[(vliq + (xco2*bco2 + (1 - xco2)*bdec))/vliq] + ((xco2^2*aco2 + 
2*xco2*(1 - xco2)*0.87*Sqrt[aco2*adec] + (1 - xco2)^2*adec)*bco2)/(R*
T*(xco2*bco2 + (1 - xco2)*bdec)^2)*(Log[(vliq + (xco2*bco2 + (1 - xco2)*bdec))/vliq]
- (xco2*bco2 + (1 - xco2)*bdec)/(vliq + (xco2*bco2 + (1 - xco2)*bdec))) 
- Log[(P*vliq)/(R*T)]])}, {xco2, vliq}]

I have also tried to use the NSolve feature with no success. I am a bit rusty in mathematica, so if anyone has any insight I would be very much obliged; thank you in advance for your help!

1

There are 1 answers

0
Bill On

You can't use NSolve (or any of the other Nfunctions because you have variables adec, phivap and yco2 which have not been assigned values) unless you are solving for all the variables which haven't been assigned values. If you know the values of those three and just didn't include them then you might be able to successfully use NSolve.

If not then this method often seems to work for complicated functions.

In[1]:= bco2 = 29.6833;
bdec = 209.891;
aco2 = 2.75447*10^6;
bco2 = 7.94935*10^7;
P = 41.4;
T = 411;
R = 83.1446;
NMinimize[{Norm[P - (R*T)/(vliq - (xco2*bco2 + (1 - xco2)*bdec)) - (xco2^2*aco2 + 
  2*xco2*(1 - xco2)*0.87*Sqrt[aco2*adec] + (1 - xco2)^2*adec)/(vliq*(vliq +
  (xco2*bco2 + (1 - xco2)*bdec)))] + Norm[xco2 - yco2*phivap/(Exp[Log[vliq/(vliq-
  (xco2*bco2 + (1 - xco2)*bdec))] + bco2/(vliq - (xco2*bco2 + (1 - xco2)*bdec)) -
  (2*(xco2*(aco2 + (1 - 0.13) Sqrt[aco2 + adec])))/(R*T*(xco2*bco2 + (1 - xco2)*
  bdec))*Log[(vliq + (xco2*bco2 + (1 - xco2)*bdec))/vliq] + ((xco2^2*aco2 +
  2*xco2*(1 - xco2)*0.87*Sqrt[aco2*adec] + (1 - xco2)^2*adec)*bco2)/(R*T*(xco2*
  bco2 + (1 - xco2)*bdec)^2)*(Log[(vliq + (xco2*bco2 + (1 - xco2)*bdec))/vliq] -
  (xco2*bco2 + (1 - xco2)*bdec)/(vliq + (xco2*bco2 + (1 - xco2)*bdec))) -
  Log[(P*vliq)/(R*T)]])]},
  {xco2, vliq, adec, phivap , yco2}]

Out[8]= {0.00652106, {xco2 -> -0.0000130274, vliq -> -0.154973, 
  adec -> -0.0437708, phivap -> 0.45787, yco2 -> 0.271248}}

That works by making the difference of the left hand side and right hand side as small as possible. If your function has some local minima then this might get trapped in one of those. If you have information about where the result might lie then you can add constraints and help it find the appropriate solution.