Problem 21              Due 3/26/01

Often we have a sequence of reactions in which
the intermediate is the desired product, and the
end products are waste.  We thus want to maximize
the amount of the intermediate which is produced.

Consider the sequential reversible reactions:

A + B -> AB

A + AB -> A2B

These two reactions have the equilibrium constants:

[AB] / ([A] [B]) = K1

and 

[A2B] / ([A] [AB]) = K2

From the stoichiometry of the problem we have the
mass balances relating the unknown concentrations
[A], [B], [AB], and [A2B] to the initial concentrations
of reactants [A]o and [B]o before the reaction takes place:

[A]o = [A] + [AB] + 2 [A2B]

[B]o = [B] + [AB] + [A2B]

Given all this, solve the following two-part problem:

a). Assuming the values [B]o = 1 mol/liter, K1 = 2 liter/mol,
K2 = 5 liter/mol, write a function which takes in the initial
concentration of [A] given by [A]o and returns the
concentration of the intermediate product [AB].

b). Write a successive parabolic interpolation optimization routine 
to determine the value of [A]o which maximizes [AB].  Plot up
this function and mark the optimum conditions.

Hint:  The first part is very simple: you write a function which
takes in the four unknown concentrations and returns an 
array of four zeros when the equations are satisfied.  You then
put this either under your own root finder, or use a code such
as fsolve.  The second part is just a one-dimensional optimization
problem using the results from the first part!

Note: You will probably want to put in "fixes" so that concentrations
are never negative, and that zero concentrations don't cause the
program to bomb out!