1
$\begingroup$

I'm trying to find parameters to fit an EoS to saturation pressures to different temperatures.

My experimental data are like this

psatx={{Temperature1,Pressure1,Uncertainty1},{T2,p2,u2},....}

Then I defined a function to calculate saturation pressures

psat[T_, p0_, Tc_, a0_, b_, c1_, E11r_, v11_] := (Do[
   p[0] = p0;
   f11 = Exp[-E11r/T] - 1;
   m11 = v11*f11;
   a = a0*(1 + c1*(1 - Sqrt[T/Tc]))^2;
   \[Alpha] = p[i]*a/(R*T)^2; (* Dimensionless groups*)
   \[Beta] = p[i]*b/R/T;
   \[Gamma] = p[i]*m11/R/T;
   d0 = -\[Gamma]*\[Beta]*(\[Beta] + \[Alpha]);(*Coefficients of the equation*)
   d1 = \[Alpha]*(\[Gamma] - \[Beta]) - \[Beta]*\[Gamma]*(1 + \[Beta]);
   d2 = \[Alpha] - \[Beta]*(1 + \[Beta]);
   d3 = \[Gamma] - 1;
   d4 = 1;
   polin = d4*z^4 + d3*z^3 + d2*z^2 + d1*z + d0;
   Raices = NSolve[polin == 0, z, PositiveReals]; (* Solving the 4th grade polinomy for compressibility factor*)
   zv = Max[z /. Raices];
   zl = Min[z /. Raices];
   vv = zv*R*T/p[i];
   vl = zl*R*T/p[i];
   ln\[CapitalPhi]v = 
    zv - 1 - Log[zv] + Log[vv/(vv - b)] + a/b/R/T*Log[vv/(vv + b)] + 
     Log[vv/(vv + m11)]; (*Fugacity coefficients*)
   ln\[CapitalPhi]l = 
    zl - 1 - Log[zl] + Log[vl/(vl - b)] + a/b/R/T*Log[vl/(vl + b)] + 
     Log[vl/(vl + m11)];
   \[CapitalPhi]v = Exp[ln\[CapitalPhi]v];
   \[CapitalPhi]l = Exp[ln\[CapitalPhi]l];
   p[i + 1] = p[i]*\[CapitalPhi]l/\[CapitalPhi]v,
   {i, 0, 9}];
  p[9])

Where T is the temperature, p0 is the initial guess for pressure, Tc is the critical temperature and a0, b, c1, E11r, v11 are the equation's parameters.

Up to this point, we have a saturation pressure calculator, given the parameters, and it works just fine, now the thing that I can't seem to solve is fitting it to my experimental data, by minimizing an objective function, which is:

enter image description here

I declared it like this:

F[a0_, b_, c1_, E11r_, v11_] := 
 Sum[(psat[psatx[[k, 1]], psatx[[k, 2]], Tcaceto, a0, b, c1, E11r, 
      v11] - psatx[[k, 2]])^2/psatx[[k, 3]]^2, {k, 200}];
(* I declared the Tc as "Tcaceto", a constant, and I use as initial guess for each psat calculation the experimental pressure*)

And then I just used NMinimize, in this way.

NMinimize[F[a0, b, c1, E11r, v11], {a0, b, c1, E11r, v11}]

I run it, and it just never finishes. I don't know what could be the thing that doesn't work, I've tried setting the method, starting points, but the result is the same. I would really apreciate if someone helped me in this matter. Thanks.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.