TomSym Chemical Equilibrium Problem: Difference between revisions
From TomWiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}} | {{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}} | ||
TomSym implementation of GAMS Example ( | TomSym implementation of GAMS Example (CHEM,SEQ=21) | ||
The problem is to find the equilibrium composition of a mixture of different atoms. | |||
Bracken, J, and McCormick, G P, Chapter 5. In Selected Applications of Nonlinear Programming. John Wiley and Sons, New York, 1968, pp. 48-49. | |||
c: compounds (H, H2, H2O, N, N2, NH, NO, O, O2, OH) | |||
i: atoms (H hydrogen, N nitrogen, O oxygen) | |||
<source lang="matlab"> | <source lang="matlab"> | ||
toms | % Parameters | ||
% Atoms per compound | |||
a = [1 2 2 0 0 1 0 0 0 1; | |||
0 0 0 1 2 1 1 0 0 0; | |||
0 0 1 0 0 0 1 1 2 1]; | |||
% Number of elements in mixture | |||
h=2; n=1; o=1; | |||
mix = [h n o]'; | |||
% Gibbs free energy at 3500 k and 750 psi | |||
gibbs = [-10.021; -21.096; -37.986; -9.846; -28.653; ... | |||
-18.918; -28.032; -14.640; -30.594; -26.11]; | |||
% Gibbs energy plus pressure | |||
gplusp = gibbs + log(750*0.07031); | |||
% Variables | |||
% Number of mols in mixture | |||
toms 10x1 x | |||
% Component definition | |||
eq1 = {}; | |||
for i=1:length(mix) | |||
eq1 = {eq1; sum(a(i,:)*x) == mix(i)}; | |||
end | |||
% Energy definition (xb = total number of mols in mixture) | |||
xb = sum(x); | |||
% Total free energy in mixture | |||
energy = sum(x.*(gplusp + log((x)/xb))); | |||
% Bounds on x and xb | |||
cbnd = {0.001 <= x; 0.01 <= xb}; | |||
solution = ezsolve( | solution = ezsolve(energy,{eq1, cbnd}); | ||
</source> | </source> | ||
<pre> | <pre> | ||
Problem type appears to be: | Problem type appears to be: con | ||
Time for symbolic processing: 0. | Time for symbolic processing: 0.074995 seconds | ||
Starting numeric solver | Starting numeric solver | ||
===== * * * =================================================================== * * * | ===== * * * =================================================================== * * * | ||
TOMLAB - TOMLAB Development license 999007. Valid to 2011-12-31 | TOMLAB - TOMLAB Development license 999007. Valid to 2011-12-31 | ||
===================================================================================== | ===================================================================================== | ||
Problem: --- 1: Problem 1 f_k | Problem: --- 1: Problem 1 f_k -47.706514830836568000 | ||
sum(|constr|) 0. | sum(|constr|) 0.000000000000000666 | ||
f(x_k) + sum(|constr|) | f(x_k) + sum(|constr|) -47.706514830836568000 | ||
f(x_0) | f(x_0) -0.209269531292347570 | ||
Solver: snopt. EXIT=0. INFORM=1. | Solver: snopt. EXIT=0. INFORM=1. | ||
Line 40: | Line 69: | ||
Optimality conditions satisfied | Optimality conditions satisfied | ||
FuncEv | FuncEv 26 GradEv 24 Iter 15 MinorIter 37 | ||
Elapsed time: 0. | CPU time: 0.015600 sec. Elapsed time: 0.014000 sec. | ||
</pre> | </pre> |
Revision as of 08:47, 9 November 2011
This page is part of the TomSym Manual. See TomSym Manual. |
TomSym implementation of GAMS Example (CHEM,SEQ=21)
The problem is to find the equilibrium composition of a mixture of different atoms.
Bracken, J, and McCormick, G P, Chapter 5. In Selected Applications of Nonlinear Programming. John Wiley and Sons, New York, 1968, pp. 48-49.
c: compounds (H, H2, H2O, N, N2, NH, NO, O, O2, OH)
i: atoms (H hydrogen, N nitrogen, O oxygen)
% Parameters
% Atoms per compound
a = [1 2 2 0 0 1 0 0 0 1;
0 0 0 1 2 1 1 0 0 0;
0 0 1 0 0 0 1 1 2 1];
% Number of elements in mixture
h=2; n=1; o=1;
mix = [h n o]';
% Gibbs free energy at 3500 k and 750 psi
gibbs = [-10.021; -21.096; -37.986; -9.846; -28.653; ...
-18.918; -28.032; -14.640; -30.594; -26.11];
% Gibbs energy plus pressure
gplusp = gibbs + log(750*0.07031);
% Variables
% Number of mols in mixture
toms 10x1 x
% Component definition
eq1 = {};
for i=1:length(mix)
eq1 = {eq1; sum(a(i,:)*x) == mix(i)};
end
% Energy definition (xb = total number of mols in mixture)
xb = sum(x);
% Total free energy in mixture
energy = sum(x.*(gplusp + log((x)/xb)));
% Bounds on x and xb
cbnd = {0.001 <= x; 0.01 <= xb};
solution = ezsolve(energy,{eq1, cbnd});
Problem type appears to be: con Time for symbolic processing: 0.074995 seconds Starting numeric solver ===== * * * =================================================================== * * * TOMLAB - TOMLAB Development license 999007. Valid to 2011-12-31 ===================================================================================== Problem: --- 1: Problem 1 f_k -47.706514830836568000 sum(|constr|) 0.000000000000000666 f(x_k) + sum(|constr|) -47.706514830836568000 f(x_0) -0.209269531292347570 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied FuncEv 26 GradEv 24 Iter 15 MinorIter 37 CPU time: 0.015600 sec. Elapsed time: 0.014000 sec.