PROPT Linear Problem with Bang Bang Control
From TomWiki
Jump to navigationJump to search
This page is part of the PROPT Manual. See PROPT Manual. |
Problem 5a: Miser3 manual
Problem description
Find u over t in [0; 1 ] to minimize
subject to:
% 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 Time for symbolic processing: 0.04476 seconds Starting numeric solver ===== * * * =================================================================== * * * TOMLAB - TOMLAB Development license 999007. Valid to 2011-12-31 ===================================================================================== Problem: --- 1: Linear Problem Bang f_k -41.377652164326122000 sum(|constr|) 0.000000200077248423 f(x_k) + sum(|constr|) -41.377651964248876000 f(x_0) -5.999999999999976900 Solver: KNITRO. EXIT=0. INFORM=0. Default MINLP KNITRO Locally optimal solution found FuncEv 30 GradEv 27 HessEv 19 CPU time: 0.046800 sec. Elapsed time: 0.168000 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');