A Maxwell construction is just an integral of area and then solving for a root to find vapor pressure.
This must be exactly the same value as where the Gibbs energy plot crosses at a point. I found that to be p = 0.81
.
The problem is that my areadifferential
function doesn't work properly; it doesn't return p = 0.81
;
What mistake I have made in my coding?
t = 0.95;
p[v_] := (8*t)/(3*v - 1) - 3/v^2;
Plot[p[v], {v, 0.5, 3},
PlotRange -> {{0, 3}, {0.6, 1}},
AxesLabel -> {V/Vc, P/Pc}]
g[v_] := (-t)*Log[3*v - 1] + 0.95/(3*v - 1) - 9/(4*v);
ParametricPlot[{p[v], g[v]}, {v, .65, 2.25},
AxesLabel -> {P/Pc, G/NKT},
PlotLabel -> "Gibbs Free Energy Vs. P/Pc"]
That returns pressure p = P/Pc = 0.81
as a plot which is correct
This is the error Maxwell construction "area differential" part
pint[v_] := (8/3)*t*Log[3*v - 1] + 3/v;
areadifferential[p0_, v1guess_, v2guess_] :=
(v1 = FindRoot[p[v] == p0, {v, v1guess}][[1,2]];
v2 = FindRoot[p[v] == p0, {v, v2guess}][[1,2]];
pint[v2] - pint[v1] - p0*(v2 - v1))
FindRoot[areadifferential[p0, 0.7, 2] == 0, {p0, 0.8, 0.82}]