Post Reply 
HP Prime Program using Solve function
02-03-2020, 01:46 AM
Post: #3
RE: HP Prime Program using Solve function
Thank you for the reply. The "0:=" was a typo but I am not trying to assign a list to the Z variable. I am trying to solve for a numerical value of Z. I want the solve function to assign that value to Z. I am able to do is in the solve app if I insert the equation there then solve for Z but I want to be able to do that without having to leave the program. When I have run the program it will return a value of 0. the whole code is as follows:
Code:

export Tc, Pc, Tr, Pr;
export β,α,фi,fi;
export s,Є,Ω,ѱ;
EXPORT Pure_Fugacity()
BEGIN

local Zv,Zl,Iv,Il;
local w,c,q,Z;
Ω:=.0778;
Є:=1-√2;
s:=1+√2;
ѱ:=.45724;

input({T,Tc,P,Pc});
input({w});
Tr:=T/Tc;
Pr:=P/Pc;
c:=1+(0.37464+1.54226*w-0.26992*w^(2));
α:=(c*(1-Tr^(1/2)))^2;

β:=(Ω*(Pr/Tr));
q:=ѱ*α/Tr/Ω;

//Z for vapor
solve(0=1+β-q*β*(Z-β)/(Z+β*Є)/(Z+s*β),Z,1);
 Zv:=Z;
msgbox(Zv);

//Z for liquid
solve(0=1+β-q*β*(Z-β)/(Z+β*Є)/(Z+s*β),Z,β);
Zl:=Z; 

//I for vapor
Iv:=(1/(s-β))*ln((Zv+s*β)/(Zv+β*Є));

//I for liquid
Il:=(1/(s-β))*ln((Zl+s*β)/(Zl+β*Є));

фi:=e^(Zv-1-ln(Zv-β)-q*Iv);
fi:=фi*P;

print();
print("Tr="+Tr);
print("Pr="+Pr);
print("α="+α);
print("β="+β);
print("q="+q);
print("Zv="+Zv);
print("Lv="+Iv);
print("фi="+фi);
print("fi="+fi);


END;
This is the specific part that is the trouble. There are 3 roots and when there is an initial guess of 1 it will give the root for the vapor and when the initial guess is β it gives the root for the liquid.

Code:
//Z for vapor
solve(0=1+β-q*β*(Z-β)/(Z+β*Є)/(Z+s*β),Z,1);
 Zv:=Z;
msgbox(Zv);

//Z for liquid
solve(0=1+β-q*β*(Z-β)/(Z+β*Є)/(Z+s*β),Z,β);
Zl:=Z; 

//I for vapor
Iv:=(1/(s-β))*ln((Zv+s*β)/(Zv+β*Є));
I appreciate the help. I am new at this programming language and am trying to figure how it all works.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP Prime Program using Solve function - Grayhek - 02-03-2020 01:46 AM



User(s) browsing this thread: 1 Guest(s)