MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Minimize: new method vs old method

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124169] Minimize: new method vs old method
  • From: Meriens <meriens at gmail.com>
  • Date: Wed, 11 Jan 2012 17:19:35 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Dear all,
I have a question about the operation of Minimize.
I'm doing an algorithm to calculate pressure minimizing a number called
delta.
I've done this with the "old method"  through the function
While[
Abs[delta]>10^(-8)
.............
do some calculations
.............
]

Now I want to try to minimize the function delta with the pressure as a
variable , but I don't know how to set the problem.
Surely a lot of you know how and I'm grateful in advance.
Here is my notebook.

(*Begin New method*)

\[Omega] = N[0.2615];
Tc = N[345.86];
Pc = N[3.761];
R = 8.314472;
\[Psi] = 0.42748;
\[CapitalOmega] = 0.08664;
\[Epsilon] = 0;
\[Sigma] = 1;
tr = t/Tc;
alfa = (1. + (0.480 + 1.574 \[Omega] - 0.176 \[Omega]^2 ) (1 -
        Sqrt[tr]))^2;
a = \[Psi]*alfa*R^2*(Tc^2)/Pc;
b = \[CapitalOmega]*R*Tc/Pc;
t = 170 ;(*K*)
(*---------------End Declaration constant----------------*)
q = a/(b*R*t);
p = 0.01
\[Beta] = b*p/(R*t);(*dependent on p*)
Zl = NSolve[
  zl - \[Beta] - (zl + \[Epsilon]*\[Beta])*(zl + \[Sigma]*\[Beta])*((
      1 + \[Beta] - zl)/(q*\[Beta])) == 0, zl];(*dependent on p*)
Zv = NSolve[
  zv - 1 - \[Beta] +
    q*\[Beta]*(
     zv - \[Beta])/((zv + \[Epsilon]*\[Beta])*(zv + \
\[Sigma]*\[Beta])) == 0, zv];(*dependent on p*)
zliquid = zl /. Zl[[1]];(*dependent on p*)
zvapor = zv /. Zv[[1]];(*dependent on p*)
fliquid =
 zliquid - 1 - Log[zliquid - \[Beta]] -
  q*1/(\[Sigma] - \[Epsilon])*
   Log[(zliquid + \[Sigma]*\[Beta])/(
    zliquid + \[Epsilon]*\[Beta])];(*dependent on p*)
fvapor = zvapor - 1. - Log[zvapor - \[Beta]] -
  q*1/(\[Sigma] - \[Epsilon])*
   Log[(zvapor + \[Sigma]*\[Beta])/(
    zvapor + \[Epsilon]*\[Beta])];(*dependent on p*)
fugliquid = Exp[fliquid]*p;(*dependent on p*)
fugvapor = Exp[fvapor]*p;(*dependent on p*)
delta = fugliquid/fugvapor - 1;(*dependent on p*)
FindMinimum[Abs[delta], p]

(*End New method*)

(*--------------------------------------------------------------------------------------------------------------*)

(*Begin old method*)
While[Abs[delta] > 10^(-8),
 p = p*(delta + 1);
  tr = t/Tc;
  alfa = (1. + (0.480 + 1.574 \[Omega] - 0.176 \[Omega]^2 ) (1 -
        Sqrt[tr]))^2;
 a = \[Psi]*alfa*R^2*(Tc^2)/Pc;
 b = \[CapitalOmega]*R*Tc/Pc;
 \[Beta] = b*p/(R*t);
 q = a/(b*R*t);
 Zl = NSolve[
   zl - \[Beta] - (zl + \[Epsilon]*\[Beta])*(zl + \[Sigma]*\[Beta])*((
       1 + \[Beta] - zl)/(q*\[Beta])) == 0, zl];(*dependent on p*)
 Zv = NSolve[
   zv - 1 - \[Beta] +
     q*\[Beta]*(
      zv - \[Beta])/((zv + \[Epsilon]*\[Beta])*(zv + \
\[Sigma]*\[Beta])) == 0, zv];
 zliquid = zl /. Zl[[1]];
 zvapor = zv /. Zv[[1]];
 fliquid =
  zliquid - 1 - Log[zliquid - \[Beta]] -
   q*1/(\[Sigma] - \[Epsilon])*
    Log[(zliquid + \[Sigma]*\[Beta])/(
     zliquid + \[Epsilon]*\[Beta])];
 fvapor =
  zvapor - 1. - Log[zvapor - \[Beta]] -
   q*1/(\[Sigma] - \[Epsilon])*
    Log[(zvapor + \[Sigma]*\[Beta])/(
     zvapor + \[Epsilon]*\[Beta])];
 fugliquid = Exp[fliquid]*p;
 fugvapor = Exp[fvapor]*p;
 delta = fugliquid/fugvapor - 1;
 Print[p]]

(*End Old method*)


  • Prev by Date: take square of the second and third column of a table
  • Next by Date: Cell/Stylesheet Question Umlauts
  • Previous by thread: Re: take square of the second and third column of a table
  • Next by thread: Cell/Stylesheet Question Umlauts