Re: Beginner--Help on using FindRoot to solve the system of equations
- To: mathgroup at smc.vnet.net
- Subject: [mg66225] Re: Beginner--Help on using FindRoot to solve the system of equations
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Thu, 4 May 2006 05:21:34 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <e39kql$cud$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
xiaochu at che.utexas.edu wrote: > This is a code to solve vapor-liquid equilibrium by van der Waals Equation of State. > > I don't why this code is not working, please help, thanks very much! > > > (* Name of EOS *) > > EOSName = "Van der Waals"; > > Ttilde = .; > > Dtilde = .; > > Z = 3/(3-Dtilde)-9*Dtilde/8/Ttilde; > > (* Related variables *) > > Psi1 = (-9*Dtilde)/(8*Ttilde) - Log[3-Dtilde]; > > lnB = (1-Z)-Psi1; > > mu = -lnB+Log[Dtilde]; > > P = Dr Ttilde Z; > > DtildeG=10^-14; > > DtildeL=2.91; > > Dtilde1=.; > > Dtilde2=.; > > mu1=mu/.Dtilde->Dtilde1; > > mu2=mu/.Dtilde->Dtilde2; > > P1=P/.Dtilde->Dtilde1; > > P2=P/.Dtilde->Dtilde2; > > Ttilde = 0.1; > > Result= > FindRoot[ > {P1==P2,mu1==mu2}, > {Dtilde1,DtildeG}, > {Dtilde2,DtildeL}, > MaxIterations->1000, > WorkingPrecision->16]; > > Link to the forum page for this post: > http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Special:Forum_ViewTopic&pid=10101#p10101 > Posted through http://www.mathematica-users.org [[postId=10101]] > > Hi, Use exact values for your parameters, say, 291/100 rather than 2.91. The parameter Dr that occurs in the definition of P has no value when feeding *FindRoot*. Since *FindRoot* is looking for numerics answers only, every parameter must have a value, otherwise it must be listed has variable (below, I have chosen arbitrarily the value 1 for Dr). In[1]:= EOSName = "Van der Waals"; Ttilde =. ; Dtilde =. ; Z = 3/(3 - Dtilde) - 9*(Dtilde/(8*Ttilde)); Psi1 = (-9*Dtilde)/(8*Ttilde) - Log[3 - Dtilde]; lnB = (1 - Z) - Psi1; mu = -lnB + Log[Dtilde]; P = Dr*Ttilde*Z; DtildeG = 10^(-14); DtildeL = 291/100; Dtilde1 =. ; Dtilde2 =. ; mu1 = mu /. Dtilde -> Dtilde1; mu2 = mu /. Dtilde -> Dtilde2; P1 = P /. Dtilde -> Dtilde1; P2 = P /. Dtilde -> Dtilde2; Ttilde = 1/10; Result = FindRoot[{P1 == P2, mu1 == mu2} /. Dr -> 1, {{Dtilde1, DtildeG}, {Dtilde2, DtildeL}}, MaxIterations -> 1000, WorkingPrecision -> 16] Out[18]= {Dtilde1 -> 5.8774260468984207185228791`15.999999999999998*^-13\ , Dtilde2 -> 2.9111111111110937621138592336`16.} HTH, Jean-Marc