Linear Problem with Bang Bang Control

Problem 5a: Miser3 manual

Contents

Problem description

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

$$ J = \int_{0}^{1} -6*x_1-12*x_2+3*u_1+u_2 \mathrm{d}t $$

subject to:

$$ \frac{dx_1}{dt} = u_2 $$

$$ \frac{dx_2}{dt} = -x_1+u_1 $$

$$ x_1(0) = 1 $$

$$ x_2(0) = 0 $$

$$ |u| <= 10 $$

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

Problem setup

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

tomStates x1 x2
tomControls -integer u1 u2

% Initial guess
x0 = {icollocate({x1 == 1; x2 == 0})
    collocate({u1 == 0; u2 == 0})};

% Box constraints
cbox = {-10 <= icollocate(x1) <= 10
    -10 <= icollocate(x2) <= 10
    -10 <= collocate(u1)  <= 10
    -10 <= collocate(u2)  <= 10};

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

% ODEs and path constraints
ceq = collocate({dot(x1) == u2
    dot(x2) == -x1+u1});

% Objective
objective = integrate(-6*x1-12*x2+3*u1+u2);

Solve the problem

options = struct;
options.name = 'Linear Problem Bang';
options.solver = 'knitro';
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);
t  = subs(collocate(t),solution);
x1 = subs(collocate(x1),solution);
x2 = subs(collocate(x2),solution);
u1 = subs(collocate(u1),solution);
u2 = subs(collocate(u2),solution);
Problem type appears to be: mip
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2011-02-05
=====================================================================================
Problem: ---  1: Linear Problem Bang            f_k     -41.377652164326207000
                                       sum(|constr|)      0.000000200108555051
                              f(x_k) + sum(|constr|)    -41.377651964217655000
                                              f(x_0)     -5.999999999999999100

Solver: KNITRO.  EXIT=0.  INFORM=0.
Default MINLP KNITRO
Locally optimal solution found

FuncEv   30 GradEv   27 HessEv   19 
CPU time: 0.109375 sec. Elapsed time: 0.109000 sec. 

Plot result

subplot(2,1,1)
plot(t,x1,'*-',t,x2,'*-');
legend('x1','x2');
title('Linear Problem Bang state variables');

subplot(2,1,2)
plot(t,u1,'+-',t,u2,'+-');
legend('u1','u2');
title('Linear Problem Bang control');