Hello. I want to solve this cubic equation and compare the answers then I can assing the lower result to "VmL" and the greatest result to "VmG" but I have problems when the result is a complex number and two real, Is there anyone who can help me ? I don't really know how to program with Mathematica (I'm a rookie) so, if anyone can help me with a basic example I'll appreciate so much.
And if the answer have only one real number I want to see that value with the other two ones to change the value of "p".
Thanks.
Code:
ClearAll["Global`*"];
R = 83.14; (* cm3*bar/mol*K *)
T = 480;(*K*)
(*Datos para el Heptano*)
Pc = 27.40; (*bar*)
Tc = 540.20; (*K*)
a = 27/64*(R*Tc)^2/Pc;(*cm^6*bar/mol^2*)
b = 1/8*(R*Tc)/Pc; (*cm^3/mol*)
Vc = 3/8*(R*Tc)/Pc;(*cm^3/mol*)
Zc = Rationalize[(Pc*Vc)/(R*Tc)];
For[p = 10, p < 30, p *= ob1,
ob[Vm1_] := Vm1^3 - ((R*T)/p + b) Vm1^2 + a/p Vm1 - (a*b)/p;
\[Phi][T_, Vm1_] :=
E^(b/(Vm1 - b) - (2*a)/(R*T*Vm1) -
Log[1 - (a (Vm1 - b))/(R*T*Vm1^2)]);
f[T_, Vm1_] := p*\[Phi][T, Vm1]; (*bar*)
Vm = Vm1 /. Solve[ob[Vm1] == 0, Vm1];
If[Vm[[1]] < Vm[[3]], {VmL = Vm[[1]], VmG = Vm[[3]]}, 0];
ob1 = f[T, VmL]/f[T, VmG];
If[ob1 == 1, Break[]]
];
p