PROPT Stirred Tank

From TomWiki
Revision as of 08:12, 9 November 2011 by Mbot (talk | contribs)
Jump to navigationJump to search

Notice.png

This page is part of the PROPT Manual. See PROPT Manual.

Users Guide for dyn.Opt, Example 5a, 5b, 5c

Stirred-Tank Chemical Reactor - Kirk, D. E., Optimal control theory: An introduction, Prentice-Hall, 1970.

5a - unconstrained with terminal penalty 5b - unconstrained 5c - control constraint

Problem Description

Find u over t in [0; 0.78 ] to minimize

Does not say u^2 in text

5a:


5b:


5c:


subject to:


5b, 5c - x(t_F) = [0 0];

5c - <= 1


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

Problem setup

toms t

for i=1:3


    p = tomPhase('p', t, 0, 0.78, 40);
    setPhase(p);

    tomStates x1 x2
    tomControls u

    % Initial guess
    x0 = {icollocate({x1 == 0.05; x2 == 0})
        collocate(u == 0)};

    % Box constraints
    cbox = {-1.99 <= icollocate(x1) <= 100
        -100  <= icollocate(x2) <= 100
        -1000 <= collocate(u) <= 1000};
    % x1 cannot be equal to -2, setting to greater
    % to avoid singularity in a2*exp(25.0*x1/a3)

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

    % ODEs and path constraints
    a1 = x1 + 0.25; a2 = x2 + 0.5;
    a3 = x1 + 2.0;  a4 = a2.*exp(25.0*x1./a3);

    ceq = collocate({
        dot(x1) == -2.0*a1 + a4 - a1.*u
        dot(x2) == 0.5 - x2 - a4});

Solve the problem

    options = struct;
    if i==1
        objective = final(x1)^2+final(x2)^2+...
            integrate((x1.^2+x2.^2+0.1*u.^2)/2);
        options.name = 'Stirred Tank 5a';
        solution1 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);
        t1  = subs(collocate(t),solution1);
        x11 = subs(collocate(x1),solution1);
        x21 = subs(collocate(x2),solution1);
        u1  = subs(collocate(u),solution1);
    elseif i == 2
        cbnd = {cbnd; final({x1 == 0; x2 == 0})};
        objective = integrate((x1.^2+x2.^2+0.1*u.^2)/2);
        options.name = 'Stirred Tank 5b';
        solution2 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);
    else
        cbnd = {cbnd; final({x1 == 0; x2 == 0})};
        cbox = {-1.99 <= icollocate(x1) <= 100
            -100  <= icollocate(x2) <= 100
            -1    <= collocate(u)   <= 1};
        objective = integrate((x1.^2+x2.^2)/2);
        options.name = 'Stirred Tank 5c';
        solution3 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);
    end
Problem type appears to be: qpcon
Time for symbolic processing: 0.20654 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Stirred Tank 5a                f_k       0.014213969120012288
                                       sum(|constr|)      0.000000005238862716
                              f(x_k) + sum(|constr|)      0.014213974358875005
                                              f(x_0)      0.003474999999999964

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

FuncEv    1 ConstrEv   30 ConJacEv   30 Iter   27 MinorIter  113
CPU time: 0.062400 sec. Elapsed time: 0.054000 sec. 

Problem type appears to be: qpcon
Time for symbolic processing: 0.19774 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Stirred Tank 5b                f_k       0.016702811155814214
                                       sum(|constr|)      0.000000899223600415
                              f(x_k) + sum(|constr|)      0.016703710379414628
                                              f(x_0)      0.000974999999999998

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

FuncEv    1 ConstrEv   18 ConJacEv   18 Iter   16 MinorIter  121
CPU time: 0.031200 sec. Elapsed time: 0.037000 sec. 

Problem type appears to be: qpcon
Time for symbolic processing: 0.18987 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Stirred Tank 5c                f_k       0.000989922252663804
                                       sum(|constr|)      0.000000035597654545
                              f(x_k) + sum(|constr|)      0.000989957850318349
                                              f(x_0)      0.000974999999999998

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

FuncEv    1 ConstrEv   14 ConJacEv   13 Iter   10 MinorIter  139
CPU time: 0.015600 sec. Elapsed time: 0.028000 sec. 


end

Plot result

subplot(2,1,1)
plot(t1,x11,'*-',t1,x21,'*-');
legend('x1','x2');
title('Stirred Tank state variables');

subplot(2,1,2)
plot(t1,u1,'+-');
legend('u');
title('Stirred Tank control');

StirredTank 01.png