Application Center - Maplesoft

App Preview:

Reaction equilibrium for multiple gas phase reactions

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Reaction Equilibrium for Multiple Gas Phase Reactions

We begin by creating a list of component identities and to calculate the number of components.

> components:=[A,B,C,D,X,Y,Z]; nc:=nops(components);

[Maple Math]

[Maple Math]

Next, we create a list of reactions:

> Reactions:=[R1,R2,R3];

[Maple Math]

Each reaction may be expressed as a Maple equation:

> Reaction[R1] :=A+B=C+D;

[Maple Math]

> Reaction[R2] := B+C=X+Y;

[Maple Math]

> Reaction[R3] :=A+X=Z;

[Maple Math]

The stoichiometric cofficients can be deduced from the set of reactions as follows:

> printlevel:=2:
for r in Reactions do
for i in components do
nu[i,r]:=coeff(lhs(Reaction[r])-rhs(Reaction[r]),i);
od: od;
printlevel:=1:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

We need mole balances for each component:

> r:='r':
for i in components do
CMB[i] := C[i,0] = C[i] + add(nu[i,r]*e[r],r=Reactions);
print(CMB[i]);
od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

where we use e to denote the extent of reaction. The initial concentration is denoted with a second subscript of zero.

The reaction equilibrium constants may be expressed as

> i:='i': for r in Reactions do
Kdef[r]:=K[r] = mul ((C[i])^(-nu[i,r]),i=components);
print(Kdef[r]);
od:

[Maple Math]

[Maple Math]

[Maple Math]

We create a set of equations to be solved

> Eqns := {seq(CMB[i],i=components),seq(Kdef[r],r=Reactions)};

[Maple Math]
[Maple Math]

and a set of unknown variables:

> Vars := indets(Eqns,name);

[Maple Math]

The number of degrees of freedom follows directly

> DegFree := nops(Vars)-nops(Eqns);

[Maple Math]

Case 1

> Specs[1] := C[A,0]=1.5;

[Maple Math]

> Specs[2] := C[B,0]=1.5;

[Maple Math]

> Specs[3] := seq(C[i,0]=0,i=[C,D,X,Y,Z]);

[Maple Math]

At the conditions of interest the reaction equilibrium coefficient has the following values

> Kvals := {K[R1] = 1, K[R2]=2.63, K[R3]=5};

[Maple Math]

We now augment the set of equations with the set of specifications

> AllEqns:=Eqns union {seq(Specs[k],k=1..3),op(Kvals)};

[Maple Math]
[Maple Math]

and ask Maple to solve the problem

> result:=solve(AllEqns,Vars);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

Maple found several solutions to this problem without much effort. The number of solutions can be counted using the nops command (note that in this case we must enclose result in braces).

> nops({result});

[Maple Math]

It is easy to see, however, that not all of the solutions are physically meaningful; some of them contain negative concentrations, while others are complex. Only one of the solutions is physically meaningful (all quantities being non-negative). We can pick this solution from the set of 8 by hand or we can be more sophisticated and ask Maple to find it for us.

> result2:=remove(hastype,{result},negative);

[Maple Math]
[Maple Math]

Note that we did not have to rearrange the equations into a form more suitable for numerical computation. We did not have to provide initial guesses of the unknown variables, and we did not have to work out the independent equations since we could do that with Maple as well. Of course, it is possible to compute a purely numerical solution using the Newton's method package in the share library and demonstrated below.

> read `e:/maple/numerics/nonlin/newton.mpl`:

Newton requires two arguments, a list of equations to be solved and a list of equations that provide the initial values. The list of eqns is constructed from the set used in the last example

> Eqns:=[op(AllEqns)];

[Maple Math]
[Maple Math]

The startingpoint is constructed in a rather simple-minded way (that is effective here). We make a list of the variables in the equations:

> Vars := [op(indets(Eqns,name))];

[Maple Math]

and give all of them the initial value of 0.1.

> Start := [seq(x=0.1,x=Vars)];

[Maple Math]
[Maple Math]

> result:=Newton(Eqns,Start);

[Maple Math]
[Maple Math]

>

This is the result obtained earlier. As an exercise we suggest that readers try different starting points. It may be advisable in some cases to arrange the equations in a form that does not involve possible divisions by zero (see the equilibrium equations).