1

I am trying to make a calculation but I have a few bugs and I do not understand them/how to fix them. Below is my syntax, the output, and the error messages. I am trying to calculate the point in my plot (done successfully in another window) where the areas are equal. I appreciate any help/advice.

p[v_]:=(8*.95)/(3*v-1)-3/v^2
Plot[p[v],{v,.5,3},PlotRange->{{0,4},
{.5,1}},
AxesLabel->{"v","p"},
PlotLabel->"van der Waals Isotherm for T/T_c=0.95"]
g[v_]:=-(.95)Log[3v-1]+.95/(3v-1)-9/(4v)
ParametricPlot[{p[v],g[v]},{v,.5,2.5},
AxesLabel->{"p","G/NkT_c"},
PlotLabel->"Gibbs free energy"]
pInt[v_]:=(8/3)*.95*Log[3*v-1]+3/v;
AreaDiff[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[AreaDiff[p0,.7,2]==0,{p0,.8,.82}]

enter image description here

1 Answers1

1

I would use Module[] in the definition of AreaDiff[]. Also, p0_?NumericQ and similar for other variables. See the code below.

p[v_] := (8*.95)/(3*v - 1) - 3/v^2
Plot[p[v], {v, .5, 3}, PlotRange -> {{0, 4}, {.5, 1}}, 
 AxesLabel -> {"v", "p"}, 
 PlotLabel -> "van der Waals Isotherm for T/T_c=0.95"]
g[v_] := -(.95) Log[3 v - 1] + .95/(3 v - 1) - 9/(4 v)
ParametricPlot[{p[v], g[v]}, {v, .5, 2.5}, 
 AxesLabel -> {"p", "G/NkT_c"}, PlotLabel -> "Gibbs free energy"]
pInt[v_] := (8/3)*.95*Log[3*v - 1] + 3/v;
AreaDiff[p0_?NumericQ, v1guess_?NumericQ, v2guess_?NumericQ] := 
  Module[{v1, v2}, (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[AreaDiff[p0, .7, 2] == 0, {p0, .8, .82}]

result

mszynisz
  • 824
  • 5
  • 9