PROPT Transfer Min Swing

From TomWiki
Revision as of 08:13, 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.

Example 7.1: K.L. Teo, K. K. Leong, G.J. Goh

Problem Formulation

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


subject to:



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

Problem setup

toms t phi1 phi2

% Starting guess
speed = 5;
xopt = 1.2*t;
yopt = 1.6*t;
thetaopt = pi/4;

phi1opt = 1;
phi2opt = 1;
x1opt = 10*t;
x2opt = 22-8*t;
x3opt = 0;
x4opt = 2.5*t;
x5opt = -1+t;
x6opt = 0;
x7opt = 0;
x8opt = 0;
u1opt = 0;
u2opt = 0;

Solve the problem, using a successively larger number collocation points

for n=[20 40]


    % Create a new phase and states, using n collocation points
    p = tomPhase('p', t, 0, 1, n);
    setPhase(p);
    tomStates x1 x2 x3 x4 x5 x6 x7 x8
    tomControls u1 u2

    % Initial guess
    x0 = {phi1 == phi1opt; phi2 == phi2opt
        icollocate({
        x1 == x1opt; x2 == x2opt
        x3 == x3opt; x4 == x4opt
        x5 == x5opt; x6 == x6opt
        x7 == x7opt; x8 == x8opt})
        collocate({
        u1 == u1opt; u2 == u2opt})};

    % Box constraints
    cbox = {-10  <= phi1 <= 10
        -10      <= phi2 <= 10
        -2.5     <= icollocate(x4) <= 2.5
        -1       <= icollocate(x5) <= 1
        -2.83374 <= icollocate(x7) <= 2.83374
        -0.80865 <= icollocate(x8) <= 0.71265
        -10      <= collocate(u1) <= 10
        -10      <= collocate(u2) <= 10};

    % Boundary constraints
    cbnd = {initial({x1 == 0
        x2 == 22; x3 == 0
        x4 == 0;  x5 == -1
        x6 == 0;  x7 == phi1
        x8 == phi2
        })
        final({x1 == 10
        x2 == 14;  x3 == 0
        x4 == 2.5; x5 == 0
        x6 == 0})};

    % ODEs and path constraints
    ceq = collocate({dot(x1) == 9*x4
        dot(x2) == 9*x5; dot(x3) == 9*x6
        dot(x4) == 9*(x7+17.2656*x3)
        dot(x5) == 9*x8
        dot(x6) == -9*(x7+27.0756*x3+2*x5.*x6)./x2
        dot(x7) == 9*u1; dot(x8) == 9*u2});

    % Objective
    objective = integrate(4.5*(x3.^2 + x6.^2));

Solve the problem

    options = struct;
    options.name = 'Transfer Min Swing';
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);

    % Optimal x and u to use as starting guess in the next iteration
    x1opt = subs(x1, solution);
    x2opt = subs(x2, solution);
    x3opt = subs(x3, solution);
    x4opt = subs(x4, solution);
    x5opt = subs(x5, solution);
    x6opt = subs(x6, solution);
    x7opt = subs(x7, solution);
    x8opt = subs(x8, solution);
    u1opt = subs(u1, solution);
    u2opt = subs(u2, solution);
    phi1opt = subs(phi1, solution);
    phi2opt = subs(phi2, solution);
Problem type appears to be: qpcon
Time for symbolic processing: 0.25702 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Transfer Min Swing             f_k       0.005155677076381541
                                       sum(|constr|)      0.000000000220310318
                              f(x_k) + sum(|constr|)      0.005155677296691859
                                              f(x_0)      0.000000000000000000

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

FuncEv    1 ConstrEv  107 ConJacEv  107 Iter  100 MinorIter  374
CPU time: 0.187201 sec. Elapsed time: 0.186000 sec. 

Problem type appears to be: qpcon
Time for symbolic processing: 0.25108 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Transfer Min Swing             f_k       0.005157874701172190
                                       sum(|constr|)      0.000000001277942393
                              f(x_k) + sum(|constr|)      0.005157875979114583
                                              f(x_0)      0.005155729096774491

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

FuncEv    1 ConstrEv  126 ConJacEv  126 Iter  123 MinorIter  594
CPU time: 0.951606 sec. Elapsed time: 0.965000 sec. 


end

t  = subs(collocate(t),solution);
x1 = collocate(x1opt);
x2 = collocate(x2opt);
x3 = collocate(x3opt);
x7 = collocate(x7opt);
x8 = collocate(x8opt);

Plot result

subplot(2,1,1)
plot(t,x1,'*-',t,x2,'*-',t,x3,'*-');
legend('x1','x2','x3');
title('Transfer Min Swing state variables');

subplot(2,1,2)
plot(t,x7,'+-',t,x8,'+-');
legend('x7','x8');
title('Transfer Min Swing control');

TransferMinSwing 01.png