Batch Reactor Problem

Example 6: DYNOPT User's Guide version 4.1.0

Batch reactor with reactions: A -> B -> C.

M. Cizniar, M. Fikar, M. A. Latifi, MATLAB Dynamic Optimisation Code DYNOPT. User's Guide, Technical Report, KIRP FCHPT STU Bratislava, Slovak Republic, 2006.

Contents

Problem description

Find T over t in [0; 1 ] to maximize

$$ J = x_2(t_f) $$

subject to:

$$ \frac{dx_1}{dt} = -k_1*x_1^2 $$

$$ \frac{dx_2}{dt} = k_1*x_1^2-k_2*x_2 $$

$$ k_1 = 4000*exp^{-\frac{2500}{T}} $$

$$ k_2 = 620000*exp^{-\frac{5000}{T}} $$

where

$$ x(0) = [1 \ 0] $$

$$ 298 <= T <= 398 $$

% Copyright (c) 2007-2008 by Tomlab Optimization Inc.

Problem setup

toms t
p = tomPhase('p', t, 0, 1, 30);
setPhase(p);

tomStates x1 x2
tomControls T

% Initial guess
% Note: The guess for tf must appear in the list before expression involving t.
x0 = {icollocate({x1 == 1; x2 == 0})
    collocate(T==398-t*100)};

% Box constraints
cbox = {298 <= collocate(T) <= 398};

% Boundary constraints
cbnd = initial({x1 == 1; x2 == 0});

% Various constants and expressions
k1 = 4000*exp(-2500./T);
k2 = 620000*exp(-5000./T);

% ODEs and path constraints
ceq = collocate({dot(x1) == -k1.*x1.^2
    dot(x2) == k1.*x1.^2-k2.*x2});

% Objective
objective = -final(x2);

Solve the problem

options = struct;
options.name = 'Batch Reactor';
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);

% Extract optimal states and controls from solution
t  = subs(collocate(t),solution);
x1 = subs(collocate(x1),solution);
x2 = subs(collocate(x2),solution);
T  = subs(collocate(T),solution);
Problem type appears to be: lpcon
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2010-02-05
=====================================================================================
Problem: ---  1: Batch Reactor                  f_k      -0.610799380695554730
                                       sum(|constr|)      0.000006007956194376
                              f(x_k) + sum(|constr|)     -0.610793372739360410
                                              f(x_0)      0.000000000000000000

Solver: snopt.  EXIT=0.  INFORM=1.
SNOPT 7.2-5 NLP code
Optimality conditions satisfied

FuncEv    1 ConstrEv   26 ConJacEv   26 Iter   23 MinorIter   70
CPU time: 0.093750 sec. Elapsed time: 0.093000 sec. 

Plot result

subplot(2,1,1)
plot(t,x1,'*-',t,x2,'*-');
legend('x1','x2');
title('Batch Reactor state variables');

subplot(2,1,2)
plot(t,T,'+-');
legend('T');
title('Batch Reactor control');