1
$\begingroup$

The following picture depicts the calculation procedure I wish to set up.

Calculation procedure

The inputs are $T_r$, the chemical composition of the feedstock and constraints defined by the equivalence ratio.

This information is used to calculate values for $n_i$, using a Minimize function, as follows:

 gibbs = Sum[Gf[i]*n[i], {i, 1, 6}] + Sum[n[i]*rc*tp*Log[n[i]/n[tot]], {i, 1, 6}]

 f[n1_, n2_, n3_, n4_, n5_, n6_] := gibbs
 constr = Map[0 <= # <= n1 + n2 + n3 + n4 + n5 + n6 &, {n1, n2, n3, n4, n5, n6}];
varn = {n1, n2, n3, n4, n5, n6};

An example of the minimize function:

 NMinimize[{Apply[f, varn], Join[{n1 + n2 + n3 - 4.29 == 0, n1 + 2 n2 + n4 - 5.7 == 0, 
4 n3 + 2 n4 + 2 n5 - 4.34 == 0, 2 n6 - 6.7 == 0}, constr]}, varn]

The equations in $n_1$, $n_2$, $n_3$, $n_4$, $n_5$, and $n_6$ are the constraints defined by the equivalence ratio. At different equivalence ratios, the constraint equations will be different.

The output of this line of code gives me values for $n_1$ to $n_6$.

These values are then used to calculate DeltaH, which is calculated by Hr - Hp.

Hr = N[Subscript[nr, fuel]*Subscript[Hfr, fuel]] 
Hp = (Subscript[Ho, CO]*Subscript[n, CO]) + (Subscript[Ho, CO2]*
Subscript[n, CO2]) + (Subscript[Ho, CH4]*Subscript[n, 
CH4]) + (Subscript[Ho, H2O]*Subscript[n, H2O]) + (Subscript[Ho, 
H2]*Subscript[n, H2]) + (Subscript[Ho, N2]*Subscript[n, N2])

All of the H values are known, the only variables in this case are the n values. It should be known that the subscripts 1 to 6 represent CO, CO2, CH4, H2O, H2 and N2 respectively.

If the value of DeltaH is positive, i want the code to automatically increase the temperature until DeltaH approaches zero, and if DeltaH is negative, vice versa. The criterion to stop changing the temperature is that the absolute value of DeltaH must be less than 0.00001.

At the moment, i am manually changing the input temperature, evaluating the Minimize functions, then taking the values for n1 to n6 and using them to calculate DeltaH.

How can i make it so that Mathematica will automatically adjust the input temperature, and recall values from the minimize function to calculate DeltaH?

Any suggestions will be appreciated.

$\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.