<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://tomwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbot</id>
	<title>TomWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://tomwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbot"/>
	<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=Special:Contributions/Mbot"/>
	<updated>2026-10-31T20:41:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>http://tomwiki.com/index.php?title=TomSym_Chemical_Equilibrium_Problem&amp;diff=2281</id>
		<title>TomSym Chemical Equilibrium Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=TomSym_Chemical_Equilibrium_Problem&amp;diff=2281"/>
		<updated>2011-11-09T12:48:18Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}}&lt;br /&gt;
&lt;br /&gt;
TomSym implementation of GAMS Example (WALL,SEQ=76)&lt;br /&gt;
&lt;br /&gt;
A Sample Nonlinear system to solve Chemical Equilibrium models.&lt;br /&gt;
&lt;br /&gt;
Wall, T W, Greening, D, and Woolsey, R E D, Solving Complex Chemical Equilibria Using a Geometric-Programming Based Technique. OR 34, 3 (1987).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms ba so4 baoh oh hso4 h&lt;br /&gt;
&lt;br /&gt;
r1 = {ba*so4 == 1};&lt;br /&gt;
r2 = {baoh/ba/oh == 4.8};&lt;br /&gt;
r3 = {hso4/so4/h == .98};&lt;br /&gt;
r4 = {h*oh == 1};&lt;br /&gt;
&lt;br /&gt;
b1 = {ba + 1e-7*baoh == so4 + 1e-5*hso4};&lt;br /&gt;
b2 = {2*ba + 1e-7*baoh + 1e-2*h == 2*so4 + 1e-5*hso4 + 1e-2*oh};&lt;br /&gt;
&lt;br /&gt;
x0 = {1 == ba; 1 == so4; 1 == baoh&lt;br /&gt;
    1 == oh; 1 == hso4; 1 == h };&lt;br /&gt;
&lt;br /&gt;
solution = ezsolve(ba,{r1,r2,r3,r4,b1,b2},x0);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.13614 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Problem 1                      f_k       1.000004657593424700&lt;br /&gt;
                                       sum(|constr|)      0.000000000000846878&lt;br /&gt;
                              f(x_k) + sum(|constr|)      1.000004657594271600&lt;br /&gt;
                                              f(x_0)      1.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    4 ConJacEv    4 Iter    3 MinorIter    5&lt;br /&gt;
Elapsed time: 0.008000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=TomSym_Chemical_Equilibrium_Problem&amp;diff=2280</id>
		<title>TomSym Chemical Equilibrium Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=TomSym_Chemical_Equilibrium_Problem&amp;diff=2280"/>
		<updated>2011-11-09T12:47:46Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}}&lt;br /&gt;
&lt;br /&gt;
TomSym implementation of GAMS Example (CHEM,SEQ=21)&lt;br /&gt;
&lt;br /&gt;
The problem is to find the equilibrium composition of a mixture of different atoms.&lt;br /&gt;
&lt;br /&gt;
Bracken, J, and McCormick, G P, Chapter 5. In Selected Applications of Nonlinear Programming. John Wiley and Sons, New York, 1968, pp. 48-49.&lt;br /&gt;
&lt;br /&gt;
c: compounds (H, H2, H2O, N, N2, NH, NO, O, O2, OH)&lt;br /&gt;
&lt;br /&gt;
i: atoms (H  hydrogen, N  nitrogen, O  oxygen)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Parameters&lt;br /&gt;
&lt;br /&gt;
% Atoms per compound&lt;br /&gt;
a = [1   2    2  0   0   1   0  0   0   1;&lt;br /&gt;
    0   0    0  1   2   1   1  0   0   0;&lt;br /&gt;
    0   0    1  0   0   0   1  1   2   1];&lt;br /&gt;
&lt;br /&gt;
% Number of elements in mixture&lt;br /&gt;
h=2; n=1; o=1;&lt;br /&gt;
mix = [h n o]&#039;;&lt;br /&gt;
&lt;br /&gt;
% Gibbs free energy at 3500 k and 750 psi&lt;br /&gt;
gibbs = [-10.021; -21.096; -37.986; -9.846; -28.653; ...&lt;br /&gt;
    -18.918; -28.032; -14.640; -30.594; -26.11];&lt;br /&gt;
&lt;br /&gt;
% Gibbs energy plus pressure&lt;br /&gt;
gplusp = gibbs + log(750*0.07031);&lt;br /&gt;
&lt;br /&gt;
% Variables&lt;br /&gt;
&lt;br /&gt;
% Number of mols in mixture&lt;br /&gt;
toms 10x1 x&lt;br /&gt;
&lt;br /&gt;
% Component definition&lt;br /&gt;
eq1 = {};&lt;br /&gt;
for i=1:length(mix)&lt;br /&gt;
    eq1 = {eq1; sum(a(i,:)*x) == mix(i)};&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
% Energy definition (xb = total number of mols in mixture)&lt;br /&gt;
xb = sum(x);&lt;br /&gt;
&lt;br /&gt;
% Total free energy in mixture&lt;br /&gt;
energy = sum(x.*(gplusp + log((x)/xb)));&lt;br /&gt;
&lt;br /&gt;
% Bounds on x and xb&lt;br /&gt;
cbnd = {0.001 &amp;lt;= x; 0.01 &amp;lt;= xb};&lt;br /&gt;
&lt;br /&gt;
solution = ezsolve(energy,{eq1, cbnd});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: con&lt;br /&gt;
Time for symbolic processing: 0.074995 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Problem 1                      f_k     -47.706514830836568000&lt;br /&gt;
                                       sum(|constr|)      0.000000000000000666&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -47.706514830836568000&lt;br /&gt;
                                              f(x_0)     -0.209269531292347570&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv   26 GradEv   24 Iter   15 MinorIter   37&lt;br /&gt;
CPU time: 0.015600 sec. Elapsed time: 0.014000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Van_der_Pol_Oscillator&amp;diff=2279</id>
		<title>PROPT Van der Pol Oscillator</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Van_der_Pol_Oscillator&amp;diff=2279"/>
		<updated>2011-11-09T12:13:54Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Restricted second order information for the solution of optimal control problems using control vector parameterization. 2002, Eva Balsa Canto, Julio R. Banga, Antonio A. Alonso Vassilios S. Vassiliadis&lt;br /&gt;
&lt;br /&gt;
Case Study 6.1: van der Pol oscillator&lt;br /&gt;
&lt;br /&gt;
This case study has been studied by several authors, for example Morison, Gritsis, Vassiliadis and Tanartkit and Biegler.&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
The dynamic optimization problem is to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = (1-x_2^2)*x_1-x_2+u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_1^2+x_2^2+u^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -0.3 &amp;lt;= u &amp;lt;= 1.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0 \ 1 \ 0]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_f = 5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 60);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0; x2 == 1; x3 == 0})&lt;br /&gt;
    collocate(u == -0.01)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-10  &amp;lt;= icollocate(x1) &amp;lt;= 10&lt;br /&gt;
    -10  &amp;lt;= icollocate(x2) &amp;lt;= 10&lt;br /&gt;
    -10  &amp;lt;= icollocate(x3) &amp;lt;= 10&lt;br /&gt;
    -0.3 &amp;lt;= collocate(u)   &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 0; x2 == 1; x3 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == (1-x2.^2).*x1-x2+u&lt;br /&gt;
    dot(x2) == x1; dot(x3) == x1.^2+x2.^2+u.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Van Der Pol&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.11775 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Van Der Pol                    f_k       2.867259538084708100&lt;br /&gt;
                                       sum(|constr|)      0.000000020744545091&lt;br /&gt;
                              f(x_k) + sum(|constr|)      2.867259558829253300&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   26 ConJacEv   26 Iter   23 MinorIter  348&lt;br /&gt;
CPU time: 0.218401 sec. Elapsed time: 0.222000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;);&lt;br /&gt;
title(&#039;vanDerPol state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;vanDerPol control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:vanDerPol_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Two_Stage_CSTR&amp;diff=2278</id>
		<title>PROPT Two Stage CSTR</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Two_Stage_CSTR&amp;diff=2278"/>
		<updated>2011-11-09T12:13:52Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
Section 6.3.1 Nonlinear two-stage CSTR system&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
The system consists of a series of two CSTRs, where there is a transportation delay tau = 0.1 from the first tank to the second. A truncated Taylor series expansion for the time delay.&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_5(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = f_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = f_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_1 - x_3 - tau*f_1 - R_2 + 0.25 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = x_2 - 2*x_4 - u_2*(x_4 + 0.25) - tau*f_2 + R_2 - 0.25 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = x_1^2+ x_2^2 + x_3^2 + x_4^2 + 0.1*(u_1^2 + u_2^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = 0.5 - x_1 - R_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_2 = -2*(x_2 + 0.25) - u_1*(x_2 + 0.25) + R_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; R_1 = (x_1 + 0.5)*exp(25*\frac{x_2}{x_2 + 2}) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; R_2 = (x_3 + 0.25)*exp(25*\frac{x_4}{x_4 + 2}) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The state variables x1 and x3 are normalized concentration variables in tanks 1 and 2, respectively, and x2 and x4 are normalized temperature variables in tanks 1 and 2, respectively. The variable x5 is introduced to provide the performance index to be minimized.&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0.15 \ -0.03 \ 0.10 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -0.5 &amp;lt;= u1 &amp;lt;= 0.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -0.5 &amp;lt;= u2 &amp;lt;= 0.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 20);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4 x5&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
xi = [0.15;-0.03;0.10;0;0];&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == xi(1); x2 == xi(2)&lt;br /&gt;
    x3 == xi(3); x4 == xi(4); x5 == xi(5)})&lt;br /&gt;
    collocate({u1 == 0; u2 == 0})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = collocate({-0.5 &amp;lt;= u1 &amp;lt;= 0.5&lt;br /&gt;
    -0.5 &amp;lt;= u2 &amp;lt;= 0.5});&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == xi(1); x2 == xi(2)&lt;br /&gt;
    x3 == xi(3); x4 == xi(4); x5 == xi(5)});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
R1 = (x1 + 0.5).*exp(25*x2./(x2 + 2));&lt;br /&gt;
R2 = (x3 + 0.25).*exp(25*x4./(x4 + 2));&lt;br /&gt;
f1 = 0.5 - x1 - R1;&lt;br /&gt;
f2 = -2*(x2 + 0.25) - u1.*(x2 + 0.25) + R1;&lt;br /&gt;
tau = 0.1;&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == f1; dot(x2) == f2&lt;br /&gt;
    dot(x3) == x1-x3-tau*f1-R2+0.25&lt;br /&gt;
    dot(x4) == x2-2*x4-u2.*(x4+0.25)-tau*f2+R2-0.25&lt;br /&gt;
    dot(x5) == x1.^2+ x2.^2+x3.^2+x4.^2+0.1*(u1.^2+u2.^2)});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x5);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Two Stage CSTR&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.45209 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Two Stage CSTR                 f_k       0.023238023992802660&lt;br /&gt;
                                       sum(|constr|)      0.000000172957099895&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.023238196949902555&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   26 ConJacEv   26 Iter   22 MinorIter  123&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.068000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Two Stage CSTR state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Two Stage CSTR control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:twoStageCSTR_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Two-Phase_Schwartz&amp;diff=2277</id>
		<title>PROPT Two-Phase Schwartz</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Two-Phase_Schwartz&amp;diff=2277"/>
		<updated>2011-11-09T12:13:42Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Users Guide for dyn.Opt, Example 4&lt;br /&gt;
&lt;br /&gt;
Schwartz, A. L., Theory and Implementation of Numerical Methods based on Runge-Kutta Integration for Solving Optimal Control Problems. Ph.D. Dissertation, University of California, Berkeley, 1989&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2.9 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = 5*(x_1(t_F)^2 + x_2(t_F)^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u - 0.1*(1+2*x_1^2)*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0)  = [1 \ 1] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and path constraints for t&amp;lt;1:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 1-9*(x_1-1)^2-(\frac{x_2-0.4}{0.3})^2 &amp;lt;=0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -0.8-x_2 &amp;lt;= 0 \ --&amp;gt; \ -0.8 &amp;lt;= x_2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1, (t&amp;lt;1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t1&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t1, 0, 1, 25);&lt;br /&gt;
toms t2&lt;br /&gt;
p2 = tomPhase(&#039;p2&#039;, t2, 1, 1.9, 25);&lt;br /&gt;
&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
tomStates x1p1 x2p1&lt;br /&gt;
tomControls up1&lt;br /&gt;
&lt;br /&gt;
setPhase(p2);&lt;br /&gt;
tomStates x1p2 x2p2&lt;br /&gt;
tomControls up2&lt;br /&gt;
&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
% Initial guess&lt;br /&gt;
x01 = {icollocate({x1p1 == 1; x2p1 == 1})&lt;br /&gt;
    collocate(up1==0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox1 = {-0.8 &amp;lt;= icollocate(x2p1)&lt;br /&gt;
    -1 &amp;lt;= collocate(up1) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd1 = initial({x1p1 == 1; x2p1 == 1});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq1 = collocate({&lt;br /&gt;
    dot(x1p1) == x2p1&lt;br /&gt;
    dot(x2p1) == up1 - 0.1*(1+2*x1p1.^2).*x2p1&lt;br /&gt;
    1-9*(x1p1-1).^2-((x2p1-0.4)/0.3).^2 &amp;lt;= 0});&lt;br /&gt;
&lt;br /&gt;
setPhase(p2);&lt;br /&gt;
% Initial guess&lt;br /&gt;
x02 = {icollocate({x1p2 == 1; x2p2 == 1})&lt;br /&gt;
    collocate(up2==0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox2 = {-50 &amp;lt;= collocate(up2) &amp;lt;= 50};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq2 = collocate({&lt;br /&gt;
    dot(x1p2) == x2p2&lt;br /&gt;
    dot(x2p2) == up2-0.1*(1+2*x1p2.^2).*x2p2});&lt;br /&gt;
&lt;br /&gt;
% Link phase&lt;br /&gt;
link = {final(p1,x1p1) == initial(p2,x1p2)&lt;br /&gt;
    final(p1,x2p1) == initial(p2,x2p2)};&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = 5*(final(p2,x1p2)^2+final(p2,x2p2)^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Two Phase Schwartz&#039;;&lt;br /&gt;
constr = {cbox1, cbnd1, ceq1, cbox2, ceq2, link};&lt;br /&gt;
solution = ezsolve(objective, constr, {x01, x02}, options);&lt;br /&gt;
&lt;br /&gt;
t = subs(collocate(p1,t1),solution);&lt;br /&gt;
t = [t;subs(collocate(p2,t2),solution)];&lt;br /&gt;
x1 = subs(collocate(p1,x1p1),solution);&lt;br /&gt;
x1 = [x1;subs(collocate(p2,x1p2),solution)];&lt;br /&gt;
x2 = subs(collocate(p1,x2p1),solution);&lt;br /&gt;
x2 = [x2;subs(collocate(p2,x2p2),solution)];&lt;br /&gt;
u = subs(collocate(p1,up1),solution);&lt;br /&gt;
u = [u;subs(collocate(p2,up2),solution)];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.20317 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Two Phase Schwartz             f_k       0.000000000000002272&lt;br /&gt;
                                       sum(|constr|)      0.000000000003288885&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000000000003291157&lt;br /&gt;
                                              f(x_0)     10.000000000000014000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   24 ConJacEv   24 Iter   18 MinorIter  361&lt;br /&gt;
CPU time: 0.046800 sec. Elapsed time: 0.056000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;Two Phase Schwartz state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Two Phase Schwartz control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:twoPhaseSchwartz_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Two-Link_Robotic_Arm&amp;diff=2276</id>
		<title>PROPT Two-Link Robotic Arm</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Two-Link_Robotic_Arm&amp;diff=2276"/>
		<updated>2011-11-09T12:13:39Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
12.4.2 Example 2: Two-link robotic arm&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t_F ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_F &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = \frac{sin(x_3)*(\frac{9}{4}*cos(x_3)*x_1^2+2*x_2^2) + \frac{4}{3}*(u_1-u_2) - \frac{3}{2}*cos(x_3)*u_2 } {\frac{31}{36} + \frac{9}{4}*sin(x_3)^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -\frac{sin(x_3)*(\frac{7}{2}*x_1^2+\frac{9}{4}*cos(x3)*x_2^2) - \frac{7}{3}*u_2 + \frac{3}{2}*cos(x_3)*(u_1-u_2) }{\frac{31}{36} + \frac{9}{4}*sin(x_3)^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_2-x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0)  = [0 \ 0 \ 0.5 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_F) = [0 \ 0 \ 0.5 \ 0.522] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u(1:2) &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t t_f&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, t_f, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {t_f == 3&lt;br /&gt;
    icollocate({x1 == 0; x2 == 0&lt;br /&gt;
    x3 == 0.5; x4 == 0.522})&lt;br /&gt;
    collocate({u1 == 1-2*t/t_f&lt;br /&gt;
    u2 == 1-2*t/t_f})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {2.6 &amp;lt;= t_f &amp;lt;= 100&lt;br /&gt;
    -1  &amp;lt;= collocate(u1) &amp;lt;= 1&lt;br /&gt;
    -1  &amp;lt;= collocate(u2) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == 0; x2 == 0&lt;br /&gt;
    x3 == 0.5; x4 == 0})&lt;br /&gt;
    final({x1 == 0; x2 == 0&lt;br /&gt;
    x3 == 0.5; x4 == 0.522})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == ( sin(x3).*(9/4*cos(x3).*x1.^2+2*x2.^2) ...&lt;br /&gt;
    +4/3*(u1-u2) - 3/2*cos(x3).*u2 )./ (31/36 + 9/4*sin(x3).^2)&lt;br /&gt;
    dot(x2) == -( sin(x3).*(7/2*x1.^2 + 9/4*cos(x3).*x2.^2) ...&lt;br /&gt;
    - 7/3*u2 + 3/2*cos(x3).*(u1-u2) )./ (31/36 + 9/4*sin(x3).^2)&lt;br /&gt;
    dot(x3) == x2-x1&lt;br /&gt;
    dot(x4) == x1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Two Link Robotic Arm&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.41192 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Two Link Robotic Arm           f_k       2.983364855223867600&lt;br /&gt;
                                       sum(|constr|)      0.000000154455553673&lt;br /&gt;
                              f(x_k) + sum(|constr|)      2.983365009679421300&lt;br /&gt;
                                              f(x_0)      3.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   20 ConJacEv   20 Iter   16 MinorIter  278&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.062000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Two Link Robotic Arm state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Two Link Robotic Arm control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:twoLinkRoboticArm_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Turbo_Generator&amp;diff=2275</id>
		<title>PROPT Turbo Generator</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Turbo_Generator&amp;diff=2275"/>
		<updated>2011-11-09T12:13:36Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
OCCAL - A Mixed symbolic-numeric Optimal Control CALcluator&lt;br /&gt;
&lt;br /&gt;
Section 4 Example 1&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{t} (alpha_1*( (x_1-x_1^{s})^2 + (x_4-x_4^{s})^2) + &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; alpha_2*x_2^{2} + alpha_3*(x_3-x_3^{s})^{2} + &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; beta_1*(u_1-u_1^{s})^{2} + beta_2*(u_2-u_2^{s})^{2} ) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2*x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = \frac{1}{M}*(u_1-s_4*x_1*x_4-s_5*x_1*x_3-kappa_d*x_2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u_2-A*x_3+c*x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = -x_1*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0)  = [x_1^{s} \ x_2^{s} \ x_3^{s} \ x_4^{s}] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_{1:4}^{s} = [0.60295 \ 0.0 \ 1.87243 \ 0.79778] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; alpha = [2.5 \ 1.0 \ 0.1] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; beta = [1.0 \ 1.0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; M = 0.04225 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; s_{4:5} = [0.0 \ 0.0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; c = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = 0.17 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; u_{1:2}^{s} = [0.80 \ 0.73962] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; kappa_d = 0.02535 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 20, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0i = [0.60295;0;1.87243;0.79778];&lt;br /&gt;
x0 = {icollocate({x1 == x0i(1); x2 == x0i(2)&lt;br /&gt;
    x3 == x0i(3); x4 == x0i(4)})&lt;br /&gt;
    collocate({u1 == 0; u2 == 0})};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == x0i(1); x2 == x0i(2)&lt;br /&gt;
    x3 == x0i(3); x4 == x0i(4)});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
u1s     = 0.80;    u2s     = 0.73962;&lt;br /&gt;
A       = 0.17;    c       = 0;&lt;br /&gt;
s4      = 0;       s5      = 0;&lt;br /&gt;
M       = 0.04225; alpha1  = 2.5;&lt;br /&gt;
alpha2  = 1.0;     alpha3  = 0.1;&lt;br /&gt;
beta1   = 1.0;     beta2   = 1.0;&lt;br /&gt;
kappa_d = 0.02535;&lt;br /&gt;
&lt;br /&gt;
ceq = collocate({dot(x1) == x2.*x4&lt;br /&gt;
    dot(x2) == 1/M.*(u1-s4*x1.*x4-s5*x1.*x3-kappa_d*x2)&lt;br /&gt;
    dot(x3) == u2-A*x3+c*x4; dot(x4) == -x1.*x2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(alpha1*( (x1-x0i(1)).^2 +  ...&lt;br /&gt;
    (x4-x0i(4)).^2) + alpha2*x2.^2 + alpha3*(x3-x0i(3)).^2 + ...&lt;br /&gt;
    beta1*(u1-u1s).^2 + beta2*(u2-u2s).^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Turbo Generator&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.17864 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Turbo Generator                f_k      15.019841547670794000&lt;br /&gt;
                                       sum(|constr|)      0.000000000046608960&lt;br /&gt;
                              f(x_k) + sum(|constr|)     15.019841547717403000&lt;br /&gt;
                                              f(x_0)    -57.012069754799789000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   35 ConJacEv   35 Iter   23 MinorIter  119&lt;br /&gt;
CPU time: 0.046800 sec. Elapsed time: 0.048000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Turbo Generator state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Turbo Generator control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:turboGenerator_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Tubular_Reactor&amp;diff=2274</id>
		<title>PROPT Tubular Reactor</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Tubular_Reactor&amp;diff=2274"/>
		<updated>2011-11-09T12:13:32Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Global Optimization of Chemical Processes using Stochastic Algorithms 1996, Julio R. Banga, Warren D. Seider&lt;br /&gt;
&lt;br /&gt;
Case Study V: Global optimization of a bifunctional catalyst blend in a tubular reactor&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Luus et al and Luus and Bojkov consider the optimization of a tubular reactor in which methylcyclopentane is converted into benzene. The blend of two catalysts, for hydrogenation and isomerization is described by the mass fraction u of the hydrogenation catalyst. The optimal control problem is to find the catalyst blend along the length of the reactor defined using a characteristic reaction time t in the interval 0 &amp;lt;= t &amp;lt;= t_f where t_f = 2000 gh/mol corresponding to the reactor exit such that the benzene concentration at the exit of the reactor is maximized.&lt;br /&gt;
&lt;br /&gt;
Find u(t) to maximize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_7(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = -k_1*x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = k_1*x_1-(k_2+k_3)*x_2+k_4*x_5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = k_2*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = -k_6*x_4+k_5*x_5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = k_3*x_2+k_6*x_4-(k_4+k_5+k_8+k_9)*x_5+k_7*x_6+k_{10}*x_7 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_6}{dt} = k_8*x_5-k_7*x_6 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_7}{dt} = k_9*x_5-k_{10}*x_7 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where xi, i = 1,..,7 are the mole fractions of the chemical species (i = 1 for methylcyclopentane, i = 7 for benzene), the rate constants are functions of the catalyst blend u(t):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; k_i = c(i,1)+c(i,2)*u+c(i,3)*u^2+c(i,4)*u^3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and the coefficients cij are given by Luus et al. The upper and lower bounds on the mass fraction of the hydrogenation catalyst are.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0.6 &amp;lt;= u &amp;lt;= 0.9 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial vector of mole fractions is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&lt;br /&gt;
% Data&lt;br /&gt;
c = [0.2918487e-2, -0.8045787e-2, 0.6749947e-2,  -0.1416647e-2;...&lt;br /&gt;
    0.9509977e1,   -0.3500994e2,  0.4283329e2,   -0.1733333e2; ...&lt;br /&gt;
    0.2682093e2,   -0.9556079e2,  0.1130398e3,   -0.4429997e2; ...&lt;br /&gt;
    0.2087241e3,   -0.7198052e3,  0.8277466e3,   -0.3166655e3; ...&lt;br /&gt;
    0.1350005e1,   -0.6850027e1,  0.1216671e2,   -0.6666689e1; ...&lt;br /&gt;
    0.1921995e-1,  -0.7945320e-1, 0.1105666,     -0.5033333e-1;...&lt;br /&gt;
    0.1323596,     -0.4696255,    0.5539323,     -0.2166664;   ...&lt;br /&gt;
    0.7339981e1,   -0.2527328e2,  0.2993329e2,   -0.1199999e2; ...&lt;br /&gt;
    -0.3950534,     0.1679353e1,  -0.1777829e1,  0.4974987;    ...&lt;br /&gt;
    -0.2504665e-4,  0.1005854e-1, -0.1986696e-1, 0.9833470e-2]&#039;;&lt;br /&gt;
&lt;br /&gt;
% Independent variable&lt;br /&gt;
toms t&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x1opt = 1; x2opt = 0;&lt;br /&gt;
x3opt = 0; x4opt = 0;&lt;br /&gt;
x5opt = 0; x6opt = 0;&lt;br /&gt;
x7opt = 0; uopt = 0.9;&lt;br /&gt;
&lt;br /&gt;
% Loop over number of collocation points&lt;br /&gt;
for n=[10 80]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 2000, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates x1 x2 x3 x4 x5 x6 x7&lt;br /&gt;
    tomControls u&lt;br /&gt;
&lt;br /&gt;
    % Collocate initial guess&lt;br /&gt;
    x0 = {icollocate({x1 == x1opt; x2 == x2opt&lt;br /&gt;
        x3 == x3opt; x4 == x4opt; x5 == x5opt&lt;br /&gt;
        x6 == x6opt; x7 == x7opt})&lt;br /&gt;
        collocate(u == uopt)};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {icollocate({&lt;br /&gt;
        0 &amp;lt;= x1 &amp;lt;= 1; 0 &amp;lt;= x2 &amp;lt;= 1&lt;br /&gt;
        0 &amp;lt;= x3 &amp;lt;= 1; 0 &amp;lt;= x4 &amp;lt;= 1&lt;br /&gt;
        0 &amp;lt;= x5 &amp;lt;= 1; 0 &amp;lt;= x6 &amp;lt;= 1&lt;br /&gt;
        0 &amp;lt;= x7 &amp;lt;= 1})&lt;br /&gt;
        0.6 &amp;lt;= collocate(u) &amp;lt;= 0.9};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x1 == 1; x2 == 0&lt;br /&gt;
        x3 == 0; x4 == 0; x5 == 0&lt;br /&gt;
        x6 == 0; x7 == 0});&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    uvec = [1, u, u.^2, u.^3];&lt;br /&gt;
    k    = (c&#039;*uvec&#039;)&#039;;&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x1) == -k(1)*x1&lt;br /&gt;
        dot(x2) ==  k(1)*x1-(k(2)+k(3))*x2+k(4)*x5&lt;br /&gt;
        dot(x3) ==  k(2)*x2&lt;br /&gt;
        dot(x4) == -k(6)*x4+k(5)*x5&lt;br /&gt;
        dot(x5) ==  k(3)*x2+k(6)*x4-(k(4)+k(5)+k(8)+k(9))*x5+...&lt;br /&gt;
        k(7)*x6+k(10).*x7&lt;br /&gt;
        dot(x6) == k(8)*x5-k(7)*x6&lt;br /&gt;
        dot(x7) == k(9)*x5-k(10)*x7});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = -final(x7);&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Tubular Reactor&#039;;&lt;br /&gt;
    options.d2c = false;&lt;br /&gt;
    Prob = sym2prob(&#039;con&#039;,objective,{cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
    Prob.xInit = 35; % Use 35 random starting points.&lt;br /&gt;
    Prob.GO.localSolver = &#039;snopt&#039;;&lt;br /&gt;
    if n&amp;lt;=10&lt;br /&gt;
        Result = tomRun(&#039;multiMin&#039;, Prob, 1);&lt;br /&gt;
    else&lt;br /&gt;
        Result = tomRun(&#039;snopt&#039;, Prob, 1);&lt;br /&gt;
    end&lt;br /&gt;
    solution = getSolution(Result);&lt;br /&gt;
&lt;br /&gt;
    % Store optimum for use in initial guess&lt;br /&gt;
    x1opt = subs(x1,solution);&lt;br /&gt;
    x2opt = subs(x2,solution);&lt;br /&gt;
    x3opt = subs(x3,solution);&lt;br /&gt;
    x4opt = subs(x4,solution);&lt;br /&gt;
    x5opt = subs(x5,solution);&lt;br /&gt;
    x6opt = subs(x6,solution);&lt;br /&gt;
    x7opt = subs(x7,solution);&lt;br /&gt;
    uopt  = subs(u,solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Tubular Reactor - Trial 10     f_k      -0.010093483541388937&lt;br /&gt;
                                       sum(|constr|)      0.000000004530098742&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.010093479011290195&lt;br /&gt;
&lt;br /&gt;
Solver: multiMin with local solver snopt.  EXIT=0.  INFORM=0.&lt;br /&gt;
Find local optima using multistart local search&lt;br /&gt;
Did 35 local tries. Found 1 global, 31 minima. TotFuncEv 1488. TotConstrEv 1418&lt;br /&gt;
&lt;br /&gt;
FuncEv 1488 GradEv 1418 ConstrEv 1418 ConJacEv   23 Iter  907 &lt;br /&gt;
CPU time: 2.480416 sec. Elapsed time: 2.489000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Tubular Reactor                f_k      -0.010082374603677158&lt;br /&gt;
                                       sum(|constr|)      0.000000000037585022&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.010082374566092137&lt;br /&gt;
                                              f(x_0)     -0.010093483541388937&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv   46 GradEv   44 ConstrEv   44 ConJacEv   44 Iter   31 MinorIter  531&lt;br /&gt;
CPU time: 2.059213 sec. Elapsed time: 2.055000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
t  = collocate(t);&lt;br /&gt;
x7 = collocate(x7opt);&lt;br /&gt;
u  = collocate(uopt);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x7,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x7&#039;);&lt;br /&gt;
title(&#039;Tubular Reactor state variable x7&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Tubular Reactor control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:tubularReactor_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Transfer_Min_Swing&amp;diff=2273</id>
		<title>PROPT Transfer Min Swing</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Transfer_Min_Swing&amp;diff=2273"/>
		<updated>2011-11-09T12:13:29Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Example 7.1: K.L. Teo, K. K. Leong, G.J. Goh&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 1 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{1} 4.5 (x_3^2 + x_6^2) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = 9*x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = 9*x_5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 9*x_6 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = 9*(x_7+17.2656*x_3) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = 9*x_8 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_6}{dt} = -9*\frac{x_7+27.0756*x_3+2*x_5*x_6}{x_2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_7}{dt} = 9*u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_8}{dt} = 9*u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0 \ 22 \ 0 \ 0 \ -1 \ 0 \ NaN \ NaN] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(1) = [10 \ 14 \ 0 \ 2.5 \ 0 \ 0 \ NaN \ NaN] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |x_4| &amp;lt;= 2.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |x_5| &amp;lt;= 1.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |x_7| &amp;lt;= 2.83374 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -0.80865 &amp;lt;= x_8 &amp;lt;= 0.71265 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt;= 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t phi1 phi2&lt;br /&gt;
&lt;br /&gt;
% Starting guess&lt;br /&gt;
speed = 5;&lt;br /&gt;
xopt = 1.2*t;&lt;br /&gt;
yopt = 1.6*t;&lt;br /&gt;
thetaopt = pi/4;&lt;br /&gt;
&lt;br /&gt;
phi1opt = 1;&lt;br /&gt;
phi2opt = 1;&lt;br /&gt;
x1opt = 10*t;&lt;br /&gt;
x2opt = 22-8*t;&lt;br /&gt;
x3opt = 0;&lt;br /&gt;
x4opt = 2.5*t;&lt;br /&gt;
x5opt = -1+t;&lt;br /&gt;
x6opt = 0;&lt;br /&gt;
x7opt = 0;&lt;br /&gt;
x8opt = 0;&lt;br /&gt;
u1opt = 0;&lt;br /&gt;
u2opt = 0;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[20 40]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    % Create a new phase and states, using n collocation points&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 1, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
    tomStates x1 x2 x3 x4 x5 x6 x7 x8&lt;br /&gt;
    tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    x0 = {phi1 == phi1opt; phi2 == phi2opt&lt;br /&gt;
        icollocate({&lt;br /&gt;
        x1 == x1opt; x2 == x2opt&lt;br /&gt;
        x3 == x3opt; x4 == x4opt&lt;br /&gt;
        x5 == x5opt; x6 == x6opt&lt;br /&gt;
        x7 == x7opt; x8 == x8opt})&lt;br /&gt;
        collocate({&lt;br /&gt;
        u1 == u1opt; u2 == u2opt})};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {-10  &amp;lt;= phi1 &amp;lt;= 10&lt;br /&gt;
        -10      &amp;lt;= phi2 &amp;lt;= 10&lt;br /&gt;
        -2.5     &amp;lt;= icollocate(x4) &amp;lt;= 2.5&lt;br /&gt;
        -1       &amp;lt;= icollocate(x5) &amp;lt;= 1&lt;br /&gt;
        -2.83374 &amp;lt;= icollocate(x7) &amp;lt;= 2.83374&lt;br /&gt;
        -0.80865 &amp;lt;= icollocate(x8) &amp;lt;= 0.71265&lt;br /&gt;
        -10      &amp;lt;= collocate(u1) &amp;lt;= 10&lt;br /&gt;
        -10      &amp;lt;= collocate(u2) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = {initial({x1 == 0&lt;br /&gt;
        x2 == 22; x3 == 0&lt;br /&gt;
        x4 == 0;  x5 == -1&lt;br /&gt;
        x6 == 0;  x7 == phi1&lt;br /&gt;
        x8 == phi2&lt;br /&gt;
        })&lt;br /&gt;
        final({x1 == 10&lt;br /&gt;
        x2 == 14;  x3 == 0&lt;br /&gt;
        x4 == 2.5; x5 == 0&lt;br /&gt;
        x6 == 0})};&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    ceq = collocate({dot(x1) == 9*x4&lt;br /&gt;
        dot(x2) == 9*x5; dot(x3) == 9*x6&lt;br /&gt;
        dot(x4) == 9*(x7+17.2656*x3)&lt;br /&gt;
        dot(x5) == 9*x8&lt;br /&gt;
        dot(x6) == -9*(x7+27.0756*x3+2*x5.*x6)./x2&lt;br /&gt;
        dot(x7) == 9*u1; dot(x8) == 9*u2});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = integrate(4.5*(x3.^2 + x6.^2));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Transfer Min Swing&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x and u to use as starting guess in the next iteration&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    x3opt = subs(x3, solution);&lt;br /&gt;
    x4opt = subs(x4, solution);&lt;br /&gt;
    x5opt = subs(x5, solution);&lt;br /&gt;
    x6opt = subs(x6, solution);&lt;br /&gt;
    x7opt = subs(x7, solution);&lt;br /&gt;
    x8opt = subs(x8, solution);&lt;br /&gt;
    u1opt = subs(u1, solution);&lt;br /&gt;
    u2opt = subs(u2, solution);&lt;br /&gt;
    phi1opt = subs(phi1, solution);&lt;br /&gt;
    phi2opt = subs(phi2, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.25702 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Transfer Min Swing             f_k       0.005155677076381541&lt;br /&gt;
                                       sum(|constr|)      0.000000000220310318&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.005155677296691859&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  107 ConJacEv  107 Iter  100 MinorIter  374&lt;br /&gt;
CPU time: 0.187201 sec. Elapsed time: 0.186000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.25108 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Transfer Min Swing             f_k       0.005157874701172190&lt;br /&gt;
                                       sum(|constr|)      0.000000001277942393&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.005157875979114583&lt;br /&gt;
                                              f(x_0)      0.005155729096774491&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  126 ConJacEv  126 Iter  123 MinorIter  594&lt;br /&gt;
CPU time: 0.951606 sec. Elapsed time: 0.965000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = collocate(x1opt);&lt;br /&gt;
x2 = collocate(x2opt);&lt;br /&gt;
x3 = collocate(x3opt);&lt;br /&gt;
x7 = collocate(x7opt);&lt;br /&gt;
x8 = collocate(x8opt);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;);&lt;br /&gt;
title(&#039;Transfer Min Swing state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,x7,&#039;+-&#039;,t,x8,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;x7&#039;,&#039;x8&#039;);&lt;br /&gt;
title(&#039;Transfer Min Swing control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:transferMinSwing_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Time_Delay_2_(Approximate)&amp;diff=2272</id>
		<title>PROPT Time Delay 2 (Approximate)</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Time_Delay_2_(Approximate)&amp;diff=2272"/>
		<updated>2011-11-09T12:13:26Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
8.3.2 Example 2&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
Linear time-delay system considered by Palanisamy et al.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_2(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = t*x_1 + x_1(t-tau) + u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_1^2 + u^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; tau = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Taylor series expansion gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} \approx \frac{(t+1)*x_1 + u }{1 + tau} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -inf &amp;lt;= u &amp;lt;= inf &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
tau = 1;&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == ((t+1).*x1+u)/(1+tau)&lt;br /&gt;
    dot(x2) == x1.^2+u.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Time Delay 2 Appr.&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.070509 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Time Delay 2 Appr.             f_k       5.340734691399960700&lt;br /&gt;
                                       sum(|constr|)      0.000000236393505091&lt;br /&gt;
                              f(x_k) + sum(|constr|)      5.340734927793465500&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   31 ConJacEv   31 Iter   26 MinorIter  138&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.068000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Time Delay 2 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:timeDelay2_approximate_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Time_Delay_2&amp;diff=2271</id>
		<title>PROPT Time Delay 2</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Time_Delay_2&amp;diff=2271"/>
		<updated>2011-11-09T12:13:25Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
8.3.2 Example 2&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
Linear time-delay system considered by Palanisamy et al.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_2(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = t*x_1 + x_1(t-tau) + u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_1^2 + u^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; tau = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t&amp;lt;=0) = [1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -inf &amp;lt;= u &amp;lt;= inf &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, 2, 50);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 0});&lt;br /&gt;
&lt;br /&gt;
% Expression for x1(t-tau)&lt;br /&gt;
tau = 1;&lt;br /&gt;
x1delayed = ifThenElse(t&amp;lt;tau, 1, subs(x1,t,t-tau));&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == t.*x1 + x1delayed + u&lt;br /&gt;
    dot(x2) == x1.^2 + u.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Time Delay 2&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.07238 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Time Delay 2                   f_k       4.796108536142885900&lt;br /&gt;
                                       sum(|constr|)      0.000000305572513302&lt;br /&gt;
                              f(x_k) + sum(|constr|)      4.796108841715399000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   32 ConJacEv   32 Iter   27 MinorIter  137&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.071000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Time Delay 2 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:timeDelay2_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Time_Delay_1_(Approximate)&amp;diff=2270</id>
		<title>PROPT Time Delay 1 (Approximate)</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Time_Delay_1_(Approximate)&amp;diff=2270"/>
		<updated>2011-11-09T12:13:11Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
8.3.1 Example 1&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
Linear time-delay system used for optimal control studies by Chan and Perkins&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 5 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -10*x_1-5*x_2-2*x_1(t-tau)-x_2(t-tau)+u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 0.5*(10*x_1^2+x_2^2+u^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; tau = 0.25 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Taylor series expansion gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} \approx (-12*x_1+(2*tau-6)*x_2 + u)/(1-tau) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [1 \ 1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -inf &amp;lt;= u &amp;lt;= inf &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 1; x3 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 1; x3 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
tau = 0.25;&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == (-12*x1+(2*tau-6)*x2 + u)/(1-tau)&lt;br /&gt;
    dot(x3) == 0.5*(10*x1.^2+x2.^2+u.^2)});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Time Delay 1 Appr.&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.093181 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Time Delay 1 Appr.             f_k       2.387051416916647900&lt;br /&gt;
                                       sum(|constr|)      0.000000035059748131&lt;br /&gt;
                              f(x_k) + sum(|constr|)      2.387051451976395900&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   67 ConJacEv   67 Iter   48 MinorIter  213&lt;br /&gt;
CPU time: 0.249602 sec. Elapsed time: 0.256000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Time Delay 1 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:timeDelay1_approximate_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Time_Delay_1&amp;diff=2269</id>
		<title>PROPT Time Delay 1</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Time_Delay_1&amp;diff=2269"/>
		<updated>2011-11-09T12:13:08Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
8.3.1 Example 1&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
Linear time-delay system used for optimal control studies by Chan and Perkins&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 5 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -10*x_1-5*x_2-2*x_1(t-tau)-x_2(t-tau)+u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 0.5*(10*x_1^2+x_2^2+u^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; tau = 0.25 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t&amp;lt;=0) = [1 \ 1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -inf &amp;lt;= u &amp;lt;= inf &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, 5, 50);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1&lt;br /&gt;
    x2 == 1; x3 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 1; x3 == 0});&lt;br /&gt;
&lt;br /&gt;
% Expressions for x1(t-tau) and x2(t-tau)&lt;br /&gt;
tau = 0.25;&lt;br /&gt;
x1delayed = ifThenElse(t&amp;lt;tau, 1, subs(x1,t,t-tau));&lt;br /&gt;
x2delayed = ifThenElse(t&amp;lt;tau, 1, subs(x2,t,t-tau));&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == -10*x1 - 5*x2 - 2*x1delayed - x2delayed + u&lt;br /&gt;
    dot(x3) == 0.5*(10*x1.^2+x2.^2+u.^2)});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Time Delay 1&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.10007 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Time Delay 1                   f_k       2.525970860473680400&lt;br /&gt;
                                       sum(|constr|)      0.000000011181939804&lt;br /&gt;
                              f(x_k) + sum(|constr|)      2.525970871655620200&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   70 ConJacEv   70 Iter   49 MinorIter  204&lt;br /&gt;
CPU time: 0.249602 sec. Elapsed time: 0.251000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Time Delay 1 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:timeDelay1_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_A_Simple_Terminal_Constraint_Problem&amp;diff=2268</id>
		<title>PROPT A Simple Terminal Constraint Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_A_Simple_Terminal_Constraint_Problem&amp;diff=2268"/>
		<updated>2011-11-09T12:13:00Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Problem 1: Miser3 manual&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u(t) over t in [0; 1 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{1} (x^2 + u^2) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(1) = 0.75 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0.75) = 0.9 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t1&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t1, 0, 0.75, 20);&lt;br /&gt;
toms t2&lt;br /&gt;
p2 = tomPhase(&#039;p2&#039;, t2, 0.75, 0.25, 20);&lt;br /&gt;
&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
tomStates x1p1&lt;br /&gt;
tomControls up1&lt;br /&gt;
setPhase(p2);&lt;br /&gt;
tomStates x1p2&lt;br /&gt;
tomControls up2&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x01 = {icollocate({x1p1 == 1-0.1*t1/0.75})&lt;br /&gt;
    collocate(up1==0.9*t1/0.75)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox1 = {-10 &amp;lt;= icollocate(p1,x1p1) &amp;lt;= 10&lt;br /&gt;
    -10 &amp;lt;= collocate(p1,up1) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd1 = initial(x1p1 == 1);&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq1 = collocate(dot(x1p1) == up1);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective1 = integrate(x1p1.^2+up1.^2);&lt;br /&gt;
&lt;br /&gt;
setPhase(p2);&lt;br /&gt;
% Initial guess&lt;br /&gt;
x02 = {icollocate({x1p2 == 1-0.1*t2})&lt;br /&gt;
    collocate(up2==0.9+0.1*t2)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox2 = {-10 &amp;lt;= icollocate(p2,x1p2) &amp;lt;= 10&lt;br /&gt;
    -10 &amp;lt;= collocate(p2,up2) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd2 = {initial(x1p2 == 0.9)&lt;br /&gt;
    final(x1p2 == 0.75)};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq2 = collocate(dot(x1p2) == up2);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective2 = integrate(x1p2.^2+up2.^2);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = objective1 + objective2;&lt;br /&gt;
&lt;br /&gt;
% Link phase&lt;br /&gt;
link = {final(p1,x1p1) == initial(p2,x1p2)};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Terminal Constraint 2&#039;;&lt;br /&gt;
constr = {cbox1, cbnd1, ceq1, cbox2, cbnd2, ceq2, link};&lt;br /&gt;
solution = ezsolve(objective, constr, {x01, x02}, options);&lt;br /&gt;
&lt;br /&gt;
t = subs(collocate(p1,t1),solution);&lt;br /&gt;
t = [t;subs(collocate(p2,t2),solution)];&lt;br /&gt;
x1 = subs(collocate(p1,x1p1),solution);&lt;br /&gt;
x1 = [x1;subs(collocate(p2,x1p2),solution)];&lt;br /&gt;
u = subs(collocate(p1,up1),solution);&lt;br /&gt;
u = [u;subs(collocate(p2,up2),solution)];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.098918 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Terminal Constraint 2              f_k       0.920531441471499900&lt;br /&gt;
                                       sum(|constr|)      0.000000000474625644&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.920531441946125570&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Barrier QP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
FuncEv    8 GradEv    8 ConstrEv    8 Iter    8 &lt;br /&gt;
CPU time: 0.015600 sec. Elapsed time: 0.004000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;);&lt;br /&gt;
title(&#039;Terminal Constraint state variable&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Terminal Constraint control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:terminalConstraint2_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Temperature_Control&amp;diff=2267</id>
		<title>PROPT Temperature Control</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Temperature_Control&amp;diff=2267"/>
		<updated>2011-11-09T12:12:37Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Optimal Control CY3H2, Lecture notes by Victor M. Becerra, School of Systems Engineering, University of Reading&lt;br /&gt;
&lt;br /&gt;
Heating a room using the least possible energy.&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 1] to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \frac{1}{2} \int_0^{1} u^2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = -2*x + u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = 0, &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(1) = 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2009-2009 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 1, 20);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate(x == 10*t)&lt;br /&gt;
    collocate(u == 1)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = collocate(0 &amp;lt;= u);&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial(x == 0)&lt;br /&gt;
    final(x == 10)};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate(dot(x) == -2*x+u);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = 0.5*integrate(u^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Temperature Control&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
x = subs(collocate(x),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.030845 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Temperature Control                f_k     203.731472072683000000&lt;br /&gt;
                                       sum(|constr|)      0.000000000059135659&lt;br /&gt;
                              f(x_k) + sum(|constr|)    203.731472072742150000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Barrier QP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
FuncEv    9 GradEv    9 ConstrEv    9 Iter    9 &lt;br /&gt;
Elapsed time: 0.003000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1);&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;Temperature&#039;);&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;Energy&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:temperatureControl_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Stirred_Tank&amp;diff=2266</id>
		<title>PROPT Stirred Tank</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Stirred_Tank&amp;diff=2266"/>
		<updated>2011-11-09T12:12:34Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Users Guide for dyn.Opt, Example 5a, 5b, 5c&lt;br /&gt;
&lt;br /&gt;
Stirred-Tank Chemical Reactor - Kirk, D. E., Optimal control theory: An introduction, Prentice-Hall, 1970.&lt;br /&gt;
&lt;br /&gt;
5a - unconstrained with terminal penalty 5b - unconstrained 5c - control constraint&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 0.78 ] to minimize&lt;br /&gt;
&lt;br /&gt;
Does not say u^2 in text&lt;br /&gt;
&lt;br /&gt;
5a:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{0.78} (x_1^2+x_2^2+0.1*u^2)/2 \mathrm{d}t + x_1(t_F)^2 + x_2(t_F)^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5b:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{0.78} (x_1^2+x_2^2+0.1*u^2)/2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5c:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{0.78} (x_1^2+x_2^2)/2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a_1 = x_1 + 0.25 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a_2 = x_2 + 0.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a_3 = x_1 + 2.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a_4 = a_2*exp(25.0*\frac{x_1}{a_3}) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = -2.0*a_1 + a_4 - a_1*u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = 0.5 - x_2 - a_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0.05 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5b, 5c - x(t_F) = [0 0];&lt;br /&gt;
&lt;br /&gt;
5c -  &amp;lt;= 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
&lt;br /&gt;
for i=1:3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 0.78, 40);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates x1 x2&lt;br /&gt;
    tomControls u&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    x0 = {icollocate({x1 == 0.05; x2 == 0})&lt;br /&gt;
        collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {-1.99 &amp;lt;= icollocate(x1) &amp;lt;= 100&lt;br /&gt;
        -100  &amp;lt;= icollocate(x2) &amp;lt;= 100&lt;br /&gt;
        -1000 &amp;lt;= collocate(u) &amp;lt;= 1000};&lt;br /&gt;
    % x1 cannot be equal to -2, setting to greater&lt;br /&gt;
    % to avoid singularity in a2*exp(25.0*x1/a3)&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x1 == 0.05; x2 == 0});&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    a1 = x1 + 0.25; a2 = x2 + 0.5;&lt;br /&gt;
    a3 = x1 + 2.0;  a4 = a2.*exp(25.0*x1./a3);&lt;br /&gt;
&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x1) == -2.0*a1 + a4 - a1.*u&lt;br /&gt;
        dot(x2) == 0.5 - x2 - a4});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    if i==1&lt;br /&gt;
        objective = final(x1)^2+final(x2)^2+...&lt;br /&gt;
            integrate((x1.^2+x2.^2+0.1*u.^2)/2);&lt;br /&gt;
        options.name = &#039;Stirred Tank 5a&#039;;&lt;br /&gt;
        solution1 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
        t1  = subs(collocate(t),solution1);&lt;br /&gt;
        x11 = subs(collocate(x1),solution1);&lt;br /&gt;
        x21 = subs(collocate(x2),solution1);&lt;br /&gt;
        u1  = subs(collocate(u),solution1);&lt;br /&gt;
    elseif i == 2&lt;br /&gt;
        cbnd = {cbnd; final({x1 == 0; x2 == 0})};&lt;br /&gt;
        objective = integrate((x1.^2+x2.^2+0.1*u.^2)/2);&lt;br /&gt;
        options.name = &#039;Stirred Tank 5b&#039;;&lt;br /&gt;
        solution2 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
    else&lt;br /&gt;
        cbnd = {cbnd; final({x1 == 0; x2 == 0})};&lt;br /&gt;
        cbox = {-1.99 &amp;lt;= icollocate(x1) &amp;lt;= 100&lt;br /&gt;
            -100  &amp;lt;= icollocate(x2) &amp;lt;= 100&lt;br /&gt;
            -1    &amp;lt;= collocate(u)   &amp;lt;= 1};&lt;br /&gt;
        objective = integrate((x1.^2+x2.^2)/2);&lt;br /&gt;
        options.name = &#039;Stirred Tank 5c&#039;;&lt;br /&gt;
        solution3 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.20654 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Stirred Tank 5a                f_k       0.014213969120012288&lt;br /&gt;
                                       sum(|constr|)      0.000000005238862716&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.014213974358875005&lt;br /&gt;
                                              f(x_0)      0.003474999999999964&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   30 ConJacEv   30 Iter   27 MinorIter  113&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.054000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.19774 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Stirred Tank 5b                f_k       0.016702811155814214&lt;br /&gt;
                                       sum(|constr|)      0.000000899223600415&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.016703710379414628&lt;br /&gt;
                                              f(x_0)      0.000974999999999998&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   18 ConJacEv   18 Iter   16 MinorIter  121&lt;br /&gt;
CPU time: 0.031200 sec. Elapsed time: 0.037000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.18987 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Stirred Tank 5c                f_k       0.000989922252663804&lt;br /&gt;
                                       sum(|constr|)      0.000000035597654545&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000989957850318349&lt;br /&gt;
                                              f(x_0)      0.000974999999999998&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   14 ConJacEv   13 Iter   10 MinorIter  139&lt;br /&gt;
CPU time: 0.015600 sec. Elapsed time: 0.028000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t1,x11,&#039;*-&#039;,t1,x21,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;Stirred Tank state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t1,u1,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Stirred Tank control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:stirredTank_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Spring_Mass_Damper_(2_Degree_Freedom)&amp;diff=2265</id>
		<title>PROPT Spring Mass Damper (2 Degree Freedom)</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Spring_Mass_Damper_(2_Degree_Freedom)&amp;diff=2265"/>
		<updated>2011-11-09T12:12:31Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
The Direct Approach of General Dynamic Optimal Control: Application on General Software&lt;br /&gt;
&lt;br /&gt;
Tawiwat Veeraklaew, Ph.D. and Settapong Malisuwan, Ph.D. Chulachomklao Royal Military Academy Nakhon-Nayok, Thailand&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = u_1+u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = A*x + B*u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2009 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 60);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
x = [x1;x2;x3;x4];&lt;br /&gt;
u = [u1;u2];&lt;br /&gt;
&lt;br /&gt;
m1 = 1.0; m2 = 1.0; c1 = 1.0; c3 = 1.0;&lt;br /&gt;
c2 = 2.0; k1 = 3.0; k2 = 3.0; k3 = 3.0;&lt;br /&gt;
&lt;br /&gt;
B = [0 0; 1/m1 0;&lt;br /&gt;
    0 0; 0 1/m2];&lt;br /&gt;
&lt;br /&gt;
A = [0 1 0 0;...&lt;br /&gt;
    1/m1*[-(k1+k2) -(c1+c2) k2 c2];...&lt;br /&gt;
    0 0 0 1;...&lt;br /&gt;
    1/m2*[ k2 c2 -(k2+k3) -(c2+c3)]];&lt;br /&gt;
&lt;br /&gt;
x0i = [5; 0; 10; 0];&lt;br /&gt;
xfi = [0; 0;  0; 0];&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0 &amp;lt;= collocate(u) &amp;lt;= 9};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial(x == x0i)&lt;br /&gt;
    final(x == xfi)};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate(dot(x) == A*x+B*u);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(u1+u2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Spring Mass Damper&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, [], options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lp&lt;br /&gt;
Time for symbolic processing: 0.068338 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Spring Mass Damper             f_k      16.485256203083797000&lt;br /&gt;
                                       sum(|constr|)      0.000000005591243026&lt;br /&gt;
                              f(x_k) + sum(|constr|)     16.485256208675040000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Dual Simplex LP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
FuncEv  243 Iter  243 &lt;br /&gt;
CPU time: 0.078000 sec. Elapsed time: 0.041000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Spring Mass Damper state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Spring Mass Damper control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:springSystem_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_6&amp;diff=2264</id>
		<title>PROPT Singular Control 6</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_6&amp;diff=2264"/>
		<updated>2011-11-09T12:12:29Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Viscocity Solutions of Hamilton-Jacobi Equations and Optimal Control Problems. Alberto Bressan, S.I.S.S.A, Trieste, Italy.&lt;br /&gt;
&lt;br /&gt;
A singular control example.&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 10 ] to maximize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_2-x_1^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
t_F = 10;&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, t_F, 80);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
x = [x1; x2; x3];&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0, x2 == 0, x3 == 0})&lt;br /&gt;
    collocate(u==0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial(x == [0;0;0]);&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == u; dot(x2) == -x(1)&lt;br /&gt;
    dot(x3) == x(2)-x(1).^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = -final(x(3));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 6&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
% Extract optimal states and controls from solution&lt;br /&gt;
t  = collocate(subs(t,solution));&lt;br /&gt;
u  = collocate(subs(u,solution));&lt;br /&gt;
x1 = collocate(subs(x1,solution));&lt;br /&gt;
x2 = collocate(subs(x2,solution));&lt;br /&gt;
x3 = collocate(subs(x3,solution));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.076014 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 6             f_k     -55.555568442322517000&lt;br /&gt;
                                       sum(|constr|)      0.000000011402048583&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -55.555568430920466000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   58 ConJacEv   58 Iter   49 MinorIter  678&lt;br /&gt;
CPU time: 0.733205 sec. Elapsed time: 0.738000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(3,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2/10,&#039;*-&#039;,t,x3/50,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2/10&#039;,&#039;x3/50&#039;);&lt;br /&gt;
title(&#039;Singular Control 6 state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(3,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 6 control&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(3,1,3)&lt;br /&gt;
plot(t,-1*(t&amp;lt;t_F/3)+1/2*(t&amp;gt;=t_F/3),&#039;*-&#039;);&lt;br /&gt;
legend(&#039;Known u&#039;);&lt;br /&gt;
title(&#039;Singular Control 6 known solution&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl6_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_5&amp;diff=2263</id>
		<title>PROPT Singular Control 5</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_5&amp;diff=2263"/>
		<updated>2011-11-09T12:12:27Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.3 Yeo&#039;s singular control problem&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 1 ] to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_4(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -x_3*u + 16*x_5 - 8 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = x_1^2 + x_2^2 + 0.0005*(x_2+16*x_5-8-0.1*x_3*u^2)^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0 \ -1 \ -sqrt(5) \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -4 &amp;lt;= u &amp;lt;= 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The state x4 is implemented as a cost directly. x4 in the implementation is x5. u has a low limit of 9 in the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 1, 80);&lt;br /&gt;
setPhase(p)&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0; x2 == -1&lt;br /&gt;
    x3 == -sqrt(5); x4 == 0})&lt;br /&gt;
    collocate(u == 3)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0 &amp;lt;= collocate(u) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 0; x2 == -1&lt;br /&gt;
    x3 == -sqrt(5); x4 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == -x3.*u + 16*x4 - 8&lt;br /&gt;
    dot(x3) == u; dot(x4) == 1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(x1.^2 + x2.^2 + ...&lt;br /&gt;
    0.0005*(x2+16*x4-8-0.1*x3.*u.^2).^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 5&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: con&lt;br /&gt;
Time for symbolic processing: 0.16034 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 5             f_k       0.119318613152343460&lt;br /&gt;
                                       sum(|constr|)      0.000000483936371958&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.119319097088715420&lt;br /&gt;
                                              f(x_0)      1.024412849382206200&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv  374 GradEv  372 ConstrEv  372 ConJacEv  372 Iter  345 MinorIter  938&lt;br /&gt;
CPU time: 4.180827 sec. Elapsed time: 4.185000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 5 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl5_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_4&amp;diff=2262</id>
		<title>PROPT Singular Control 4</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_4&amp;diff=2262"/>
		<updated>2011-11-09T12:12:23Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.2.3 Example 4&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 5 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_4(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = x_1^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [1 \ 0 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 100);&lt;br /&gt;
setPhase(p)&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 0&lt;br /&gt;
    x3 == 0; x4 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 0&lt;br /&gt;
    x3 == 0; x4 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2; dot(x2) == x3&lt;br /&gt;
    dot(x3) == u; dot(x4) == x1.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x4);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 4&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.089315 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 4             f_k       1.252389645383044100&lt;br /&gt;
                                       sum(|constr|)      0.000000063932037643&lt;br /&gt;
                              f(x_k) + sum(|constr|)      1.252389709315081800&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   92 ConJacEv   92 Iter   89 MinorIter  652&lt;br /&gt;
CPU time: 9.313260 sec. Elapsed time: 2.553000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 4 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl4_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_3&amp;diff=2261</id>
		<title>PROPT Singular Control 3</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_3&amp;diff=2261"/>
		<updated>2011-11-09T12:12:21Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.2.3 Example 3&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 5 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_1^2 + x_2^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0 \ 1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 60);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0; x2 == 1; x3 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 0; x2 == 1; x3 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == u; dot(x3) == x1.^2 + x2.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 3&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.08177 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 3             f_k       0.753994561590099140&lt;br /&gt;
                                       sum(|constr|)      0.000000015978036398&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.753994577568135590&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   43 ConJacEv   43 Iter   34 MinorIter  366&lt;br /&gt;
CPU time: 0.265202 sec. Elapsed time: 0.264000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 3 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl3_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_2&amp;diff=2260</id>
		<title>PROPT Singular Control 2</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_2&amp;diff=2260"/>
		<updated>2011-11-09T12:12:18Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.2.2 Example 2&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 5 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_1^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0 \ 1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0; x2 == 1; x3 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 0; x2 == 1; x3 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == u; dot(x3) == x1.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 2&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.07418 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 2             f_k       0.268336059478540940&lt;br /&gt;
                                       sum(|constr|)      0.000000004483166969&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.268336063961707890&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  107 ConJacEv  107 Iter  100 MinorIter  353&lt;br /&gt;
CPU time: 0.343202 sec. Elapsed time: 0.333000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 2 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl2_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Control_1&amp;diff=2259</id>
		<title>PROPT Singular Control 1</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Control_1&amp;diff=2259"/>
		<updated>2011-11-09T12:12:14Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.2.1 Example 1&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_2(t_F) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = 0.5*x_1^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == u&lt;br /&gt;
    dot(x2) == 0.5*x1.^2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Control 1&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.064118 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Control 1             f_k       0.166665695130345510&lt;br /&gt;
                                       sum(|constr|)      0.000000330654862346&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.166666025785207870&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   41 ConJacEv   41 Iter   39 MinorIter  164&lt;br /&gt;
CPU time: 0.078001 sec. Elapsed time: 0.079000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Control 1 control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularControl1_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_CSTR&amp;diff=2258</id>
		<title>PROPT Singular CSTR</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_CSTR&amp;diff=2258"/>
		<updated>2011-11-09T12:12:13Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
10.4 Nonlinear two-stage CSTR problem&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t_F ] to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x(t_F)&#039;*x(t_F) + t_F &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(the state variables are moved to bounds)&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = -3*x_1+g_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -11.1558*x_2+g_1-8.1558*(x_2+0.1592)*u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 1.5*(0.5*x_1-x_3)+g_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = 0.75*x_2-4.9385*x_4+g_2-3.4385*(x_4+0.122)*u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g_1 = 1.5e7*(0.5251-x_1)*exp(-\frac{10}{x_2+0.6932})- &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 1.5e10*(0.4748+x_1)*exp(-\frac{15}{x_2+0.6932}) - 1.4280 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g_2 = 1.5e7*(0.4236-x_2)*exp(-\frac{10}{x_4+0.6560})- &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 1.5e10*(0.5764+x_3)*exp(-\frac{15}{x4+0.6560}) - 0.5086 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [0.1962 \ -0.0372 \ 0.0946 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u(1:2) &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t t_f&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, t_f, 30);&lt;br /&gt;
setPhase(p)&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {t_f == 0.3&lt;br /&gt;
    icollocate({x1 == 0.1962; x2 == -0.0372&lt;br /&gt;
    x3 == 0.0946; x4 == 0})&lt;br /&gt;
    collocate({u1 == 0; u2 == 0})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0.1 &amp;lt;= t_f &amp;lt;= 100&lt;br /&gt;
    -1 &amp;lt;= collocate(u1) &amp;lt;= 1&lt;br /&gt;
    -1 &amp;lt;= collocate(u2) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == 0.1962; x2 == -0.0372&lt;br /&gt;
    x3 == 0.0946; x4 == 0})&lt;br /&gt;
    final({x1 == 0; x2 == 0&lt;br /&gt;
    x3 == 0; x4 == 0})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
g1 = 1.5e7*(0.5251-x1).*exp(-10./(x2+0.6932)) ...&lt;br /&gt;
    - 1.5e10*(0.4748+x1).*exp(-15./(x2+0.6932)) - 1.4280;&lt;br /&gt;
g2 = 1.5e7*(0.4236-x2).*exp(-10./(x4+0.6560)) ...&lt;br /&gt;
    - 1.5e10*(0.5764+x3).*exp(-15./(x4+0.6560)) - 0.5086;&lt;br /&gt;
&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == -3*x1+g1&lt;br /&gt;
    dot(x2) == -11.1558*x2+g1-8.1558*(x2+0.1592).*u1&lt;br /&gt;
    dot(x3) == 1.5*(0.5*x1-x3)+g2&lt;br /&gt;
    dot(x4) == 0.75*x2-4.9385*x4+g2-3.4385*(x4+0.122).*u2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular CSTR&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.51719 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular CSTR                  f_k       0.324402684069356740&lt;br /&gt;
                                       sum(|constr|)      0.000000010809237995&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.324402694878594740&lt;br /&gt;
                                              f(x_0)      0.299999999999999990&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   75 ConJacEv   75 Iter   42 MinorIter  427&lt;br /&gt;
CPU time: 0.187201 sec. Elapsed time: 0.192000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Singular CSTR state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Singular CSTR control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularCSTR_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Singular_Arc_Problem&amp;diff=2257</id>
		<title>PROPT Singular Arc Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Singular_Arc_Problem&amp;diff=2257"/>
		<updated>2011-11-09T12:12:10Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Problem 3: Miser3 manual&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u(t) over t in [0; t_f ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_f &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = cos(x_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = sin(x_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(t_f) = x_3(t_f) = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt;= 2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [\frac{pi}{2} \ 4 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms t_f&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, t_f, 60);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {t_f == 20&lt;br /&gt;
    icollocate({&lt;br /&gt;
    x1 == pi/2+pi/2*t/t_f&lt;br /&gt;
    x2 == 4-4*t/t_f; x3 == 0})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {2 &amp;lt;= t_f &amp;lt;= 1000&lt;br /&gt;
    -2 &amp;lt;= collocate(u) &amp;lt;= 2};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == pi/2; x2 == 4; x3 == 0})&lt;br /&gt;
    final({x2 == 0; x3 == 0})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == u&lt;br /&gt;
    dot(x2) == cos(x1); dot(x3) == sin(x1)});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Singular Arc&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.1042 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Singular Arc                   f_k       4.321198387073171600&lt;br /&gt;
                                       sum(|constr|)      0.000000179336713690&lt;br /&gt;
                              f(x_k) + sum(|constr|)      4.321198566409885100&lt;br /&gt;
                                              f(x_0)     20.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   77 ConJacEv   77 Iter   70 MinorIter  377&lt;br /&gt;
CPU time: 0.483603 sec. Elapsed time: 0.473000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;);&lt;br /&gt;
title(&#039;Singular Arc state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Singular Arc control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:singularArc_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Simple_Bang_Bang_Problem&amp;diff=2256</id>
		<title>PROPT Simple Bang Bang Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Simple_Bang_Bang_Problem&amp;diff=2256"/>
		<updated>2011-11-09T12:12:08Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Function Space Complementarity Methods for Optimal Control Problems, Dissertation, Martin Weiser&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [-0.5; 0.5 ] to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_{-\frac{1}{2}}^{\frac{1}{2}} t*u \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, -0.5, 1, 20);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
tomStates x&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {collocate(u == 1-2*(t+0.5))&lt;br /&gt;
    icollocate(x == 1-2*(t+0.5))};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1 &amp;lt;= icollocate(x) &amp;lt;= 1&lt;br /&gt;
    -1 &amp;lt;= collocate(u)  &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate(dot(x) == 0);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(t.*u);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Simple Bang Bang Problem&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, ceq}, x0, options);&lt;br /&gt;
t = subs(collocate(t),solution);&lt;br /&gt;
u = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lp&lt;br /&gt;
Time for symbolic processing: 0.013436 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Simple Bang Bang Problem       f_k      -0.250490325030180820&lt;br /&gt;
                                       sum(|constr|)      0.000000000000870996&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.250490325029309850&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Dual Simplex LP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Elapsed time: 0.002000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1);&lt;br /&gt;
plot(t,u,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
ylim([-1.1,1.1]);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simpleBangBang_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Space_Shuttle_Reentry&amp;diff=2255</id>
		<title>PROPT Space Shuttle Reentry</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Space_Shuttle_Reentry&amp;diff=2255"/>
		<updated>2011-11-09T12:12:03Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
SOCS 6.5.0 Manual&lt;br /&gt;
&lt;br /&gt;
7.4.4 Maximum Crossrange Space Shuttle Reentry Problem.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t ] to maximize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = lat &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
The equations given in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t t_f&lt;br /&gt;
&lt;br /&gt;
% Scaled time&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, t_f, 30);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates alt long lat vel ggamma azi&lt;br /&gt;
tomControls aalpha bbeta&lt;br /&gt;
&lt;br /&gt;
% Constants&lt;br /&gt;
tGuess = 2000;&lt;br /&gt;
tMax   = 4000;&lt;br /&gt;
tMin   = 100;&lt;br /&gt;
cr2d    = 180/pi;&lt;br /&gt;
betalim = 90;&lt;br /&gt;
weight  = 203000;&lt;br /&gt;
cm2w    = 32.174;&lt;br /&gt;
cea     = 20902900;&lt;br /&gt;
mmu      = 0.14076539e17;&lt;br /&gt;
rho0    = 0.002378;&lt;br /&gt;
href    = 23800;&lt;br /&gt;
cl0     = -0.20704;&lt;br /&gt;
cl1     = 0.029244;&lt;br /&gt;
cd0     = 0.07854;&lt;br /&gt;
cd1     = -6.1592e-3;&lt;br /&gt;
cd2     = 6.21408e-4;&lt;br /&gt;
sref    = 2690;&lt;br /&gt;
&lt;br /&gt;
alt0 = 260000;&lt;br /&gt;
altf = 80000;&lt;br /&gt;
&lt;br /&gt;
vel0 = 25600;&lt;br /&gt;
velf = 2500;&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {&lt;br /&gt;
    t_f == 1000&lt;br /&gt;
    icollocate({&lt;br /&gt;
    alt   == alt0-(alt0-altf)*t/t_f&lt;br /&gt;
    long  == -0.5*90/cr2d&lt;br /&gt;
    lat   == -89/cr2d&lt;br /&gt;
    vel   == vel0-(vel0-velf)*t/t_f&lt;br /&gt;
    ggamma == -1/cr2d-4/cr2d*t/t_f&lt;br /&gt;
    azi   == pi/2-pi*t/t_f&lt;br /&gt;
    })&lt;br /&gt;
    collocate({&lt;br /&gt;
    aalpha == 0&lt;br /&gt;
    bbeta  == 1/cr2d&lt;br /&gt;
    })&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {&lt;br /&gt;
    initial({&lt;br /&gt;
    alt   == alt0&lt;br /&gt;
    long  == -0.5*75.3153/cr2d&lt;br /&gt;
    lat   == 0&lt;br /&gt;
    vel   == 25600&lt;br /&gt;
    ggamma == -1/cr2d&lt;br /&gt;
    azi   == 90/cr2d&lt;br /&gt;
    aalpha == 17/cr2d&lt;br /&gt;
    bbeta  == -betalim/cr2d&lt;br /&gt;
    })&lt;br /&gt;
    final({&lt;br /&gt;
    alt   == altf&lt;br /&gt;
    vel   == velf&lt;br /&gt;
    ggamma == -5/cr2d&lt;br /&gt;
    })};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {&lt;br /&gt;
    100 &amp;lt;= t_f &amp;lt;= 5000&lt;br /&gt;
    0             &amp;lt;= icollocate(alt)   &amp;lt;= 300000&lt;br /&gt;
    -0.5*90/cr2d  &amp;lt;= icollocate(long)  &amp;lt;= 0.5*90/cr2d&lt;br /&gt;
    -89/cr2d      &amp;lt;= icollocate(lat)   &amp;lt;= 89/cr2d&lt;br /&gt;
    1000          &amp;lt;= icollocate(vel)   &amp;lt;= 40000&lt;br /&gt;
    -89/cr2d      &amp;lt;= icollocate(ggamma) &amp;lt;= 89/cr2d&lt;br /&gt;
    -pi           &amp;lt;= icollocate(azi)   &amp;lt;= pi&lt;br /&gt;
    -89/cr2d      &amp;lt;= collocate(aalpha)  &amp;lt;= 89/cr2d&lt;br /&gt;
    -betalim/cr2d &amp;lt;= collocate(bbeta)   &amp;lt;= 1/cr2d&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
mass   = weight/cm2w;&lt;br /&gt;
alphad = cr2d*aalpha;&lt;br /&gt;
radius = cea+alt;&lt;br /&gt;
grav   = mmu./radius.^2;&lt;br /&gt;
&lt;br /&gt;
rhodns = rho0*exp(-alt/href);&lt;br /&gt;
dynp   = 0.5*rhodns.*vel.^2;&lt;br /&gt;
subl   = cl0+cl1*alphad;&lt;br /&gt;
subd   = cd0+cd1+cd2*alphad.*alphad;&lt;br /&gt;
drag   = dynp.*subd*sref;&lt;br /&gt;
lift   = dynp.*subl*sref;&lt;br /&gt;
vrelg  = vel./radius-grav./vel;&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(alt) == vel.*sin(ggamma)&lt;br /&gt;
    dot(long) == vel.*cos(ggamma).*sin(azi)./(radius.*cos(lat))&lt;br /&gt;
    dot(lat) == vel.*cos(ggamma).*cos(azi)./radius&lt;br /&gt;
    dot(vel) == -drag./mass-grav.*sin(ggamma)&lt;br /&gt;
    dot(ggamma) == lift.*cos(bbeta)./(mass.*vel)+cos(ggamma).*vrelg&lt;br /&gt;
    dot(azi) == lift.*sin(bbeta)./(mass.*vel.*cos(ggamma))+...&lt;br /&gt;
    vel.*cos(ggamma).*sin(azi).*sin(lat)./(radius.*cos(lat))&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = -final(lat)*180/pi;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Shuttle Reentry&#039;;&lt;br /&gt;
options.Prob.SOL.optPar(30) = 100000;&lt;br /&gt;
options.scale = &#039;auto&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Auto-scaling&lt;br /&gt;
Time for symbolic processing: 0.90962 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Shuttle Reentry                f_k     -15.142919504944096000&lt;br /&gt;
                                       sum(|constr|)      0.000000004261906835&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -15.142919500682190000&lt;br /&gt;
                                              f(x_0)     -0.000000000000795808&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv 3700 ConJacEv 3698 Iter  424 MinorIter 5688&lt;br /&gt;
CPU time: 40.139057 sec. Elapsed time: 10.405000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,3,1)&lt;br /&gt;
ezplot(alt)&lt;br /&gt;
legend(&#039;alt&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry altitude&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,3,2)&lt;br /&gt;
ezplot(vel)&lt;br /&gt;
legend(&#039;vel&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry velocity&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,3,3)&lt;br /&gt;
ezplot(long)&lt;br /&gt;
legend(&#039;long&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry longitude&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,3,4)&lt;br /&gt;
ezplot(lat)&lt;br /&gt;
legend(&#039;lat&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry latitude&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,3,5)&lt;br /&gt;
ezplot(aalpha)&lt;br /&gt;
legend(&#039;aalpha&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry aalpha&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,3,6)&lt;br /&gt;
ezplot(bbeta)&lt;br /&gt;
legend(&#039;bbeta&#039;);&lt;br /&gt;
title(&#039;Shuttle Reentry bbeta&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:shuttleEntry_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Second_Order_System&amp;diff=2254</id>
		<title>PROPT Second Order System</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Second_Order_System&amp;diff=2254"/>
		<updated>2011-11-09T12:11:59Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Users Guide for dyn.Opt, Example 1&lt;br /&gt;
&lt;br /&gt;
Optimal control of a second order system&lt;br /&gt;
&lt;br /&gt;
End time says 1 in problem text.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{2} u^2/2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1(0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1(2) = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(2) = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -100 &amp;lt;= u &amp;lt;= 100 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1-t/2; x2 == -1+t/2})&lt;br /&gt;
    collocate(u == -3.5+6*t/2)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-100 &amp;lt;= icollocate(x1) &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= icollocate(x2) &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= collocate(u)   &amp;lt;= 100};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == 1; x2 == 1})&lt;br /&gt;
    final({x1 == 0; x2 == 0})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2; dot(x2) == u});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(u.^2/2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Second Order System&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.050283 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Second Order System                f_k       3.249999999994048800&lt;br /&gt;
                                       sum(|constr|)      0.000000000461823724&lt;br /&gt;
                              f(x_k) + sum(|constr|)      3.250000000455872700&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Barrier QP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
FuncEv    6 GradEv    6 ConstrEv    6 Iter    6 &lt;br /&gt;
Elapsed time: 0.004000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;Second Order System state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Second Order System control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:secondOrderSystem_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Satellite_Control&amp;diff=2253</id>
		<title>PROPT Satellite Control</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Satellite_Control&amp;diff=2253"/>
		<updated>2011-11-09T12:11:57Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Users Guide for dyn.Opt, Example 7a, 7b, 7c&lt;br /&gt;
&lt;br /&gt;
==A satellite control problem==&lt;br /&gt;
&lt;br /&gt;
Find T (controls) over t in [0; 100 ] to minimize&lt;br /&gt;
&lt;br /&gt;
7c is free end time&lt;br /&gt;
&lt;br /&gt;
7a:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{100} ((T1^2+T2^2+T3^2)*0.5) \mathrm{d}t + &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; w_1^2 + w_2^2 + w_3^2 + (e_1 - 0.70106)^2 + (e_2 - 0.0923)^2 + (e_3 - 0.56098)^2 + (e_4 - 0.43047)^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7b:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{100} ((T1^2+T2^2+T3^2)*0.5) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7c:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_F &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I1 = 1.0e6 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I2 = 833333.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I3 = 916667.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; T1S = 550 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; T2S = 50 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; T3S = 550 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{de_1}{dt} = 0.5*(w_1*e_4-w_2*e_3+w_3*e_2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{de_2}{dt} = 0.5*(w_1*e_3+w_2*e_4-w_3*e_1) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{de_3}{dt} = 0.5*(-w_1*e_2+w_2*e_1+w_3*e_4) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{de_4}{dt} = -0.5*(w_1*e_1+w_2*e_2+w_3*e_3) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dw_1}{dt} = \frac{(I2-I3)*w_2*w_3+T1*T1S}{I1} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dw_2}{dt} = \frac{(I3-I1)*w3*w1+T2*T2S}{I2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dw_3}{dt} = \frac{(I1-I2)*w1*w2+T3*T3S}{I3} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; e(0) = [0 \ 0 \ 0 \ 1] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; w(0) = [0.01 \ 0.005 \ 0.001] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7b, 7c - x(100) = [0.70106 0.0923 0.56098 NaN 0 0 0]; 7c - free time 7c - -1 &amp;lt;= T &amp;lt;= 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
&lt;br /&gt;
% Starting guess&lt;br /&gt;
e1opt = 0;&lt;br /&gt;
e2opt = 0;&lt;br /&gt;
e3opt = 0;&lt;br /&gt;
e4opt = 0;&lt;br /&gt;
w1opt = 0;&lt;br /&gt;
w2opt = 0;&lt;br /&gt;
w3opt = 0;&lt;br /&gt;
T1opt = 0;&lt;br /&gt;
T2opt = 0;&lt;br /&gt;
T3opt = 0;&lt;br /&gt;
&lt;br /&gt;
% Final times&lt;br /&gt;
tfs = zeros(3,1);&lt;br /&gt;
&lt;br /&gt;
for i=1:3&lt;br /&gt;
    if i == 3&lt;br /&gt;
        toms t_f&lt;br /&gt;
        runs = [10 20 101];&lt;br /&gt;
    else&lt;br /&gt;
        runs = [10 40];&lt;br /&gt;
    end&lt;br /&gt;
    if i == 2&lt;br /&gt;
        e1opt = 0; e2opt = 0;&lt;br /&gt;
        e3opt = 0; e4opt = 0;&lt;br /&gt;
        w1opt = 0; w2opt = 0;&lt;br /&gt;
        w3opt = 0; T1opt = 0;&lt;br /&gt;
        T2opt = 0; T3opt = 0;&lt;br /&gt;
    end&lt;br /&gt;
    for n=runs&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
        if i == 3&lt;br /&gt;
            p = tomPhase(&#039;p&#039;, t, 0, t_f, n);&lt;br /&gt;
        else&lt;br /&gt;
            p = tomPhase(&#039;p&#039;, t, 0, 100, n);&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        setPhase(p);&lt;br /&gt;
        tomStates e1 e2 e3 e4 w1 w2 w3&lt;br /&gt;
        tomControls T1 T2 T3&lt;br /&gt;
&lt;br /&gt;
        if i == 3&lt;br /&gt;
            x0 = {t_f == 100};&lt;br /&gt;
        else&lt;br /&gt;
            x0 = {};&lt;br /&gt;
        end&lt;br /&gt;
        % Initial guess&lt;br /&gt;
        x0 = {x0; collocate({T1 == T1opt&lt;br /&gt;
            T2 == T2opt; T3 == T3opt})&lt;br /&gt;
            icollocate({&lt;br /&gt;
            e1 == e1opt; e2 == e2opt&lt;br /&gt;
            e3 == e3opt; e4 == e4opt&lt;br /&gt;
            w1 == w1opt; w2 == w2opt&lt;br /&gt;
            w3 == w3opt})};&lt;br /&gt;
&lt;br /&gt;
        if i == 3&lt;br /&gt;
            cbox = {&lt;br /&gt;
                1 &amp;lt;= t_f &amp;lt;= 1000&lt;br /&gt;
                -1 &amp;lt;= collocate(T1) &amp;lt;= 1&lt;br /&gt;
                -1 &amp;lt;= collocate(T2) &amp;lt;= 1&lt;br /&gt;
                -1 &amp;lt;= collocate(T3) &amp;lt;= 1};&lt;br /&gt;
        else&lt;br /&gt;
            cbox = {};&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % Boundary constraints&lt;br /&gt;
        cbnd = initial({e1 == 0&lt;br /&gt;
            e2 == 0;     e3 == 0&lt;br /&gt;
            e4 == 1;     w1 == 0.01&lt;br /&gt;
            w2 == 0.005; w3 == 0.001});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem 7b and 7c modifications==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
        if i ~= 1&lt;br /&gt;
            cbnd = {cbnd&lt;br /&gt;
                final({&lt;br /&gt;
                e1 == 0.70106&lt;br /&gt;
                e2 == 0.0923&lt;br /&gt;
                e3 == 0.56098&lt;br /&gt;
                w1 == 0&lt;br /&gt;
                w2 == 0&lt;br /&gt;
                w3 == 0&lt;br /&gt;
                })};&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        % ODEs and path constraints&lt;br /&gt;
        I1 = 1.0e6;&lt;br /&gt;
        I2 = 833333.0;&lt;br /&gt;
        I3 = 916667.0;&lt;br /&gt;
        T1Sc = 550;&lt;br /&gt;
        T2Sc = 50;&lt;br /&gt;
        T3Sc = 550;&lt;br /&gt;
        ceq = collocate({&lt;br /&gt;
            dot(e1) == 0.5*(w1.*e4-w2.*e3+w3.*e2)&lt;br /&gt;
            dot(e2) == 0.5*(w1.*e3+w2.*e4-w3.*e1)&lt;br /&gt;
            dot(e3) == 0.5*(-w1.*e2+w2.*e1+w3.*e4)&lt;br /&gt;
            dot(e4) == -0.5*(w1.*e1+w2.*e2+w3.*e3)&lt;br /&gt;
            dot(w1) == ((I2-I3)*w2.*w3+T1*T1Sc)/I1&lt;br /&gt;
            dot(w2) == ((I3-I1)*w3.*w1+T2*T2Sc)/I2&lt;br /&gt;
            dot(w3) == ((I1-I2)*w1.*w2+T3*T3Sc)/I3});&lt;br /&gt;
&lt;br /&gt;
        % Objective&lt;br /&gt;
        if i == 1&lt;br /&gt;
            objective = final(w1)^2 + final(w2)^2 + final(w3)^2 +...&lt;br /&gt;
                (final(e1) - 0.70106)^2 + (final(e2) - 0.0923)^2 + ...&lt;br /&gt;
                (final(e3) - 0.56098)^2 + (final(e4) - 0.43047)^2 ...&lt;br /&gt;
                + integrate((T1.^2+T2.^2+T3.^2)*0.5);&lt;br /&gt;
        elseif i == 2&lt;br /&gt;
            objective = integrate((T1.^2+T2.^2+T3.^2)*0.5);&lt;br /&gt;
        else&lt;br /&gt;
            objective = t_f;&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
        options = struct;&lt;br /&gt;
        if i == 1&lt;br /&gt;
            options.name = &#039;Satellite Control 7a&#039;;&lt;br /&gt;
        elseif i == 2&lt;br /&gt;
            options.name = &#039;Satellite Control 7b&#039;;&lt;br /&gt;
        else&lt;br /&gt;
            options.name = &#039;Satellite Control 7c&#039;;&lt;br /&gt;
        end&lt;br /&gt;
        solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
        e1opt = subs(e1, solution);&lt;br /&gt;
        e2opt = subs(e2, solution);&lt;br /&gt;
        e3opt = subs(e3, solution);&lt;br /&gt;
        e4opt = subs(e4, solution);&lt;br /&gt;
        w1opt = subs(w1, solution);&lt;br /&gt;
        w2opt = subs(w2, solution);&lt;br /&gt;
        w3opt = subs(w3, solution);&lt;br /&gt;
        T1opt = subs(T1, solution);&lt;br /&gt;
        T2opt = subs(T2, solution);&lt;br /&gt;
        T3opt = subs(T3, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.41532 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7a           f_k       0.463944669252504660&lt;br /&gt;
                                       sum(|constr|)      0.000000135115456869&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.463944804367961540&lt;br /&gt;
                                              f(x_0)      0.139185999999999230&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   27 ConJacEv   27 Iter   15 MinorIter  105&lt;br /&gt;
CPU time: 0.031200 sec. Elapsed time: 0.040000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.4063 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7a           f_k       0.463944366974705650&lt;br /&gt;
                                       sum(|constr|)      0.000000000342695654&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.463944367317401300&lt;br /&gt;
                                              f(x_0)     -0.536077645550791850&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    3 ConJacEv    3 Iter    2 MinorIter  255&lt;br /&gt;
CPU time: 0.078000 sec. Elapsed time: 0.082000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.37013 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7b           f_k      71.411903807059332000&lt;br /&gt;
                                       sum(|constr|)      0.000000066784327540&lt;br /&gt;
                              f(x_k) + sum(|constr|)     71.411903873843656000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   20 ConJacEv   20 Iter   17 MinorIter  205&lt;br /&gt;
CPU time: 0.031200 sec. Elapsed time: 0.041000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.37064 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7b           f_k      71.411593978635054000&lt;br /&gt;
                                       sum(|constr|)      0.000000015292228483&lt;br /&gt;
                              f(x_k) + sum(|constr|)     71.411593993927283000&lt;br /&gt;
                                              f(x_0)     71.236662445283315000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    5 ConJacEv    5 Iter    3 MinorIter  346&lt;br /&gt;
CPU time: 0.156001 sec. Elapsed time: 0.155000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.44253 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7c           f_k      99.185331597188878000&lt;br /&gt;
                                       sum(|constr|)      0.000010903612748681&lt;br /&gt;
                              f(x_k) + sum(|constr|)     99.185342500801625000&lt;br /&gt;
                                              f(x_0)    100.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    8 ConJacEv    8 Iter    6 MinorIter   83&lt;br /&gt;
CPU time: 0.031200 sec. Elapsed time: 0.024000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.4436 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7c           f_k      98.945461990937730000&lt;br /&gt;
                                       sum(|constr|)      0.000017743233813344&lt;br /&gt;
                              f(x_k) + sum(|constr|)     98.945479734171542000&lt;br /&gt;
                                              f(x_0)    100.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    5 ConJacEv    5 Iter    4 MinorIter  154&lt;br /&gt;
CPU time: 0.046800 sec. Elapsed time: 0.041000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.44408 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Satellite Control 7c           f_k      98.834204968061897000&lt;br /&gt;
                                       sum(|constr|)      0.000012503591248200&lt;br /&gt;
                              f(x_k) + sum(|constr|)     98.834217471653147000&lt;br /&gt;
                                              f(x_0)    100.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    7 ConJacEv    7 Iter    6 MinorIter  972&lt;br /&gt;
CPU time: 5.756437 sec. Elapsed time: 2.873000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    end&lt;br /&gt;
    tfs(i) = subs(final(t),solution);&lt;br /&gt;
    % We only want to plot the solution from the first problem&lt;br /&gt;
    if i == 1&lt;br /&gt;
        tp  = subs(collocate(t),solution);&lt;br /&gt;
        e1p = subs(collocate(e1),solution);&lt;br /&gt;
        e2p = subs(collocate(e2),solution);&lt;br /&gt;
        e3p = subs(collocate(e3),solution);&lt;br /&gt;
        e4p = subs(collocate(e4),solution);&lt;br /&gt;
        w1p = subs(collocate(w1),solution);&lt;br /&gt;
        w2p = subs(collocate(w2),solution);&lt;br /&gt;
        w3p = subs(collocate(w3),solution);&lt;br /&gt;
        T1p = subs(collocate(T1),solution);&lt;br /&gt;
        T2p = subs(collocate(T2),solution);&lt;br /&gt;
        T3p = subs(collocate(T3),solution);&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
disp(sprintf(&#039;\nFinal time for 7a = %1.4g&#039;,tfs(1)));&lt;br /&gt;
disp(sprintf(&#039;\nFinal time for 7b = %1.4g&#039;,tfs(2)));&lt;br /&gt;
disp(sprintf(&#039;\nFinal time for 7c = %1.4g&#039;,tfs(3)));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Final time for 7a = 100&lt;br /&gt;
&lt;br /&gt;
Final time for 7b = 100&lt;br /&gt;
&lt;br /&gt;
Final time for 7c = 98.83&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(3,1,1)&lt;br /&gt;
plot(tp,e1p,&#039;*-&#039;,tp,e2p,&#039;*-&#039;,tp,e3p,&#039;*-&#039;,tp,e4p,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;e1&#039;,&#039;e2&#039;,&#039;e3&#039;,&#039;e4&#039;);&lt;br /&gt;
title(&#039;Satellite Control state variables (e)&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(3,1,2)&lt;br /&gt;
plot(tp,w1p,&#039;*-&#039;,tp,w2p,&#039;*-&#039;,tp,w3p);&lt;br /&gt;
legend(&#039;w1&#039;,&#039;w2&#039;,&#039;w3&#039;);&lt;br /&gt;
title(&#039;Satellite Control state variables (w)&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(3,1,3)&lt;br /&gt;
plot(tp,T1p,&#039;+-&#039;,tp,T2p,&#039;+-&#039;,tp,T3p,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;T1&#039;,&#039;T2&#039;,&#039;T3&#039;);&lt;br /&gt;
title(&#039;Satellite Control controls&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:satelliteControl_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Time-optimal_Trajectories_for_Robot_Manipulators&amp;diff=2252</id>
		<title>PROPT Time-optimal Trajectories for Robot Manipulators</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Time-optimal_Trajectories_for_Robot_Manipulators&amp;diff=2252"/>
		<updated>2011-11-09T12:11:51Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Users Guide for dyn.Opt, Example 2&lt;br /&gt;
&lt;br /&gt;
Dissanayake, M., Goh, C. J., &amp;amp; Phan-Thien, N., Time-optimal Trajectories for Robot Manipulators, Robotica, Vol. 9, pp. 131-138, 1991.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t_F ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_F &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0)  = [0 \ -2 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_F) = [1 \ -1 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; L_1 = 0.4; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; L_2 = 0.4; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; m_1 = 0.5; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; m_2 = 0.5; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; Eye_1 = 0.1; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; Eye_2 = 0.1; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; el_1 = 0.2; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; el_2 = 0.2; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; cos(x2) = cos(x_2); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_{11} = Eye_1 + Eye_2 + m_1*el_1^2 + m_2*(L_1^2+el_2^2+2.0*L_1*el_2*cos(x2)); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_{12} = Eye_2 + m_2*el_2^2 + m_2*L_1*el_2*cos(x2); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_{22} = Eye_2 + m_2*el_2^2; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; h = m_2*L_1*el_2*sin(x_2); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; delta = \frac{1.0}{H_{11}*H_{22}-H_{12}*H_{12}}; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = delta*(2.0*h*H_{22}*x_3*x_4+h*H_{22}*x_4^2 + h*H_{12}*x_3^2+H_{22}*u_1-H_{12}*u_2); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = delta*(-2.0*h*H_{12}*x_3*x_4-h*H_{11}*x_3^2- h*H_{12}*x_4^2+H_{11}*u_2-H_{12}*u_1); &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -10 &amp;lt;= u &amp;lt;= 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms t_f&lt;br /&gt;
&lt;br /&gt;
tfopt = 7;&lt;br /&gt;
x1opt = 1*t/t_f;&lt;br /&gt;
x2opt = -2+1*t/t_f;&lt;br /&gt;
x3opt = 2;&lt;br /&gt;
x4opt = 4;&lt;br /&gt;
u1opt = 10-20*t/t_f;&lt;br /&gt;
u2opt = -10+20*t/t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[30 60]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, t_f, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates x1 x2 x3 x4&lt;br /&gt;
    tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    x0 = {t_f == tfopt&lt;br /&gt;
        icollocate({&lt;br /&gt;
        x1 == x1opt&lt;br /&gt;
        x2 == x2opt&lt;br /&gt;
        x3 == x3opt&lt;br /&gt;
        x4 == x4opt})&lt;br /&gt;
        collocate({&lt;br /&gt;
        u1 == u1opt&lt;br /&gt;
        u2 == u2opt})};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {&lt;br /&gt;
        0.1 &amp;lt;= t_f &amp;lt;= 50&lt;br /&gt;
        -10 &amp;lt;= collocate(u1) &amp;lt;= 10&lt;br /&gt;
        -10 &amp;lt;= collocate(u2) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = {initial({x1 == 0; x2 == -2&lt;br /&gt;
        x3 == 0; x4 == 0})&lt;br /&gt;
        final({x1 == 1; x2 == -1&lt;br /&gt;
        x3 == 0; x4 == 0})};&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    L_1 = 0.4;   L_2 = 0.4;&lt;br /&gt;
    m_1 = 0.5;   m_2 = 0.5;&lt;br /&gt;
    Eye_1 = 0.1; Eye_2 = 0.1;&lt;br /&gt;
    el_1 = 0.2;  el_2 = 0.2;&lt;br /&gt;
&lt;br /&gt;
    H_11  = Eye_1 + Eye_2 + m_1*el_1^2+ ...&lt;br /&gt;
        m_2*(L_1^2+el_2^2+2.0*L_1*el_2*cos(x2));&lt;br /&gt;
    H_12  = Eye_2 + m_2*el_2^2 + m_2*L_1*el_2*cos(x2);&lt;br /&gt;
    H_22  = Eye_2 + m_2*el_2^2;&lt;br /&gt;
    h     = m_2*L_1*el_2*sin(x2);&lt;br /&gt;
    delta = 1.0./(H_11.*H_22-H_12.^2);&lt;br /&gt;
&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x1) == x3&lt;br /&gt;
        dot(x2) == x4&lt;br /&gt;
        dot(x3) == delta.*(2.0*h.*H_22.*x3.*x4 ...&lt;br /&gt;
        +h.*H_22.*x4.^2+h.*H_12.*x3.^2+H_22.*u1-H_12.*u2)&lt;br /&gt;
        dot(x4) == delta.*(-2.0*h.*H_12.*x3.*x4 ...&lt;br /&gt;
        -h.*H_11.*x3.^2-h.*H_12.*x4.^2+H_11.*u2-H_12.*u1)});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Robot Manipulators&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x, y, and speed, to use as starting guess&lt;br /&gt;
    % in the next iteration&lt;br /&gt;
    tfopt = subs(final(t), solution);&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    x3opt = subs(x3, solution);&lt;br /&gt;
    x4opt = subs(x4, solution);&lt;br /&gt;
    u1opt = subs(u1, solution);&lt;br /&gt;
    u2opt = subs(u2, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.59011 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Robot Manipulators             f_k       0.391698237386178090&lt;br /&gt;
                                       sum(|constr|)      0.000063099633743277&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.391761337019921390&lt;br /&gt;
                                              f(x_0)      7.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   68 ConJacEv   68 Iter   26 MinorIter  437&lt;br /&gt;
CPU time: 0.124801 sec. Elapsed time: 0.134000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.58064 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Robot Manipulators             f_k       0.391820155673057110&lt;br /&gt;
                                       sum(|constr|)      0.000000000018899679&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.391820155691956770&lt;br /&gt;
                                              f(x_0)      0.391698237386178090&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   16 ConJacEv   16 Iter   12 MinorIter  440&lt;br /&gt;
CPU time: 0.187201 sec. Elapsed time: 0.191000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1opt),solution);&lt;br /&gt;
x2 = subs(collocate(x2opt),solution);&lt;br /&gt;
x3 = subs(collocate(x3opt),solution);&lt;br /&gt;
x4 = subs(collocate(x4opt),solution);&lt;br /&gt;
u1 = subs(collocate(u1opt),solution);&lt;br /&gt;
u2 = subs(collocate(u2opt),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Robot Manipulators state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Robot Manipulators control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:robotManipulators_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Robot_Arm_Movement&amp;diff=2251</id>
		<title>PROPT Robot Arm Movement</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Robot_Arm_Movement&amp;diff=2251"/>
		<updated>2011-11-09T12:11:49Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Benchmarking Optimization Software with COPS Elizabeth D. Dolan and Jorge J. More ARGONNE NATIONAL LABORATORY&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u(t) over t in [0; 1 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_f &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; L*\frac{d^{2}rho}{dt^{2}} = u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I_1*\frac{d^{2}theta}{dt^{2}} = u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I_2*\frac{d^{2}phi}{dt^{2}} = u_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= rho &amp;lt;= L &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |theta| &amp;lt;= pi &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= phi &amp;lt;= pi &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u_{1:3}| &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I_1 = \frac{((L-rho)^3+rho^3)}{3}*sin(phi)^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I_2 = \frac{((L-rho)^3+rho^3)}{3} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The boundary conditions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [rho_0 \ theta_0 \ phi_0] = [4.5 \ 0 \ \frac{pi}{4}] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [rho_1 \ theta_1 \ phi_1] = [4.5 \ \frac{2*pi}{3} \ \frac{pi}{4}] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; L = 5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All first order derivatives are 0 at boundaries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms t_f&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
tfopt = 1;&lt;br /&gt;
x1opt = 4.5;&lt;br /&gt;
x2opt = 0;&lt;br /&gt;
x3opt = 2*pi/3*t.^2;&lt;br /&gt;
x4opt = 0;&lt;br /&gt;
x5opt = pi/4;&lt;br /&gt;
x6opt = 0;&lt;br /&gt;
u1opt = 0;&lt;br /&gt;
u2opt = 0;&lt;br /&gt;
u3opt = 0;&lt;br /&gt;
&lt;br /&gt;
for n=[20 100]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    %rho d(rho)dt theta d(theta)dt phi d(phi)dt&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, t_f, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
    tomStates x1 x2 x3 x4 x5 x6&lt;br /&gt;
    tomControls u1 u2 u3&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    x0 = {t_f == tfopt&lt;br /&gt;
        icollocate({x1 == x1opt&lt;br /&gt;
        x2 == x2opt; x3 == x3opt&lt;br /&gt;
        x4 == x4opt; x5 == x5opt&lt;br /&gt;
        x6 == x6opt})&lt;br /&gt;
        collocate({u1 == u1opt&lt;br /&gt;
        u2 == u2opt; u3 == u3opt})};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    L = 5;&lt;br /&gt;
    cbox = {&lt;br /&gt;
        0.1 &amp;lt;= t_f &amp;lt;= 10&lt;br /&gt;
        0   &amp;lt;= icollocate(x1) &amp;lt;= L&lt;br /&gt;
        -pi &amp;lt;= icollocate(x3) &amp;lt;= pi&lt;br /&gt;
        0   &amp;lt;= icollocate(x5) &amp;lt;= pi&lt;br /&gt;
        -1  &amp;lt;= collocate(u1)  &amp;lt;= 1&lt;br /&gt;
        -1  &amp;lt;= collocate(u2)  &amp;lt;= 1&lt;br /&gt;
        -1  &amp;lt;= collocate(u3)  &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = {initial({x1 == 4.5; x2 == 0&lt;br /&gt;
        x3 == 0; x4 == 0&lt;br /&gt;
        x5 == pi/4; x6 == 0})&lt;br /&gt;
        final({x1 == 4.5; x2 == 0&lt;br /&gt;
        x3 == 2*pi/3&lt;br /&gt;
        x4 == 0&lt;br /&gt;
        x5 == pi/4&lt;br /&gt;
        x6 == 0&lt;br /&gt;
        })};&lt;br /&gt;
&lt;br /&gt;
    I1 = ((L-x1).^3+x1.^3)./3.*sin(x5).^2;&lt;br /&gt;
    I2 = ((L-x1).^3+x1.^3)/3;&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    ceq = collocate({dot(x1) == x2&lt;br /&gt;
        dot(x2) == u1/L;   dot(x3) == x4&lt;br /&gt;
        dot(x4) == u2./I1; dot(x5) == x6&lt;br /&gt;
        dot(x6) == u3./I2});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Robot Arm&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x, y, and speed, to use as starting guess in the next iteration&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    x3opt = subs(x3, solution);&lt;br /&gt;
    x4opt = subs(x4, solution);&lt;br /&gt;
    x5opt = subs(x5, solution);&lt;br /&gt;
    u1opt = subs(u1, solution);&lt;br /&gt;
    u2opt = subs(u2, solution);&lt;br /&gt;
    u3opt = subs(u3, solution);&lt;br /&gt;
    tfopt = subs(final(t), solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.3121 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Robot Arm                      f_k       9.146367546080650600&lt;br /&gt;
                                       sum(|constr|)      0.000000278037569148&lt;br /&gt;
                              f(x_k) + sum(|constr|)      9.146367824118220500&lt;br /&gt;
                                              f(x_0)      1.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   17 ConJacEv   17 Iter   11 MinorIter  225&lt;br /&gt;
CPU time: 0.031200 sec. Elapsed time: 0.037000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.3096 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Robot Arm                      f_k       9.140854009735493300&lt;br /&gt;
                                       sum(|constr|)      0.000002639179211847&lt;br /&gt;
                              f(x_k) + sum(|constr|)      9.140856648914704500&lt;br /&gt;
                                              f(x_0)      9.146367546080650600&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv    7 ConJacEv    7 Iter    4 MinorIter  729&lt;br /&gt;
CPU time: 1.606810 sec. Elapsed time: 0.634000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x5 = subs(collocate(x5),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
u3 = subs(collocate(u3),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x5,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;rho&#039;,&#039;theta&#039;,&#039;phi&#039;);&lt;br /&gt;
title(&#039;Robot Arm state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;*-&#039;,t,u2,&#039;*-&#039;,t,u3,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;,&#039;u3&#039;);&lt;br /&gt;
title(&#039;Robot Arm control variables&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:robotArmMovement_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Rigid_Body_Rotation&amp;diff=2250</id>
		<title>PROPT Rigid Body Rotation</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Rigid_Body_Rotation&amp;diff=2250"/>
		<updated>2011-11-09T12:11:48Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
On smooth optimal control determination, Ilya Ioslovich and Per-Olof Gutman, Technion, Israel Institute of Technology.&lt;br /&gt;
&lt;br /&gt;
Example 1: Rigid body rotation&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 1 ] to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \frac{1}{4}*\int_0^{1} (u_1^2+u_2^2)^2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = a*y+u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dy}{dt} = -a*x+u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{du_1}{dt} = a*u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{du_2}{dt} = -a*u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0.9 \ 0.75] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_f) = [0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a = 2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 1, 20);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x y u1 u2&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x == 0.9; y == 0.75})&lt;br /&gt;
    final({x == 0; y == 0})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
a = 2;&lt;br /&gt;
ceq = collocate({dot(x)  == a*y+u1; dot(y)  == -a*x+u2&lt;br /&gt;
    dot(u1) == a*u2; dot(u2) == -a*u1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = 0.25*integrate((u1.^2+u2.^2).^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Rigid Body Rotation&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, [], options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x = subs(collocate(x),solution);&lt;br /&gt;
y = subs(collocate(y),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: con&lt;br /&gt;
Time for symbolic processing: 0.11175 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Rigid Body Rotation            f_k       0.470939062500258190&lt;br /&gt;
                                       sum(|constr|)      0.000000000003070916&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.470939062503329120&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    3 GradEv    1 MinorIter   39&lt;br /&gt;
Elapsed time: 0.010000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1);&lt;br /&gt;
subplot(2,1,1);&lt;br /&gt;
plot(t,x,&#039;*-&#039;,t,y,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x&#039;,&#039;y&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2);&lt;br /&gt;
plot(t,u1,&#039;*-&#039;,t,u2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:rigidBodyRotation_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Rayleigh_Unconstrained&amp;diff=2249</id>
		<title>PROPT Rayleigh Unconstrained</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Rayleigh_Unconstrained&amp;diff=2249"/>
		<updated>2011-11-09T12:11:44Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Lecture Notes for ECE/MAE 7360, Robust and Optimal Control (part 2) Fall 2003, Jinsong Liang, Nov. 20, 2003 Utah State University at Logan&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t_F ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{2.5} x_1^2 + u^2 \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -x_1+(1.4-0.14*x_2^2)*x_2+4*u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1(0) = -5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(0) = -5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2.5, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == -5; x2 == -5})&lt;br /&gt;
    collocate(u == 0)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-100 &amp;lt;= icollocate(x1) &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= icollocate(x2) &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= collocate(u) &amp;lt;= 100};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == -5; x2 == -5});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({dot(x1) == x2&lt;br /&gt;
    dot(x2) == -x1+(1.4-0.14*x2.^2).*x2+4*u});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = integrate(x1.^2+u.^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Rayleigh Unconstrained&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.10859 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Rayleigh Unconstrained         f_k      29.376079656023276000&lt;br /&gt;
                                       sum(|constr|)      0.000000003739617241&lt;br /&gt;
                              f(x_k) + sum(|constr|)     29.376079659762894000&lt;br /&gt;
                                              f(x_0)     62.499999999999517000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   47 ConJacEv   47 Iter   36 MinorIter  144&lt;br /&gt;
CPU time: 0.093601 sec. Elapsed time: 0.091000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;Rayleigh Unconstrained state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Rayleigh Unconstrained System control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:rayleighUnconstrained_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Quadruple_Integral&amp;diff=2248</id>
		<title>PROPT Quadruple Integral</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Quadruple_Integral&amp;diff=2248"/>
		<updated>2011-11-09T12:11:31Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS&lt;br /&gt;
&lt;br /&gt;
12.4.5 Example 5&lt;br /&gt;
&lt;br /&gt;
CHAPMAN &amp;amp; HALL/CRC Monographs and Surveys in Pure and Applied Mathematics&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; t_F ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_F &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The initial condition are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0)  = [0.1 \ 0.2 \ 0.3 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_F) = [0 \ 0 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1 &amp;lt;= u &amp;lt;= 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms t_f&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, t_f, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {t_f == 5&lt;br /&gt;
    icollocate({x1 == 0.1-0.1*t/t_f&lt;br /&gt;
    x2 == 0.2-0.2*t/t_f; x3 == 0.3-0.3*t/t_f})&lt;br /&gt;
    collocate(u == -1)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0.1 &amp;lt;= t_f &amp;lt;= 100&lt;br /&gt;
    -1 &amp;lt;= collocate(u) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == 0.1; x2 == 0.2; x3 == 0.3; x4 == 0})&lt;br /&gt;
    final({x1 == 0; x2 == 0; x3 == 0; x4 == 0})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == x2; dot(x2) == x3&lt;br /&gt;
    dot(x3) == x4; dot(x4) == u});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Quadruple Integral&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
x4 = subs(collocate(x4),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.12111 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Quadruple Integral             f_k       4.849598187644263100&lt;br /&gt;
                                       sum(|constr|)      0.000000078353877264&lt;br /&gt;
                              f(x_k) + sum(|constr|)      4.849598265998140300&lt;br /&gt;
                                              f(x_0)      5.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   58 ConJacEv   58 Iter   31 MinorIter  474&lt;br /&gt;
CPU time: 0.109201 sec. Elapsed time: 0.090000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Quadruple Integral state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Quadruple Integral control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:quadrupleIntegral_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Quadratic_constraint_problem&amp;diff=2247</id>
		<title>PROPT Quadratic constraint problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Quadratic_constraint_problem&amp;diff=2247"/>
		<updated>2011-11-09T12:11:30Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Paper: LINEAR-QUADRATIC OPTIMAL CONTROL WITH INTEGRAL QUADRATIC CONSTRAINTS. OPTIMAL CONTROL APPLICATIONS AND METHODS Optim. Control Appl. Meth., 20, 79-92 (1999)&lt;br /&gt;
&lt;br /&gt;
E. B. LIM(1), Y. Q. LIU(2), K. L. TEO(2) AND J. B. MOORE(1)&lt;br /&gt;
&lt;br /&gt;
(1) Department of Systems Engineering, Research School of Information Sciences and Engineering, Australian National University, Canberra ACT 0200, Australia&lt;br /&gt;
&lt;br /&gt;
(2) School of Mathematics and Statistics, Curtin University of Technology, Perth, WA 6845, Australia&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u(t) over t in [0; 1 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = 0.5*x_1(1)^2 + 0.5*\int_0^1 (x_1^2 + u_1^2 + u_2^2) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = 3*x_1+x_2 + u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -x_1+2*x_2 + u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1(0) = 4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(0) = -4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0.5*x_2(1)^2 + 0.5*\int_0^1 (x_1^2 + u_1^2 + u_2^2) &amp;lt;= 80 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Introduce a new variable to remove integral in constraint:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 0.5 * (x_1.^2 + u_1.^2 + u_2.^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
resulting in event constraint:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0.5*x_2(1)^2 + x_3(1) &amp;lt;= 8 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 1, 50);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({&lt;br /&gt;
    x1 == 4-5*t&lt;br /&gt;
    x2 == -4-1*t&lt;br /&gt;
    x3 == 50*t&lt;br /&gt;
    })&lt;br /&gt;
    collocate({&lt;br /&gt;
    u1 == -10+10*t&lt;br /&gt;
    u2 == 14-12*t})};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {&lt;br /&gt;
    initial({&lt;br /&gt;
    x1 == 4&lt;br /&gt;
    x2 == -4&lt;br /&gt;
    x3 == 0&lt;br /&gt;
    })&lt;br /&gt;
    final(x2)^2/2+final(x3) &amp;lt;= 80};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == 3*x1+x2 + u1&lt;br /&gt;
    dot(x2) == -x1+2*x2 + u2&lt;br /&gt;
    dot(x3) == 1/2 * (x2.^2 + u1.^2 + u2.^2)&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(x1)^2/2 + final(x3);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Quadratic Constraint&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
x3 = subs(collocate(x3),solution);&lt;br /&gt;
u1 = subs(collocate(u1),solution);&lt;br /&gt;
u2 = subs(collocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.12268 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Quadratic Constraint           f_k      67.888740121887480000&lt;br /&gt;
                                       sum(|constr|)      0.000000192408232753&lt;br /&gt;
                              f(x_k) + sum(|constr|)     67.888740314295717000&lt;br /&gt;
                                              f(x_0)     50.499999999999915000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   32 ConJacEv   32 Iter   31 MinorIter  279&lt;br /&gt;
CPU time: 0.218401 sec. Elapsed time: 0.217000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3/10,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3/10&#039;);&lt;br /&gt;
title(&#039;Quadratic Constraint state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Quadratic Constraint control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:quadraticConstraint_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Plug-Flow_Tubular_Reactor&amp;diff=2246</id>
		<title>PROPT Plug-Flow Tubular Reactor</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Plug-Flow_Tubular_Reactor&amp;diff=2246"/>
		<updated>2011-11-09T12:11:26Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
A HYBRID METHOD FOR THE OPTIMAL CONTROL OF CHEMICAL PROCESSES 1998, E F Carrasco, J R Banga&lt;br /&gt;
&lt;br /&gt;
Case Study II: Plug-Flow Tubular Reactor&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
This case study considers a plug-flow reactor as studied by Reddy and Husain, Luus and Mekarapiruk and Luus. The objective is to maximize the normalized concentration of the desired product.&lt;br /&gt;
&lt;br /&gt;
Find u(t) to maximize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_1(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = (1-x_1)*k_1-x_1*k_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = 300*((1-x_1)*k_1-x_1*k_2)-u*(x_2-290) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where x1 denotes the normalized concentration of de desired product, and x2 is the temperature. The initial conditions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0 \ 380]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rate constants are given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; k_1 = 1.7536e5*exp(-\frac{1.1374e4}{1.9872*x_2}) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; k_2 = 2.4885e10*exp(-\frac{2.2748e4}{1.9872*x_2}) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where the final time t_f = 5 min. The constraint on the control variable (the normalized coolant flow rate) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u &amp;lt;= 0.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In addition, there is an upper path constraint on the temperature:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2(t) &amp;lt;= 460 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 5, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 0.6*t/5&lt;br /&gt;
    x2 == 380})&lt;br /&gt;
    collocate(u == 0.25)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0 &amp;lt;= icollocate(x1) &amp;lt;= 10&lt;br /&gt;
    100 &amp;lt;= icollocate(x2) &amp;lt;= 460&lt;br /&gt;
    0   &amp;lt;= collocate(u)   &amp;lt;= 0.5};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 0; x2 == 380});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
k1 = 1.7536e5*exp(-1.1374e4/1.9872./x2);&lt;br /&gt;
k2 = 2.4885e10*exp(-2.2748e4/1.9872./x2);&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == (1-x1).*k1-x1.*k2&lt;br /&gt;
    dot(x2) == 300*((1-x1).*k1-x1.*k2)-u.*(x2-290)});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = -final(x1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Plug Flow Reactor&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.18266 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Plug Flow Reactor              f_k      -0.677125737913608190&lt;br /&gt;
                                       sum(|constr|)      0.000031723901907782&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.677094014011700440&lt;br /&gt;
                                              f(x_0)     -0.599999999999999200&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  346 ConJacEv  346 Iter  112 MinorIter  325&lt;br /&gt;
CPU time: 0.234001 sec. Elapsed time: 0.227000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2/100,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2/100&#039;);&lt;br /&gt;
title(&#039;Plug Flow Reactor state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Plug Flow Reactor control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:plugFlowReactor_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Penicillin_Plant&amp;diff=2245</id>
		<title>PROPT Penicillin Plant</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Penicillin_Plant&amp;diff=2245"/>
		<updated>2011-11-09T12:11:21Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Fed-batch Fermentor Control: Dynamic Optimization of Batch Processes II. Role of Measurements in Handling Uncertainty 2001, B. Srinivasan, D. Bonvin, E. Visser, S. Palanki&lt;br /&gt;
&lt;br /&gt;
Illustrative example: Nominal Optimization of a Fed-Batch Fermentor for Penicillin Production.&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
This particular example was featured in the work of B. Srinivasan et al. 2001. The optimal trajectories for the problem was provided in the work.&lt;br /&gt;
&lt;br /&gt;
In this problem, the objective is to maximize the concentration of penicillin, P, produced in a fed-batch bioreactor, given a finite amount of time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reactions: S -&amp;gt; X, S -&amp;gt; P&lt;br /&gt;
Conditions: Fed-batch, isothermal.&lt;br /&gt;
Objective: Maximize the concentration of product P at a given final time.&lt;br /&gt;
Manipulated variable: Feed rate of S.&lt;br /&gt;
Constraints: Input bounds; upper limit on the biomass concentration,&lt;br /&gt;
which is motivated by oxygen-transfer limitation typically occurring at&lt;br /&gt;
large biomass concentration.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = -P(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{X}{dt} = my*X - \frac{u}{V}*X &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{S}{dt} = -\frac{my*X}{Yx} - \frac{v*X}{Yp} + \frac{u}{V}*(Sin-S) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{P}{dt} = v*X - \frac{u}{V}*P &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{V}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; my = \frac{um*S}{Km+S+S^{2}/Ki} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Programmer: Wee Kiat Lim (Nanyang Technological University)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2009-2009 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
Penalty for variations in u&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
penalty_constant = 0.001;&lt;br /&gt;
&lt;br /&gt;
% Various constants&lt;br /&gt;
miu_m = 0.02;  Km   = 0.05;  Ki = 5;&lt;br /&gt;
Yx    = 0.5;   Yp   = 1.2;   v = 0.004;&lt;br /&gt;
Sin   = 200;   umin = 0;     umax = 1;&lt;br /&gt;
Xmin  = 0;     Xmax = 3.7;   Smin = 0;&lt;br /&gt;
&lt;br /&gt;
% no. of collocation points to use&lt;br /&gt;
narr = [20 80];&lt;br /&gt;
for n=narr&lt;br /&gt;
    toms t1&lt;br /&gt;
    toms tcut&lt;br /&gt;
    p1 = tomPhase(&#039;p1&#039;, t1, 0, tcut, n);&lt;br /&gt;
&lt;br /&gt;
    setPhase(p1);&lt;br /&gt;
    tomStates X1 S1 P1 V1 %Vs %Scaling is disabled here&lt;br /&gt;
    tomControls u1&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    if n == narr(1)&lt;br /&gt;
        x01 = {tcut == 75&lt;br /&gt;
            icollocate({X1 == 1+2.7*t1/tcut; S1 == 0.5;&lt;br /&gt;
            P1 == 0.6*t1/tcut; V1 == 150})&lt;br /&gt;
            collocate(u1 == 0.03+0.06*t1/tcut)};&lt;br /&gt;
    else&lt;br /&gt;
        x01 = {tcut == tcutg&lt;br /&gt;
            icollocate({X1 == Xg1; S1 == Sg1; P1 == Pg1; V1 == Vg1})&lt;br /&gt;
            collocate(u1 == ug1)};&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox1 = {75 &amp;lt;= tcut &amp;lt;= 85&lt;br /&gt;
        0 &amp;lt;= icollocate(X1) &amp;lt;= Xmax&lt;br /&gt;
        Smin &amp;lt;= icollocate(S1) &amp;lt;= 100&lt;br /&gt;
        0 &amp;lt;= icollocate(P1) &amp;lt;= 5&lt;br /&gt;
        1 &amp;lt;= icollocate(V1) &amp;lt;= 300&lt;br /&gt;
        umin &amp;lt;= collocate(u1) &amp;lt;= umax};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd1 = initial({X1 == 1; S1 == 0.5;&lt;br /&gt;
        P1 == 0; V1 == 150});&lt;br /&gt;
&lt;br /&gt;
    miu1 = (miu_m*S1)/(Km + S1 + S1^2/Ki);&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    temp11 = miu1*X1;&lt;br /&gt;
    temp21 = u1/V1;&lt;br /&gt;
    temp31 = v*X1;&lt;br /&gt;
    ceq1 = collocate ({&lt;br /&gt;
        dot(X1) == temp11 - u1/V1*X1&lt;br /&gt;
        dot(S1) == -temp11/Yx - temp31/Yp + temp21*(Sin - S1)&lt;br /&gt;
        dot(P1) == temp31 - temp21*P1&lt;br /&gt;
        dot(V1) == u1});&lt;br /&gt;
&lt;br /&gt;
    if n == narr(1)&lt;br /&gt;
        % No objective in first phase&lt;br /&gt;
        objective = 0;&lt;br /&gt;
    else&lt;br /&gt;
        % Variation penalty&lt;br /&gt;
        objective = penalty_constant*integrate(dot(u1)^2);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    toms t2&lt;br /&gt;
    p2 = tomPhase(&#039;p2&#039;, t2, tcut, 150-tcut, n);&lt;br /&gt;
&lt;br /&gt;
    setPhase(p2);&lt;br /&gt;
    tomStates X2 S2 P2 V2 %Vs %Scaling is disabled here&lt;br /&gt;
    tomControls u2&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    if n == narr(1)&lt;br /&gt;
        x02 = {&lt;br /&gt;
            icollocate({X2 == Xmax; S2 == 0; P2 == 0.6+t2/150; V2 == 150});&lt;br /&gt;
            collocate(u2 == 0.01);&lt;br /&gt;
            };&lt;br /&gt;
    else&lt;br /&gt;
        x02 = {&lt;br /&gt;
            icollocate({X2 == Xg2; S2 == Sg2; P2 == Pg2; V2 == Vg2})&lt;br /&gt;
            collocate(u2 == ug2)&lt;br /&gt;
            };&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    umax2 = 0.03;&lt;br /&gt;
    cbox2 = {0 &amp;lt;= icollocate(X2) &amp;lt;= Xmax&lt;br /&gt;
        Smin &amp;lt;= icollocate(S2) &amp;lt;= 100&lt;br /&gt;
        0 &amp;lt;= icollocate(P2) &amp;lt;= 5&lt;br /&gt;
        1 &amp;lt;= icollocate(V2) &amp;lt;= 300&lt;br /&gt;
        umin &amp;lt;= collocate(u2) &amp;lt;= umax2&lt;br /&gt;
        initial(S2) &amp;lt;= 0.2};&lt;br /&gt;
&lt;br /&gt;
    miu2 = (miu_m*S2)/(Km + S2 + S2^2/Ki);&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    temp12 = miu2*X2;&lt;br /&gt;
    temp22 = u2/V2;&lt;br /&gt;
    temp32 = v*X2;&lt;br /&gt;
    ceq2 = collocate ({&lt;br /&gt;
        dot(X2) == temp12 - u2/V2*X2&lt;br /&gt;
        dot(S2) == -temp12/Yx - temp32/Yp + temp22*(Sin - S2)&lt;br /&gt;
        dot(P2) == temp32 - temp22*P2&lt;br /&gt;
        dot(V2) == u2});&lt;br /&gt;
&lt;br /&gt;
    % Phase links&lt;br /&gt;
    links = {initial(X2) == final(p1,X1)&lt;br /&gt;
        initial(S2) == final(p1,S1)&lt;br /&gt;
        initial(P2) == final(p1,P1)&lt;br /&gt;
        initial(V2) == final(p1,V1)};&lt;br /&gt;
&lt;br /&gt;
    if n == narr(1)&lt;br /&gt;
        % Objective (Negative sign is added to &#039;maximize&#039; P)&lt;br /&gt;
        objective = -final(P2);&lt;br /&gt;
        ptype = &#039;lpcon&#039;;&lt;br /&gt;
        solver = &#039;snopt&#039;;&lt;br /&gt;
    else&lt;br /&gt;
        objective = objective-final(P2)+penalty_constant*integrate(dot(u2)^2);&lt;br /&gt;
        ptype = &#039;con&#039;;&lt;br /&gt;
        solver = &#039;snopt&#039;;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Solve the problem&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Penicillin Plant&#039;;&lt;br /&gt;
    Prob = sym2prob(ptype, objective, {cbox1, cbnd1, ceq1, cbox2, ceq2, links}, {x01, x02}, options);&lt;br /&gt;
    Result = tomRun(solver, Prob, 1);&lt;br /&gt;
    solution = getSolution(Result);&lt;br /&gt;
&lt;br /&gt;
    ug1 = subs(u1,solution);&lt;br /&gt;
    Xg1 = subs(X1,solution);&lt;br /&gt;
    Sg1 = subs(S1,solution);&lt;br /&gt;
    Pg1 = subs(P1,solution);&lt;br /&gt;
    Vg1 = subs(V1,solution);&lt;br /&gt;
    ug2 = subs(u2,solution);&lt;br /&gt;
    Xg2 = subs(X2,solution);&lt;br /&gt;
    Sg2 = subs(S2,solution);&lt;br /&gt;
    Pg2 = subs(P2,solution);&lt;br /&gt;
    Vg2 = subs(V2,solution);&lt;br /&gt;
    tcutg = solution.tcut;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Penicillin Plant               f_k      -1.682729742163946000&lt;br /&gt;
                                       sum(|constr|)      0.000005098522916677&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -1.682724643641029200&lt;br /&gt;
                                              f(x_0)     -1.599999999999999600&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  652 ConJacEv  652 Iter  210 MinorIter 2952&lt;br /&gt;
CPU time: 1.326009 sec. Elapsed time: 1.312000 sec. &lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Penicillin Plant               f_k      -1.682693890525556800&lt;br /&gt;
                                       sum(|constr|)      0.000001881327092638&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -1.682692009198464300&lt;br /&gt;
                                              f(x_0)     -1.682727201466558900&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv   18 GradEv   16 ConstrEv   16 ConJacEv   16 Iter   15 MinorIter  976&lt;br /&gt;
CPU time: 1.419609 sec. Elapsed time: 1.419000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
Optimal states and control trajectories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
uopt = subs([collocate(p1,u1);collocate(p2,u2)],solution);&lt;br /&gt;
Xopt = subs([collocate(p1,X1);collocate(p2,X2)],solution);&lt;br /&gt;
Sopt = subs([collocate(p1,S1);collocate(p2,S2)],solution);&lt;br /&gt;
Popt = subs([collocate(p1,P1);collocate(p2,P2)],solution);&lt;br /&gt;
Vopt = subs([collocate(p1,V1);collocate(p2,V2)],solution);&lt;br /&gt;
&lt;br /&gt;
t = subs([collocate(p1,t1);collocate(p2,t2)],solution);&lt;br /&gt;
np = length(t);&lt;br /&gt;
&lt;br /&gt;
Pfinal=subs(final(p2,P2),solution);&lt;br /&gt;
&lt;br /&gt;
% Plots of the trajectories&lt;br /&gt;
figure(1)&lt;br /&gt;
subplot(3,1,1);&lt;br /&gt;
plot(t,Popt,&#039;*-&#039;);&lt;br /&gt;
title([&#039;Final Penicillin concentration is &#039;,num2str(Pfinal),&#039; g/L.&#039;])&lt;br /&gt;
ylabel(&#039;Penicillin Conc&#039;)&lt;br /&gt;
xlabel(&#039;Time (hrs)&#039;)&lt;br /&gt;
subplot(3,1,2);&lt;br /&gt;
plot(t,Xopt,&#039;*-&#039;);&lt;br /&gt;
ylabel(&#039;Cell Mass Conc&#039;)&lt;br /&gt;
xlabel(&#039;Time (hrs)&#039;)&lt;br /&gt;
subplot(3,1,3);&lt;br /&gt;
plot(t,Sopt,&#039;*-&#039;);&lt;br /&gt;
ylabel(&#039;Substrate Conc&#039;)&lt;br /&gt;
xlabel(&#039;Time (hrs)&#039;)&lt;br /&gt;
&lt;br /&gt;
figure(2)&lt;br /&gt;
subplot(2,1,1);&lt;br /&gt;
plot(t,Vopt,&#039;*-&#039;);&lt;br /&gt;
title([&#039;Final Penicillin concentration is &#039;,num2str(Pfinal),&#039; g/L.&#039;])&lt;br /&gt;
ylabel(&#039;Volume of medium&#039;)&lt;br /&gt;
xlabel(&#039;Time (hrs)&#039;)&lt;br /&gt;
subplot(2,1,2);&lt;br /&gt;
plot(t,uopt,&#039;*-&#039;);&lt;br /&gt;
ylabel(&#039;Feed flowrate&#039;)&lt;br /&gt;
xlabel(&#039;Time (hrs)&#039;)&lt;br /&gt;
&lt;br /&gt;
fprintf(&#039;\n&#039;)&lt;br /&gt;
fprintf(&#039;Optimization completed... \n&#039;)&lt;br /&gt;
fprintf(&#039;Final Penicillin concentration is %5.4f g/L.\n&#039;,Pfinal)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optimization completed... &lt;br /&gt;
Final Penicillin concentration is 1.6827 g/L.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:penicillinPlant_01.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:penicillinPlant_02.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Pendulum_Gravity_Estimation&amp;diff=2244</id>
		<title>PROPT Pendulum Gravity Estimation</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Pendulum_Gravity_Estimation&amp;diff=2244"/>
		<updated>2011-11-09T12:11:18Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
User&#039;s Guide for DIRCOL&lt;br /&gt;
&lt;br /&gt;
Problem 2.5 Pendulum&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \frac{1}{2}*((x_{t_f}-x_{f_{meas}})^2 + (y_{t_f}-y_{f_{meas}})^2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dy}{dt} = v &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{du}{dt} = lambda*x/m &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dv}{dt} = lambda*y/m-g &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x^2 + y^2 - L^2 = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [x_0 \ y_0 \ u_0 \ v_0] = [0.4 \ -0.3 \ 0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [x_{f_{meas}} \ y_{f_{meas}}] = [-0.231625 \ -0.443109] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; L = 0.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; m = 0.3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t g&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
gopt = 20;&lt;br /&gt;
xopt = 0.4-(0.4+0.231625)*t/2;&lt;br /&gt;
yopt = -0.3-(-0.3+0.443109)*t/2;&lt;br /&gt;
uopt = 0;&lt;br /&gt;
vopt = 0;&lt;br /&gt;
lambdaopt = -5;&lt;br /&gt;
&lt;br /&gt;
for n=[20 51]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 2, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
    tomStates x y u v&lt;br /&gt;
    tomControls lambda&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    x0 = {g == gopt&lt;br /&gt;
        icollocate({&lt;br /&gt;
        x == xopt&lt;br /&gt;
        y == yopt&lt;br /&gt;
        u == uopt&lt;br /&gt;
        v == vopt})&lt;br /&gt;
        collocate(lambda == lambdaopt)};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {1 &amp;lt;= g &amp;lt;= 100};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x == 0.4; y == -0.3&lt;br /&gt;
        u == 0; v == 0});&lt;br /&gt;
&lt;br /&gt;
    L   = 0.5;&lt;br /&gt;
    m   = 0.3;&lt;br /&gt;
    xmeas = -0.231625;&lt;br /&gt;
    ymeas = -0.443109;&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x) == u&lt;br /&gt;
        dot(y) == v&lt;br /&gt;
        dot(u) == lambda.*x/m&lt;br /&gt;
        dot(v) == lambda.*y/m-g&lt;br /&gt;
        x.^2 + y.^2 - L^2 == 0});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = 1/2*((final(x)-xmeas)^2+(final(y)-ymeas)^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Pendulum Gravity&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
    gopt = subs(g, solution);&lt;br /&gt;
    xopt = subs(x, solution);&lt;br /&gt;
    yopt = subs(y, solution);&lt;br /&gt;
    uopt = subs(u, solution);&lt;br /&gt;
    vopt = subs(v, solution);&lt;br /&gt;
    lambdaopt = subs(lambda, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.14939 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Pendulum Gravity               f_k       0.000000017178935982&lt;br /&gt;
                                       sum(|constr|)      0.000001384358823592&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000001401537759574&lt;br /&gt;
                                              f(x_0)     -0.124997863253000020&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   98 ConJacEv   98 Iter   43 MinorIter   96&lt;br /&gt;
CPU time: 0.078000 sec. Elapsed time: 0.088000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.15159 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Pendulum Gravity               f_k       0.000000000017699578&lt;br /&gt;
                                       sum(|constr|)      0.000000032138058518&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000000032155758096&lt;br /&gt;
                                              f(x_0)     -0.124997846074064280&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   13 ConJacEv   13 Iter   12 MinorIter  190&lt;br /&gt;
CPU time: 0.202801 sec. Elapsed time: 0.200000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Show result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
disp(sprintf(&#039;Gravity estimated to %g&#039;,gopt));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Gravity estimated to 9.82655&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Path_Tracking_Robot_(Two-Phase)&amp;diff=2243</id>
		<title>PROPT Path Tracking Robot (Two-Phase)</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Path_Tracking_Robot_(Two-Phase)&amp;diff=2243"/>
		<updated>2011-11-09T12:11:15Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
User&#039;s Guide for DIRCOL&lt;br /&gt;
&lt;br /&gt;
2.7 Optimal path tracking for a simple robot. A robot with two rotational joints and simplified equations of motion has to move along a prescribed path with constant velocity.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{2} (\sum_{i=1}^{2} (w_i*(q_i(t) - q_{i,ref})^2) + \sum_{i=1}^{2} (w_{2+i}*(\frac{dq}{dt}_i(t) - \frac{dq}{dt}_{i,ref})^2) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d^2q_1}{dt^2} = u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d^2q_2}{dt^2} = u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A transformation gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_{1:4}(0) = [0 \ 0 \ 0.5 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_{1:4}(2) = [0.5 \ 0.5 \ 0 \ 0.5] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; w_{1:4} = [100 \ 100 \ 500 \ 500] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1{1,ref} = \frac{t}{2} \ (0&amp;lt;t&amp;lt;1), \ \frac{1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2{1,ref} = 0 \ (0&amp;lt;t&amp;lt;1), \ \frac{t-1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_3{1,ref} = \frac{1}{2} \ (0&amp;lt;t&amp;lt;1), \ 0 \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_4{1,ref} = 0 \ (0&amp;lt;t&amp;lt;1), \ \frac{1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt; 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
t_F = 2;&lt;br /&gt;
toms t1&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t1, 0, t_F/2, 25);&lt;br /&gt;
toms t2&lt;br /&gt;
p2 = tomPhase(&#039;p2&#039;, t2, t_F/2, t_F/2, 25);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates x1p1 x2p1 x3p1 x4p1&lt;br /&gt;
tomControls u1p1 u2p1&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox1 = {-10 &amp;lt;= collocate(u1p1) &amp;lt;= 10&lt;br /&gt;
    -10 &amp;lt;= collocate(u2p1) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
w1 = 100; w2 = 100;&lt;br /&gt;
w3 = 500; w4 = 500;&lt;br /&gt;
err1p1 = w1*(x1p1-t1/2).^2;&lt;br /&gt;
err2p1 = w2*(x2p1).^2;&lt;br /&gt;
err3p1 = w3*(x3p1-1/2).^2;&lt;br /&gt;
err4p1 = w4*(x4p1).^2;&lt;br /&gt;
&lt;br /&gt;
cbnd1 = initial({x1p1 == 0; x2p1 == 0&lt;br /&gt;
    x3p1 == 0.5; x4p1 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq1 = collocate({dot(x1p1) == x3p1&lt;br /&gt;
    dot(x2p1) == x4p1; dot(x3p1) == u1p1&lt;br /&gt;
    dot(x4p1) == u2p1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective1 = integrate(err1p1+err2p1+err3p1+err4p1);&lt;br /&gt;
&lt;br /&gt;
% Phase 2&lt;br /&gt;
setPhase(p2);&lt;br /&gt;
tomStates x1p2 x2p2 x3p2 x4p2&lt;br /&gt;
tomControls u1p2 u2p2&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox2 = {-10 &amp;lt;= collocate(u1p2) &amp;lt;= 10&lt;br /&gt;
    -10 &amp;lt;= collocate(u2p2) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
err1p2 = w1*(x1p2-1/2).^2;&lt;br /&gt;
err2p2 = w2*(x2p2-(t2-1)/2).^2;&lt;br /&gt;
err3p2 = w3*(x3p2).^2;&lt;br /&gt;
err4p2 = w4*(x4p2-1/2).^2;&lt;br /&gt;
&lt;br /&gt;
cbnd2 = final({x1p2 == 0.5&lt;br /&gt;
    x2p2 == 0.5&lt;br /&gt;
    x3p2 == 0&lt;br /&gt;
    x4p2 == 0.5});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq2 = collocate({&lt;br /&gt;
    dot(x1p2) == x3p2&lt;br /&gt;
    dot(x2p2) == x4p2&lt;br /&gt;
    dot(x3p2) == u1p2&lt;br /&gt;
    dot(x4p2) == u2p2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective2 = integrate(err1p2+err2p2+err3p2+err4p2);&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = objective1 + objective2;&lt;br /&gt;
&lt;br /&gt;
% Link phase&lt;br /&gt;
link = {final(p1,x1p1) == initial(p2,x1p2)&lt;br /&gt;
    final(p1,x2p1) == initial(p2,x2p2)&lt;br /&gt;
    final(p1,x3p1) == initial(p2,x3p2)&lt;br /&gt;
    final(p1,x4p1) == initial(p2,x4p2)};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Path Tracking Robot (Two-Phase)&#039;;&lt;br /&gt;
options.solver = &#039;sqopt7&#039;;&lt;br /&gt;
constr = {cbox1, cbnd1, ceq1, cbox2, cbnd2, ceq2, link};&lt;br /&gt;
solution = ezsolve(objective, constr, [], options);&lt;br /&gt;
t = subs(collocate(p1,t1),solution);&lt;br /&gt;
t = [t;subs(collocate(p2,t2),solution)];&lt;br /&gt;
x1 = subs(collocate(p1,x1p1),solution);&lt;br /&gt;
x1 = [x1;subs(collocate(p2,x1p2),solution)];&lt;br /&gt;
x2 = subs(collocate(p1,x2p1),solution);&lt;br /&gt;
x2 = [x2;subs(collocate(p2,x2p2),solution)];&lt;br /&gt;
x3 = subs(collocate(p1,x3p1),solution);&lt;br /&gt;
x3 = [x3;subs(collocate(p2,x3p2),solution)];&lt;br /&gt;
x4 = subs(collocate(p1,x4p1),solution);&lt;br /&gt;
x4 = [x4;subs(collocate(p2,x4p2),solution)];&lt;br /&gt;
u1 = subs(collocate(p1,u1p1),solution);&lt;br /&gt;
u1 = [u1;subs(collocate(p2,u1p2),solution)];&lt;br /&gt;
u2 = subs(collocate(p1,u2p1),solution);&lt;br /&gt;
u2 = [u2;subs(collocate(p2,u2p2),solution)];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.25294 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Path Tracking Robot (Two-Phase)    f_k       1.049952991376699200&lt;br /&gt;
                                       sum(|constr|)      0.000000000261665098&lt;br /&gt;
                              f(x_k) + sum(|constr|)      1.049952991638364300&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: SQOPT.  EXIT=0.  INFORM=1.&lt;br /&gt;
SQOPT 7.2-5 QP solver&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
Iter  297 &lt;br /&gt;
CPU time: 0.046800 sec. Elapsed time: 0.123000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1);&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Path Tracking Robot state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2);&lt;br /&gt;
plot(t,u1,&#039;*-&#039;,t,u2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Path Tracking Robot control variables&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:pathTrackingRobot_twophase_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Path_Tracking_Robot&amp;diff=2242</id>
		<title>PROPT Path Tracking Robot</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Path_Tracking_Robot&amp;diff=2242"/>
		<updated>2011-11-09T12:11:10Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
User&#039;s Guide for DIRCOL&lt;br /&gt;
&lt;br /&gt;
2.7 Optimal path tracking for a simple robot. A robot with two rotational joints and simplified equations of motion has to move along a prescribed path with constant velocity.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find u over t in [0; 2 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \int_0^{2} (\sum_{i=1}^{2} (w_i*(q_i(t) - q_{i,ref})^2) + \sum_{i=1}^{2} (w_{2+i}*(\frac{dq}{dt}_i(t) - \frac{dq}{dt}_{i,ref})^2) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d^2q_1}{dt^2} = u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d^2q_2}{dt^2} = u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A transformation gives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = x_4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = u_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_{1:4}(0) = [0 \ 0 \ 0.5 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_{1:4}(2) = [0.5 \ 0.5 \ 0 \ 0.5] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; w_{1:4} = [100 \ 100 \ 500 \ 500] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1{1,ref} = \frac{t}{2} \ (0&amp;lt;t&amp;lt;1), \ \frac{1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_2{1,ref} = 0 \ (0&amp;lt;t&amp;lt;1), \ \frac{t-1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_3{1,ref} = \frac{1}{2} \ (0&amp;lt;t&amp;lt;1), \ 0 \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_4{1,ref} = 0 \ (0&amp;lt;t&amp;lt;1), \ \frac{1}{2} \ (1&amp;lt;t&amp;lt;2) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |u| &amp;lt; 10 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 2, 100, [], &#039;fem1s&#039;); % Use splines with FEM constraints&lt;br /&gt;
%p = tomPhase(&#039;p&#039;, t, 0, 2, 100, [], &#039;fem1&#039;);  % Use linear finite elements&lt;br /&gt;
%p = tomPhase(&#039;p&#039;, t, 0, 2, 100); % Use Gauss point collocation&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2 x3 x4&lt;br /&gt;
tomControls u1 u2&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {&lt;br /&gt;
    -10 &amp;lt;= collocate(u1) &amp;lt;= 10&lt;br /&gt;
    -10 &amp;lt;= collocate(u2) &amp;lt;= 10};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({x1 == 0; x2 == 0&lt;br /&gt;
    x3 == 0.5; x4 == 0})&lt;br /&gt;
    final({x1 == 0.5; x2 == 0.5&lt;br /&gt;
    x3 == 0; x4 == 0.5})};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
w1 = 100; w2 = 100;&lt;br /&gt;
w3 = 500; w4 = 500;&lt;br /&gt;
&lt;br /&gt;
err1 = w1*(x1-t/2.*(t&amp;lt;1)-1/2*(t&amp;gt;=1)).^2;&lt;br /&gt;
err2 = w2*(x2-(t-1)/2.*(t&amp;gt;=1)).^2;&lt;br /&gt;
err3 = w3*(x3-1/2*(t&amp;lt;1)).^2;&lt;br /&gt;
err4 = w4*(x4-1/2*(t&amp;gt;=1)).^2;&lt;br /&gt;
&lt;br /&gt;
toterr = integrate(err1+err2+err3+err4);&lt;br /&gt;
&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == x3&lt;br /&gt;
    dot(x2) == x4&lt;br /&gt;
    dot(x3) == u1&lt;br /&gt;
    dot(x4) == u2});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = toterr;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Path Tracking Robot&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, [], options);&lt;br /&gt;
t  = subs(icollocate(t),solution);&lt;br /&gt;
x1 = subs(icollocate(x1),solution);&lt;br /&gt;
x2 = subs(icollocate(x2),solution);&lt;br /&gt;
x3 = subs(icollocate(x3),solution);&lt;br /&gt;
x4 = subs(icollocate(x4),solution);&lt;br /&gt;
u1 = subs(icollocate(u1),solution);&lt;br /&gt;
u2 = subs(icollocate(u2),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.16121 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Path Tracking Robot                f_k       1.031157512955303400&lt;br /&gt;
                                       sum(|constr|)      0.000000055682846425&lt;br /&gt;
                              f(x_k) + sum(|constr|)      1.031157568638149800&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: CPLEX.  EXIT=0.  INFORM=1.&lt;br /&gt;
CPLEX Barrier QP solver&lt;br /&gt;
Optimal solution found&lt;br /&gt;
&lt;br /&gt;
FuncEv   10 GradEv   10 ConstrEv   10 Iter   10 &lt;br /&gt;
CPU time: 0.249602 sec. Elapsed time: 0.061000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1);&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Path Tracking Robot state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2);&lt;br /&gt;
plot(t,u1,&#039;*-&#039;,t,u2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;);&lt;br /&gt;
title(&#039;Path Tracking Robot control variables&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:pathTrackingRobot_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Park-Ramirez_bioreactor&amp;diff=2241</id>
		<title>PROPT Park-Ramirez bioreactor</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Park-Ramirez_bioreactor&amp;diff=2241"/>
		<updated>2011-11-09T12:11:06Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Dynamic optimization of chemical and biochemical processes using restricted second-order information 2001, Eva Balsa-Canto, Julio R. Banga, Antonio A. Alonso Vassilios S. Vassiliadis&lt;br /&gt;
&lt;br /&gt;
Case Study I: Park-Ramirez bioreactor&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
This case study deals with the optimal production of secreted protein in a fed-batch reactor. It was originally formulated by Park and Ramirez (Park &amp;amp; Ramirez, 1988) and it has also been considered by other researchers (Vassiliadis, 1993; Yang &amp;amp; Wu, 1994; Banga, Irizarry &amp;amp; Seider, 1995; Luus, 1995; Tholudur &amp;amp; Ramirez, 1997). The objective is to maximize the secreted heterologous protein by a yeast strain in a fed-batch culture. The dynamic model accounts for host-cell growth, gene expression, and the secretion of expressed polypeptides. The mathematical statement is as follows:&lt;br /&gt;
&lt;br /&gt;
Find u(t) over t in [t0,t_f] to maximize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_1(t_f)*x_5(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = g_1*(x_2-x_1)-\frac{u}{x_5}*x_1 ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = g_2*x_3-\frac{u}{x_5}*x_2 ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = g_3*x_3-\frac{u}{x_5}*x_3 ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = -7.3*g_3*x_3+\frac{u}{x_5}*(20-x_4) ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = u ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g_1 = 4.75*\frac{g_3}{(0.12+g_3)} ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g_2 = \frac{x_4}{(0.1+x4)}*exp(-5*x_4) ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g_3 = 21.87*\frac{x_4}{(x_4+0.4)*(x_4+62.5)} ,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where x1 and x2 are, respectively, the concentration of the secreted protein and the total protein (l-1), x3 is the culture cell density (g l-1), x4 is the substrate concentration (g l-1), x5 is the holdup volume (l), u is the nutrient (glucose) feed rate (l h-1), and J is the mass of protein produced (in arbitrary units). The initial conditions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0 \ 0 \ 1 \ 5 \ 1]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For final time t_f = 15 h, and the following constraints on the control variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u &amp;lt;= 2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[20 40 80 120]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 15, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates z1 z2 z3 z4 z5&lt;br /&gt;
    tomControls u&lt;br /&gt;
&lt;br /&gt;
    if n&amp;gt;20&lt;br /&gt;
        % Interpolate an initial guess for the n collocation points&lt;br /&gt;
        x0 = {icollocate({z1 == z1opt; z2 == z2opt&lt;br /&gt;
            z3 == z3opt; z4 == z4opt; z5 == z5opt})&lt;br /&gt;
            collocate(u == uopt)};&lt;br /&gt;
    else&lt;br /&gt;
        x0 = {};&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {icollocate({z1 &amp;lt;= 3&lt;br /&gt;
        z2 &amp;lt;= 3; 0   &amp;lt;= z3 &amp;lt;= 4&lt;br /&gt;
        0 &amp;lt;= z4 &amp;lt;= 10; 0.5 &amp;lt;= z5 &amp;lt;= 25})&lt;br /&gt;
        0 &amp;lt;= collocate(u) &amp;lt;= 2.5};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({z1 == 0; z2 == 0; z3 == 1&lt;br /&gt;
        z4 == 5; z5 == 1});&lt;br /&gt;
&lt;br /&gt;
    % Various constants and expressions&lt;br /&gt;
    g3 = 21.87*z4./(z4+.4)./(z4+62.5);&lt;br /&gt;
    g1 = 4.75*g3./(0.12+g3);&lt;br /&gt;
    g2 = z4./(0.1+z4).*exp(-5*z4);&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(z1) == g1.*(z2-z1)-u./z5.*z1&lt;br /&gt;
        dot(z2) == g2.*z3-u./z5.*z2&lt;br /&gt;
        dot(z3) == g3.*z3-u./z5.*z3&lt;br /&gt;
        dot(z4) == -7.3*g3.*z3+u./z5.*(20-z4)&lt;br /&gt;
        dot(z5) == u});&lt;br /&gt;
&lt;br /&gt;
    % Secreted protein must be less than total protein&lt;br /&gt;
    % proteinlimit = {z1 &amp;lt;= z2};&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    if n == 120&lt;br /&gt;
        objective = -final(z1)*final(z5)+var(diff(collocate(u)));&lt;br /&gt;
    else&lt;br /&gt;
        objective = -final(z1)*final(z5);&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Park Bio Reactor&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal z and u, to use as starting guess in the&lt;br /&gt;
    % next iteration&lt;br /&gt;
    z1opt = subs(z1, solution);&lt;br /&gt;
    z2opt = subs(z2, solution);&lt;br /&gt;
    z3opt = subs(z3, solution);&lt;br /&gt;
    z4opt = subs(z4, solution);&lt;br /&gt;
    z5opt = subs(z5, solution);&lt;br /&gt;
    uopt  = subs(u, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.48856 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Park Bio Reactor               f_k     -31.891604942090204000&lt;br /&gt;
                                       sum(|constr|)      0.000000000222835644&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -31.891604941867367000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  102 ConJacEv  102 Iter   61 MinorIter  911&lt;br /&gt;
CPU time: 0.171601 sec. Elapsed time: 0.172000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.48207 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Park Bio Reactor               f_k     -29.523702508277267000&lt;br /&gt;
                                       sum(|constr|)      0.000000000531678452&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -29.523702507745590000&lt;br /&gt;
                                              f(x_0)    -31.891604942089948000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   75 ConJacEv   75 Iter   58 MinorIter  588&lt;br /&gt;
CPU time: 0.436803 sec. Elapsed time: 0.434000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.4837 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Park Bio Reactor               f_k     -31.866762161406442000&lt;br /&gt;
                                       sum(|constr|)      0.000000000726937524&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -31.866762160679503000&lt;br /&gt;
                                              f(x_0)    -29.523702508277417000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  137 ConJacEv  137 Iter  120 MinorIter  784&lt;br /&gt;
CPU time: 4.586429 sec. Elapsed time: 4.584000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.51719 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Park Bio Reactor               f_k     -32.616144466384739000&lt;br /&gt;
                                       sum(|constr|)      0.000000000312031161&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -32.616144466072711000&lt;br /&gt;
                                              f(x_0)    -31.477810607457531000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  134 ConJacEv  134 Iter  116 MinorIter  930&lt;br /&gt;
CPU time: 46.815900 sec. Elapsed time: 16.326000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
z1 = collocate(z1opt);&lt;br /&gt;
z2 = collocate(z2opt);&lt;br /&gt;
z3 = collocate(z3opt);&lt;br /&gt;
z4 = collocate(z4opt);&lt;br /&gt;
z5 = collocate(z5opt);&lt;br /&gt;
u  = collocate(uopt);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,z1,&#039;*-&#039;,t,z2,&#039;*-&#039;,t,z3,&#039;*-&#039;,t,z4,&#039;*-&#039;,t,z5,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;z1&#039;,&#039;z2&#039;,&#039;z3&#039;,&#039;z4&#039;,&#039;z5&#039;);&lt;br /&gt;
title(&#039;Park Bio Reactor state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Park Bio Reactor control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:parkBioReactor_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Parameter_Estimation_Problem&amp;diff=2240</id>
		<title>PROPT Parameter Estimation Problem</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Parameter_Estimation_Problem&amp;diff=2240"/>
		<updated>2011-11-09T12:10:52Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Example 5: DYNOPT User&#039;s Guide version 4.1.0&lt;br /&gt;
&lt;br /&gt;
M. Cizniar, M. Fikar, M. A. Latifi, MATLAB Dynamic Optimisation Code DYNOPT. User&#039;s Guide, Technical Report, KIRP FCHPT STU Bratislava, Slovak Republic, 2006.&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
Find p1 and p2 over t in [0; 6 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = \sum_{i=1,2,3,5} ( x_1(t_i) - x_1^{m}(t_i) )^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = 1-2*x_2-x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_0 = [p_1 \ p_2] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_i = [1 \ 2 \ 3 \ 5] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1^{m}(t_i) = [0.264 \ 0.594 \ 0.801 \ 0.959] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; -1.5 &amp;lt;= p_{1:2} &amp;lt;= 1.5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t p1 p2&lt;br /&gt;
x1meas = [0.264;0.594;0.801;0.959];&lt;br /&gt;
tmeas  = [1;2;3;5];&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {-1.5 &amp;lt;= p1 &amp;lt;= 1.5&lt;br /&gt;
    -1.5 &amp;lt;= p2 &amp;lt;= 1.5};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[10 40]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 6, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
    tomStates x1 x2&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    if n == 10&lt;br /&gt;
        x0 = {p1 == 0; p2 == 0};&lt;br /&gt;
    else&lt;br /&gt;
        x0 = {p1 == p1opt; p2 == p2opt&lt;br /&gt;
            icollocate({x1 == x1opt; x2 == x2opt})};&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x1 == p1; x2 == p2});&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    x1err = sum((atPoints(tmeas,x1) - x1meas).^2);&lt;br /&gt;
    ceq = collocate({dot(x1) == x2; dot(x2) == 1-2*x2-x1});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = x1err;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name   = &#039;Parameter Estimation&#039;;&lt;br /&gt;
    options.solver = &#039;snopt&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x, p for starting point&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    p1opt = subs(p1, solution);&lt;br /&gt;
    p2opt = subs(p2, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.049765 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Parameter Estimation               f_k       0.000000352979271145&lt;br /&gt;
                                       sum(|constr|)      0.000000000000054134&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000000352979325279&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 Iter    5 MinorIter   17&lt;br /&gt;
Elapsed time: 0.002000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qp&lt;br /&gt;
Time for symbolic processing: 0.051384 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem:  1: Parameter Estimation               f_k       0.000000355693079657&lt;br /&gt;
                                       sum(|constr|)      0.000000000000071929&lt;br /&gt;
                              f(x_k) + sum(|constr|)      0.000000355693151586&lt;br /&gt;
                                              f(x_0)     -1.983813647020728800&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 MinorIter   40&lt;br /&gt;
Elapsed time: 0.003000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = collocate(x1opt);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,tmeas,x1meas,&#039;ro&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;Meas&#039;);&lt;br /&gt;
title(&#039;Parameter Estimation state variable&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:parameterEstimation_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Parallel_Reactions_in_Tubular_Reactor&amp;diff=2239</id>
		<title>PROPT Parallel Reactions in Tubular Reactor</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Parallel_Reactions_in_Tubular_Reactor&amp;diff=2239"/>
		<updated>2011-11-09T12:10:45Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Problem 4: DYNOPT User&#039;s Guide version 4.1.0&lt;br /&gt;
&lt;br /&gt;
Batch reactor with reactions: A -&amp;gt; B and A -&amp;gt; C.&lt;br /&gt;
&lt;br /&gt;
M. Cizniar, M. Fikar, M. A. Latifi, MATLAB Dynamic Optimisation Code DYNOPT. User&#039;s Guide, Technical Report, KIRP FCHPT STU Bratislava, Slovak Republic, 2006.&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
Find T over t in [0; 1 ] to maximize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_2(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = -(u+0.5*u^2)*x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u*x_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(0) = [1 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u &amp;lt;= 5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
p = tomPhase(&#039;p&#039;, t, 0, 1, 30);&lt;br /&gt;
setPhase(p);&lt;br /&gt;
&lt;br /&gt;
tomStates x1 x2&lt;br /&gt;
tomControls u&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({x1 == 1; x2 == 0})&lt;br /&gt;
    collocate(u == 5*t)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0 &amp;lt;= collocate(u) &amp;lt;= 5};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = initial({x1 == 1; x2 == 0});&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(x1) == -(u+0.5*u.^2).*x1&lt;br /&gt;
    dot(x2) == u.*x1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = -final(x2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Parallel Reactions&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1),solution);&lt;br /&gt;
x2 = subs(collocate(x2),solution);&lt;br /&gt;
u  = subs(collocate(u),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.087774 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Parallel Reactions             f_k      -0.573540787113988930&lt;br /&gt;
                                       sum(|constr|)      0.000000228705850230&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.573540558408138670&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   35 ConJacEv   35 Iter   34 MinorIter  118&lt;br /&gt;
CPU time: 0.046800 sec. Elapsed time: 0.042000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;Parallel Reactions state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Parallel Reactions control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:parallelReactions_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Orbit_Raising_Minimum_Time&amp;diff=2238</id>
		<title>PROPT Orbit Raising Minimum Time</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Orbit_Raising_Minimum_Time&amp;diff=2238"/>
		<updated>2011-11-09T12:10:42Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
Minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = t_f &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to the dynamic constraints&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d_r}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{du}{dt} = \frac{v^2}{r}-\frac{mmu}{r^2}+T*\frac{w1}{m} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dv}{dt} = -u*\frac{v}{r}+T*\frac{w2}{m} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dm}{dt} = -\frac{T}{g0*ISP} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
the boundary conditions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; r(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; u(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; u(t_f) = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v(t_0) = (\frac{mmu}{r(t_0)})^{0.5} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v(t_f) = (\frac{mmu}{r(t_f)})^{0.5} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; m(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where w1 = sin(phi) and w2 = cos(phi)&lt;br /&gt;
&lt;br /&gt;
At t_f, r and m are free.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2009 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
mmu     = 1;&lt;br /&gt;
t_f    = 3.32;  m_0    = 1;            r_0    = 1;   u_0    = 0;&lt;br /&gt;
u_f    = 0;     v_0    = sqrt(mmu/r_0); rmin   = 0.9; rmax   = 5;&lt;br /&gt;
umin   = -5;    umax   = 5;            vmin   = -5;  vmax   = 5;&lt;br /&gt;
mmax   = m_0;   mmin   = 0.1;          tf_min = 0.5; tf_max = 10;&lt;br /&gt;
r_f     = 1.5;&lt;br /&gt;
&lt;br /&gt;
T  = 0.1405;&lt;br /&gt;
Ve = 1.8758;&lt;br /&gt;
&lt;br /&gt;
toms t t_f&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, t_f, 50);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates r u v m&lt;br /&gt;
&lt;br /&gt;
% The problem becomes less nonlinear if w1 and w2 are control variables&lt;br /&gt;
% (with the constraints w1^2+w2^2==1) than if phi is the control varialbe&lt;br /&gt;
% (with w1 and w2 being nonlinear functions of phi).&lt;br /&gt;
tomControls w1 w2&lt;br /&gt;
phi = atan2(w1,w2);&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {t_f == 3.32&lt;br /&gt;
    icollocate({&lt;br /&gt;
    r == r_0+(r_f-r_0)*t/t_f&lt;br /&gt;
    u == 0.1&lt;br /&gt;
    v == v_0&lt;br /&gt;
    m == m_0-(T/Ve)*t})&lt;br /&gt;
    collocate({&lt;br /&gt;
    w1 == -0.7*sign(t-t_f/2)&lt;br /&gt;
    w2 == 0.4&lt;br /&gt;
    })};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({&lt;br /&gt;
    r == r_0&lt;br /&gt;
    u == u_0&lt;br /&gt;
    v == v_0&lt;br /&gt;
    m == m_0&lt;br /&gt;
    })&lt;br /&gt;
    final({&lt;br /&gt;
    r == r_f&lt;br /&gt;
    u == u_f&lt;br /&gt;
    v == sqrt(mmu/r)})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {0.5 &amp;lt;= t_f &amp;lt;= 10&lt;br /&gt;
    rmin &amp;lt;= icollocate(r) &amp;lt;= rmax&lt;br /&gt;
    umin &amp;lt;= icollocate(u) &amp;lt;= umax&lt;br /&gt;
    vmin &amp;lt;= icollocate(v) &amp;lt;= vmax&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(r) == u&lt;br /&gt;
    dot(u) == v^2/r-mmu/r^2+T*w1/m&lt;br /&gt;
    dot(v) == -u*v/r+T*w2/m&lt;br /&gt;
    dot(m) == -T/Ve&lt;br /&gt;
    w1^2+w2^2 == 1&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = t_f;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Orbit Raising Problem Min Time&#039;;&lt;br /&gt;
options.scale = &#039;manual&#039;; % Auto-scaling is not really needed as all variables are already reasonably scaled.&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.26997 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Orbit Raising Problem Min Time  f_k       3.248079535631201800&lt;br /&gt;
                                        sum(|constr|)      0.000032253387193478&lt;br /&gt;
                               f(x_k) + sum(|constr|)      3.248111789018395300&lt;br /&gt;
                                               f(x_0)      3.319999999999999800&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   68 ConJacEv   68 Iter   35 MinorIter  283&lt;br /&gt;
CPU time: 1.606810 sec. Elapsed time: 0.414000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
ezplot([r u v m]);&lt;br /&gt;
legend(&#039;r&#039;,&#039;u&#039;,&#039;v&#039;,&#039;m&#039;);&lt;br /&gt;
title(&#039;Orbit Raising Problem Min Time state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
ezplot([w1 w2 phi])&lt;br /&gt;
legend(&#039;w_1&#039;, &#039;w_2&#039;, &#039;\phi&#039;);&lt;br /&gt;
title(&#039;Orbit Raising Problem Min Time control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:orbitRaisingMinTime_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Orbit_Raising_Maximum_Radius&amp;diff=2237</id>
		<title>PROPT Orbit Raising Maximum Radius</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Orbit_Raising_Maximum_Radius&amp;diff=2237"/>
		<updated>2011-11-09T12:10:40Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
Maximize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = r(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to the dynamic constraints&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{d_r}{dt} = u &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{du}{dt} = \frac{v^2}{r}-\frac{mmu}{r^2}+T*\frac{w1}{m} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dv}{dt} = -u*\frac{v}{r}+T*\frac{w2}{m} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dm}{dt} = -\frac{T}{g0*ISP} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
the boundary conditions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; r(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; u(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; u(t_f) = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v(t_0) = (\frac{mmu}{r(t_0)})^{0.5} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v(t_f) = (\frac{mmu}{r(t_f)})^{0.5} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; m(t_0) = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and the path constraint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; w_1^2+w_2^2 = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The control pitch angel is not being used in this formulation. Instead two control variables (w1,w2) are used to for the thrust direction. A path constraint ensures that (w1,w2) is a unit vector.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2009 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
t_F    = 3.32;&lt;br /&gt;
mmu    = 1;&lt;br /&gt;
m_0   = 1;   r_0     = 1;            u_0         = 0;&lt;br /&gt;
u_f   = 0;   v_0     = sqrt(mmu/r_0); rmin        = 0.9;&lt;br /&gt;
rmax  = 5;   umin    = -5;           umax        = 5;&lt;br /&gt;
vmin  = -5;  vmax    = 5;            mmax        = m_0;&lt;br /&gt;
mmin  = 0.1;&lt;br /&gt;
&lt;br /&gt;
T  = 0.1405;&lt;br /&gt;
Ve = 1.8758;&lt;br /&gt;
&lt;br /&gt;
toms t&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, t_F, 40);&lt;br /&gt;
setPhase(p1);&lt;br /&gt;
&lt;br /&gt;
tomStates r u v m&lt;br /&gt;
tomControls w1 w2&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate({&lt;br /&gt;
    r == r_0&lt;br /&gt;
    u == u_0 + (u_f-u_0)*t/t_F&lt;br /&gt;
    v == v_0&lt;br /&gt;
    m == m_0})&lt;br /&gt;
    collocate({w1 == 0; w2 == 1})};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial({&lt;br /&gt;
    r == r_0&lt;br /&gt;
    u == u_0&lt;br /&gt;
    v == v_0&lt;br /&gt;
    m == m_0&lt;br /&gt;
    })&lt;br /&gt;
    final({u == u_f&lt;br /&gt;
    v - sqrt(mmu/r) == 0})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {&lt;br /&gt;
    rmin &amp;lt;= icollocate(r) &amp;lt;= rmax&lt;br /&gt;
    umin &amp;lt;= icollocate(u) &amp;lt;= umax&lt;br /&gt;
    vmin &amp;lt;= icollocate(v) &amp;lt;= vmax&lt;br /&gt;
    mmin &amp;lt;= icollocate(m) &amp;lt;= mmax&lt;br /&gt;
    -1 &amp;lt;= collocate(w1) &amp;lt;= 1&lt;br /&gt;
    -1 &amp;lt;= collocate(w2) &amp;lt;= 1};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = collocate({&lt;br /&gt;
    dot(r) == u&lt;br /&gt;
    dot(u) == v^2/r-mmu/r^2+T*w1/m&lt;br /&gt;
    dot(v) == -u*v/r+T*w2/m&lt;br /&gt;
    dot(m) == -T/Ve&lt;br /&gt;
    w1^2+w2^2 == 1});&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = -final(r);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Orbit Raising Problem Max Radius&#039;;&lt;br /&gt;
options.solver = &#039;snopt&#039;;&lt;br /&gt;
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.22212 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Orbit Raising Problem Max Radius  f_k      -1.518744202740535800&lt;br /&gt;
                                          sum(|constr|)      0.000017265830060524&lt;br /&gt;
                                 f(x_k) + sum(|constr|)     -1.518726936910475200&lt;br /&gt;
                                                 f(x_0)     -0.999999999999991120&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   59 ConJacEv   59 Iter   36 MinorIter  346&lt;br /&gt;
CPU time: 0.202801 sec. Elapsed time: 0.226000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
ezplot([r u v m]);&lt;br /&gt;
legend(&#039;r&#039;,&#039;u&#039;,&#039;v&#039;,&#039;m&#039;);&lt;br /&gt;
title(&#039;Orbit Raising Problem Max Radius state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
ezplot([w1 w2 atan2(w1,w2)])&lt;br /&gt;
legend(&#039;w_1&#039;, &#039;w_2&#039;, &#039;\phi&#039;);&lt;br /&gt;
title(&#039;Orbit Raising Problem Max Radius control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:orbitRaisingMaxRadius_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_One_Dimensional_Rocket_Ascent&amp;diff=2236</id>
		<title>PROPT One Dimensional Rocket Ascent</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_One_Dimensional_Rocket_Ascent&amp;diff=2236"/>
		<updated>2011-11-09T12:10:31Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
User&#039;s Guide for DIRCOL&lt;br /&gt;
&lt;br /&gt;
Problem 2.3 One-dimensional ascent of a rocket&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find tCut over t in [0; t_F ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = tCut &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = a-g \ (0&amp;lt;t&amp;lt;tCut)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -g \ (tCut&amp;lt;t&amp;lt;t_F)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [x_1 \ x_2] = 0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; g = 1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; a = 2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_1(t_f) = 100 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms tCut tp2&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t, 0, tCut, 20);&lt;br /&gt;
p2 = tomPhase(&#039;p2&#039;, t, tCut, tp2, 20);&lt;br /&gt;
&lt;br /&gt;
t_f = tCut+tp2;&lt;br /&gt;
&lt;br /&gt;
x1p1 = tomState(p1,&#039;x1p1&#039;);&lt;br /&gt;
x2p1 = tomState(p1,&#039;x2p1&#039;);&lt;br /&gt;
x1p2 = tomState(p2,&#039;x1p2&#039;);&lt;br /&gt;
x2p2 = tomState(p2,&#039;x2p2&#039;);&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {tCut==10&lt;br /&gt;
    t_f==15&lt;br /&gt;
    icollocate(p1,{x1p1 == 50*tCut/10;x2p1 == 0;})&lt;br /&gt;
    icollocate(p2,{x1p2 == 50+50*t/100;x2p2 == 0;})};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {&lt;br /&gt;
    1  &amp;lt;= tCut &amp;lt;= t_f-0.00001&lt;br /&gt;
    t_f &amp;lt;= 100&lt;br /&gt;
    0  &amp;lt;= icollocate(p1,x1p1)&lt;br /&gt;
    0  &amp;lt;= icollocate(p1,x2p1)&lt;br /&gt;
    0  &amp;lt;= icollocate(p2,x1p2)&lt;br /&gt;
    0  &amp;lt;= icollocate(p2,x2p2)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial(p1,{x1p1 == 0;x2p1 == 0;})&lt;br /&gt;
    final(p2,x1p2 == 100)};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
a = 2; g = 1;&lt;br /&gt;
ceq = {collocate(p1,{&lt;br /&gt;
    dot(p1,x1p1) == x2p1&lt;br /&gt;
    dot(p1,x2p1) == a-g})&lt;br /&gt;
    collocate(p2,{&lt;br /&gt;
    dot(p2,x1p2) == x2p2&lt;br /&gt;
    dot(p2,x2p2) == -g})};&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = tCut;&lt;br /&gt;
&lt;br /&gt;
% Link phase&lt;br /&gt;
link = {final(p1,x1p1) == initial(p2,x1p2)&lt;br /&gt;
    final(p1,x2p1) == initial(p2,x2p2)};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;One Dim Rocket&#039;;&lt;br /&gt;
constr = {cbox, cbnd, ceq, link};&lt;br /&gt;
solution = ezsolve(objective, constr, x0, options);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.11449 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: One Dim Rocket                 f_k       9.999998166162907200&lt;br /&gt;
                                       sum(|constr|)      0.000733735151552596&lt;br /&gt;
                              f(x_k) + sum(|constr|)     10.000731901314460000&lt;br /&gt;
                                              f(x_0)     10.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   10 ConJacEv   10 Iter    8 MinorIter   91&lt;br /&gt;
CPU time: 0.015600 sec. Elapsed time: 0.015000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
t = [subs(collocate(p1,t),solution);subs(collocate(p2,t),solution)];&lt;br /&gt;
x1 = subs(collocate(p1,x1p1),solution);&lt;br /&gt;
x1 = [x1;subs(collocate(p2,x1p2),solution)];&lt;br /&gt;
x2 = subs(collocate(p1,x2p1),solution);&lt;br /&gt;
x2 = [x2;subs(collocate(p2,x2p2),solution)];&lt;br /&gt;
&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;);&lt;br /&gt;
title(&#039;One Dim Rocket state variables&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:onedimRocket_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Oil_Shale_Pyrolysis&amp;diff=2235</id>
		<title>PROPT Oil Shale Pyrolysis</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Oil_Shale_Pyrolysis&amp;diff=2235"/>
		<updated>2011-11-09T12:10:29Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Dynamic Optimization of Batch Reactors Using Adaptive Stochastic Algorithms 1997, Eugenio F. Carrasco, Julio R. Banga&lt;br /&gt;
&lt;br /&gt;
Case Study II: Oil Shale Pyrolysis&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
A very challenging optimal control problem is the oil shale pyrolysis case study, as considered by Luus (1994). The system consists of a series of five chemical reactions:&lt;br /&gt;
&lt;br /&gt;
A1 -&amp;gt; A2&lt;br /&gt;
&lt;br /&gt;
A2 -&amp;gt; A3&lt;br /&gt;
&lt;br /&gt;
A1+A2 -&amp;gt; A2+A2&lt;br /&gt;
&lt;br /&gt;
A1+A2 -&amp;gt; A3+A2&lt;br /&gt;
&lt;br /&gt;
A1+A2 -&amp;gt; A4+A2&lt;br /&gt;
&lt;br /&gt;
This system is described by the differential equations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = -k_1*x_1-(k_3+k_4+k_5)*x_1*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = k_1*x_1-k_2*x_2+k_3*x_1*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = k_2*x_2+k_4*x_1*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = k_5*x_1*x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where the state variables are the concentrations of species, Ai, i = 1, ..., 4. The initial condition is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [1 \ 0 \ 0 \ 0]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rate expressions are given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; k_i = k_{i0}*exp(-\frac{Ei}{R*T}), i=1,2,3,4,5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where the values of ki0 and Ei are given by Luus (1994). The optimal control problem is to find the residence time t_f and the temperature profile T(t) in the time interval 0 &amp;lt;= t &amp;lt;= t_f so that the production of pyrolytic bitumen, given by x2, is maximized. Therefore, the performance index is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_2(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The constraints on the control variable (temperature) are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 698.15 &amp;lt;= T &amp;lt;= 748.15 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
toms t_f&lt;br /&gt;
&lt;br /&gt;
ai = [8.86; 24.25; 23.67; 18.75; 20.70];&lt;br /&gt;
bi = [20300; 37400; 33800; 28200; 31000]/1.9872;&lt;br /&gt;
&lt;br /&gt;
for n=[4 10 20 30 35]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, t_f, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates x1 x2 x3 x4&lt;br /&gt;
    tomControls T&lt;br /&gt;
&lt;br /&gt;
    % Initial guess&lt;br /&gt;
    if n == 4&lt;br /&gt;
        x0 = {t_f == 9.3&lt;br /&gt;
            collocate(T == 725)};&lt;br /&gt;
    else&lt;br /&gt;
        x0 = {t_f == tfopt&lt;br /&gt;
            icollocate({&lt;br /&gt;
            x1 == x1opt; x2 == x2opt&lt;br /&gt;
            x3 == x3opt; x4 == x4opt&lt;br /&gt;
            })&lt;br /&gt;
            collocate(T == Topt)};&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {9.1 &amp;lt;= t_f &amp;lt;= 12&lt;br /&gt;
        icollocate({0 &amp;lt;= x1 &amp;lt;= 1; 0 &amp;lt;= x2 &amp;lt;= 1&lt;br /&gt;
        0 &amp;lt;= x3 &amp;lt;= 1; 0 &amp;lt;= x4 &amp;lt;= 1})&lt;br /&gt;
        698.15 &amp;lt;= collocate(T) &amp;lt;= 748.15};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x1 == 1; x2 == 0; x3 == 0; x4 == 0});&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
&lt;br /&gt;
    ki1 = exp(ai(1)-bi(1)./T);&lt;br /&gt;
    ki2 = exp(ai(2)-bi(2)./T);&lt;br /&gt;
    ki3 = exp(ai(3)-bi(3)./T);&lt;br /&gt;
    ki4 = exp(ai(4)-bi(4)./T);&lt;br /&gt;
    ki5 = exp(ai(5)-bi(5)./T);&lt;br /&gt;
&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x1) == -ki1.*x1-(ki3+ki4+ki5).*x1.*x2&lt;br /&gt;
        dot(x2) == ki1.*x1-ki2.*x2+ki3.*x1.*x2&lt;br /&gt;
        dot(x3) == ki2.*x2+ki4.*x1.*x2&lt;br /&gt;
        dot(x4) == ki5.*x1.*x2});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = -final(x2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Oil Pyrolysis&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    x3opt = subs(x3, solution);&lt;br /&gt;
    x4opt = subs(x4, solution);&lt;br /&gt;
    Topt = subs(T, solution);&lt;br /&gt;
    tfopt = subs(final(t), solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.42383 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Oil Pyrolysis                  f_k      -0.357327805323273240&lt;br /&gt;
                                       sum(|constr|)      0.000000000957541036&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.357327804365732190&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   93 ConJacEv   93 Iter   50 MinorIter  197&lt;br /&gt;
CPU time: 0.062400 sec. Elapsed time: 0.064000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.42239 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Oil Pyrolysis                  f_k      -0.354368283541904860&lt;br /&gt;
                                       sum(|constr|)      0.000000002719365042&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.354368280822539790&lt;br /&gt;
                                              f(x_0)     -0.357327805323273070&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  208 ConJacEv  208 Iter  112 MinorIter  305&lt;br /&gt;
CPU time: 0.156001 sec. Elapsed time: 0.153000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.43305 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Oil Pyrolysis                  f_k      -0.351747594492437030&lt;br /&gt;
                                       sum(|constr|)      0.000000280199856233&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.351747314292580830&lt;br /&gt;
                                              f(x_0)     -0.354368283541905970&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  124 ConJacEv  124 Iter   71 MinorIter  281&lt;br /&gt;
CPU time: 0.140401 sec. Elapsed time: 0.142000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.42125 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Oil Pyrolysis                  f_k      -0.352833701465704920&lt;br /&gt;
                                       sum(|constr|)      0.000000018165177960&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.352833683300526950&lt;br /&gt;
                                              f(x_0)     -0.351747594492436640&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  409 ConJacEv  409 Iter  194 MinorIter  697&lt;br /&gt;
CPU time: 0.639604 sec. Elapsed time: 0.645000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.42103 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Oil Pyrolysis                  f_k      -0.352618526247765740&lt;br /&gt;
                                       sum(|constr|)      0.000016167955157926&lt;br /&gt;
                              f(x_k) + sum(|constr|)     -0.352602358292607830&lt;br /&gt;
                                              f(x_0)     -0.352833701465704590&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   64 ConJacEv   64 Iter   46 MinorIter  364&lt;br /&gt;
CPU time: 0.187201 sec. Elapsed time: 0.180000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = subs(collocate(x1opt),solution);&lt;br /&gt;
x2 = subs(collocate(x2opt),solution);&lt;br /&gt;
x3 = subs(collocate(x3opt),solution);&lt;br /&gt;
x4 = subs(collocate(x4opt),solution);&lt;br /&gt;
T  = subs(collocate(Topt),solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;);&lt;br /&gt;
title(&#039;Oil Pyrolysis state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,T,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;T&#039;);&lt;br /&gt;
title(&#039;Oil Pyrolysis control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:oilPyrolysis_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Obstacle_Avoidance&amp;diff=2234</id>
		<title>PROPT Obstacle Avoidance</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Obstacle_Avoidance&amp;diff=2234"/>
		<updated>2011-11-09T12:10:27Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
OPTRAGEN 1.0 A MATLAB Toolbox for Optimal Trajectory Generation, Raktim Bhattacharya, Texas A&amp;amp;M University (Note: There is typographical error in the OPTRAGEN documentation. The objective involves second derivatives of x and y.)&lt;br /&gt;
&lt;br /&gt;
A robot with obstacles in 2D space. Travel from point A to B using minimum energy.&lt;br /&gt;
&lt;br /&gt;
==Problem Formulation==&lt;br /&gt;
&lt;br /&gt;
Find theta(t) and V over t in [0; 1 ] to minimize&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \int_0^{1} ( (\frac{d^2x}{dt^2})^2 + (\frac{d^2y}{dt^2})^2 ) \mathrm{d}t &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx}{dt} = V*cos(theta) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dy}{dt} = V*sin(theta) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [x_0 \ y_0] = [0 \ 0] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; [x_1 \ y_1] = [1.2 \ 1.6] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; (x-0.4)^2 + (y-0.5)^2 &amp;gt;= 0.1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; (x-0.8)^2 + (y-1.5)^2 &amp;gt;= 0.1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Where V is a constant scalar speed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&lt;br /&gt;
clear pi % 3.14159... unless someone has set it to something else!&lt;br /&gt;
&lt;br /&gt;
toms t V&lt;br /&gt;
&lt;br /&gt;
t_f = 1; % final time&lt;br /&gt;
&lt;br /&gt;
% Starting guess&lt;br /&gt;
speed = 5;&lt;br /&gt;
xopt = 1.2*t;&lt;br /&gt;
yopt = 1.6*t;&lt;br /&gt;
vxopt = 1.2;&lt;br /&gt;
vyopt = 1.6;&lt;br /&gt;
thetaopt = pi/4;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[4 15 30]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    % Create a new phase and states, using n collocation points&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, t_f, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
    tomStates x y vx vy&lt;br /&gt;
    tomControls theta&lt;br /&gt;
&lt;br /&gt;
    % Interpolate an initial guess for the n collocation points&lt;br /&gt;
    x0 = {V == speed&lt;br /&gt;
        icollocate({x == xopt; y == yopt; vx == vxopt; vy == vyopt})&lt;br /&gt;
        collocate(theta == thetaopt)};&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {0 &amp;lt;= V &amp;lt;= 100 };&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = {initial({x == 0; y == 0})&lt;br /&gt;
        final({x == 1.2; y == 1.6})};&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    ode = collocate({&lt;br /&gt;
        dot(x) == vx == V*cos(theta)&lt;br /&gt;
        dot(y) == vy == V*sin(theta)&lt;br /&gt;
        });&lt;br /&gt;
&lt;br /&gt;
    % A 30th order polynomial is more than sufficient to give good&lt;br /&gt;
    % accuracy. However, that means that mcollocate would only check&lt;br /&gt;
    % about 60 points. In order to make sure we don&#039;t hit an obstacle,&lt;br /&gt;
    % we check 300 evenly spaced points instead, using atPoints.&lt;br /&gt;
    obstacles = atPoints(linspace(0,t_f,300), {&lt;br /&gt;
        (x-0.4)^2 + (y-0.5)^2 &amp;gt;= 0.1&lt;br /&gt;
        (x-0.8)^2 + (y-1.5)^2 &amp;gt;= 0.1});&lt;br /&gt;
&lt;br /&gt;
    % Objective: minimum energy.&lt;br /&gt;
    objective = integrate(dot(vx)^2+dot(vy)^2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Obstacle avoidance&#039;;&lt;br /&gt;
    constr = {cbox, cbnd, ode, obstacles};&lt;br /&gt;
    solution = ezsolve(objective, constr, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x, y, and speed, to use as starting guess in the next iteration&lt;br /&gt;
    xopt = subs(x, solution);&lt;br /&gt;
    yopt = subs(y, solution);&lt;br /&gt;
    vxopt = subs(vx, solution);&lt;br /&gt;
    vyopt = subs(vy, solution);&lt;br /&gt;
    thetaopt = subs(theta, solution);&lt;br /&gt;
    speed = subs(V,solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.16968 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Obstacle avoidance             f_k      29.812856165009947000&lt;br /&gt;
                                       sum(|constr|)      0.000000001309307815&lt;br /&gt;
                              f(x_k) + sum(|constr|)     29.812856166319254000&lt;br /&gt;
                                              f(x_0)      0.000000000000062528&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   22 ConJacEv   22 Iter   20 MinorIter 2732&lt;br /&gt;
CPU time: 0.218401 sec. Elapsed time: 0.218000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.17036 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Obstacle avoidance             f_k      22.128728366252528000&lt;br /&gt;
                                       sum(|constr|)      0.000000000006755102&lt;br /&gt;
                              f(x_k) + sum(|constr|)     22.128728366259281000&lt;br /&gt;
                                              f(x_0)     29.812856165012775000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  151 ConJacEv  151 Iter  136 MinorIter  486&lt;br /&gt;
CPU time: 0.920406 sec. Elapsed time: 0.915000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: qpcon&lt;br /&gt;
Time for symbolic processing: 0.16882 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Obstacle avoidance             f_k      22.091923284169869000&lt;br /&gt;
                                       sum(|constr|)      0.000000000011094717&lt;br /&gt;
                              f(x_k) + sum(|constr|)     22.091923284180965000&lt;br /&gt;
                                              f(x_0)     22.128728366262933000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  309 ConJacEv  309 Iter  281 MinorIter  720&lt;br /&gt;
CPU time: 4.071626 sec. Elapsed time: 3.770000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
th = linspace(0,2*pi,500);&lt;br /&gt;
x1 = sqrt(0.1)*cos(th)+0.4;&lt;br /&gt;
y1 = sqrt(0.1)*sin(th)+0.5;&lt;br /&gt;
x2 = sqrt(0.1)*cos(th)+0.8;&lt;br /&gt;
y2 = sqrt(0.1)*sin(th)+1.5;&lt;br /&gt;
ezplot(x,y);&lt;br /&gt;
hold on&lt;br /&gt;
plot(x1,y1,&#039;r&#039;,x2,y2,&#039;r&#039;);&lt;br /&gt;
hold off&lt;br /&gt;
xlabel(&#039;x&#039;);&lt;br /&gt;
ylabel(&#039;y&#039;);&lt;br /&gt;
title(sprintf(&#039;Obstacle avoidance state variables, Speed = %2.4g&#039;,speed));&lt;br /&gt;
axis image&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:obstacleAvoidance_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Nonlinear_CSTR&amp;diff=2233</id>
		<title>PROPT Nonlinear CSTR</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Nonlinear_CSTR&amp;diff=2233"/>
		<updated>2011-11-09T12:10:25Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Dynamic optimization of chemical and biochemical processes using restricted second-order information 2001, Eva Balsa-Canto, Julio R. Banga, Antonio A. Alonso Vassilios S. Vassiliadis&lt;br /&gt;
&lt;br /&gt;
Case Study III: Nonlinear CSTR&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
The problem was first introduced by Jensen (1964) and consists of determining the four optimal controls of a chemical reactor in order to obtain maximum economic benefit. The system dynamics describe four simultaneous chemical reactions taking place in an isothermal continuous stirred tank reactor. The controls are the flow rates of three feed streams and an electrical energy input used to promote a photochemical reaction. Luus (1990) and Bojkov, Hansel, and Luus (1993) considered two sub-cases using three and four control variables respectively.&lt;br /&gt;
&lt;br /&gt;
The problem is formulated as follows:Find u1(t), u2(t), u3(t) and u4(t) over t in [t0,t_f] to maximize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_8(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = u_4-q*x_1-17.6*x_1*x_2-23*x_1*x_6*u_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = u_1-q*x_2-17.6*x_1*x_2-146*x_2*x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = u_2-q*x_3-73*x_2*x_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_4}{dt} = -q*x_4+35.2*x_1*x_2-51.3*x_4*x_5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_5}{dt} = -q*x_5+219*x_2*x_3-51.3*x_4*x_5 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_6}{dt} = -q*x_6+102.6*x_4.*x_5-23*x_1*x_6*u_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_7}{dt} = -q*x_7+46*x_1*x_6*u_3 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_8}{dt} = 5.8*(q*x_1-u_4)-3.7*u_1-4.1*u_2+ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; q*(23*x_4+11*x_5+28*x_6+35*x_7)-5*u_3^2-0.099 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; q = u_1+u_2+u_4; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
with the initial conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0.1883 \ 0.2507 \ 0.0467 \ 0.0899 \ 0.1804 \ 0.1394 \ 0.1046 \ 0.000]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the following bounds on the control variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u1 &amp;lt;= 20 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u2 &amp;lt;= 6 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u3 &amp;lt;= 4 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; 0 &amp;lt;= u4 &amp;lt;= 20 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The final time is considered fixed as t_f = 0.2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem, using a successively larger number collocation points==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
for n=[5 20 60]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    p = tomPhase(&#039;p&#039;, t, 0, 0.2, n);&lt;br /&gt;
    setPhase(p);&lt;br /&gt;
&lt;br /&gt;
    tomStates x1 x2 x3 x4 x5 x6 x7 x8&lt;br /&gt;
    tomControls u1 u2 u3 u4&lt;br /&gt;
&lt;br /&gt;
    % Interpolate an initial guess for the n collocation points&lt;br /&gt;
    if n == 5&lt;br /&gt;
        x0 = {};&lt;br /&gt;
    else&lt;br /&gt;
        x0 = {icollocate({x1 == x1opt; x2 == x2opt&lt;br /&gt;
            x3 == x3opt; x4 == x4opt; x5 == x5opt&lt;br /&gt;
            x6 == x6opt; x7 == x7opt; x8 == x8opt})&lt;br /&gt;
            collocate({u1 == u1opt; u2 == u2opt&lt;br /&gt;
            u3 == u3opt; u4 == u4opt})};&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    % Box constraints&lt;br /&gt;
    cbox = {icollocate({&lt;br /&gt;
        0 &amp;lt;= x1; 0 &amp;lt;= x2; 0 &amp;lt;= x3&lt;br /&gt;
        0 &amp;lt;= x4; 0 &amp;lt;= x5; 0 &amp;lt;= x6&lt;br /&gt;
        0 &amp;lt;= x7; 0 &amp;lt;= x8})&lt;br /&gt;
        collocate({&lt;br /&gt;
        0 &amp;lt;= u1 &amp;lt;= 20; 0 &amp;lt;= u2 &amp;lt;= 6&lt;br /&gt;
        0 &amp;lt;= u3 &amp;lt;= 4;  0 &amp;lt;= u4 &amp;lt;= 20})};&lt;br /&gt;
&lt;br /&gt;
    % Boundary constraints&lt;br /&gt;
    cbnd = initial({x1 == 0.1883; x2 == 0.2507&lt;br /&gt;
        x3 == 0.0467; x4 == 0.0899; x5 == 0.1804&lt;br /&gt;
        x6 == 0.1394; x7 == 0.1064; x8 == 0});&lt;br /&gt;
&lt;br /&gt;
    % ODEs and path constraints&lt;br /&gt;
    % 4.1*u2+(u1+u2.*u4) in another paper, -0.09 instead of -0.099&lt;br /&gt;
    q = u1+u2+u4;&lt;br /&gt;
    ceq = collocate({&lt;br /&gt;
        dot(x1) == (u4-q.*x1-17.6*x1.*x2-23*x1.*x6.*u3)&lt;br /&gt;
        dot(x2) == (u1-q.*x2-17.6*x1.*x2-146*x2.*x3)&lt;br /&gt;
        dot(x3) == (u2-q.*x3-73*x2.*x3)&lt;br /&gt;
        dot(x4) == (-q.*x4+35.2*x1.*x2-51.3*x4.*x5)&lt;br /&gt;
        dot(x5) == (-q.*x5+219*x2.*x3-51.3*x4.*x5)&lt;br /&gt;
        dot(x6) == (-q.*x6+102.6*x4.*x5-23*x1.*x6.*u3)&lt;br /&gt;
        dot(x7) == (-q.*x7+46*x1.*x6.*u3)&lt;br /&gt;
        dot(x8) == (5.8*(q.*x1-u4)-3.7*u1-4.1*u2+q.*...&lt;br /&gt;
        (23*x4+11*x5+28*x6+35*x7)-5*u3.^2-0.099)});&lt;br /&gt;
&lt;br /&gt;
    % Objective&lt;br /&gt;
    objective = -final(x8);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
    options = struct;&lt;br /&gt;
    options.name = &#039;Nonlinear CSTR&#039;;&lt;br /&gt;
    solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);&lt;br /&gt;
&lt;br /&gt;
    % Optimal x and u as starting point&lt;br /&gt;
    x1opt = subs(x1, solution);&lt;br /&gt;
    x2opt = subs(x2, solution);&lt;br /&gt;
    x3opt = subs(x3, solution);&lt;br /&gt;
    x4opt = subs(x4, solution);&lt;br /&gt;
    x5opt = subs(x5, solution);&lt;br /&gt;
    x6opt = subs(x6, solution);&lt;br /&gt;
    x7opt = subs(x7, solution);&lt;br /&gt;
    x8opt = subs(x8, solution);&lt;br /&gt;
    u1opt = subs(u1, solution);&lt;br /&gt;
    u2opt = subs(u2, solution);&lt;br /&gt;
    u3opt = subs(u3, solution);&lt;br /&gt;
    u4opt = subs(u4, solution);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.53917 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Nonlinear CSTR                 f_k     -21.841502289865439000&lt;br /&gt;
                                       sum(|constr|)      0.000000000210252562&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -21.841502289655185000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   53 ConJacEv   53 Iter   41 MinorIter  340&lt;br /&gt;
CPU time: 0.093601 sec. Elapsed time: 0.085000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.5364 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Nonlinear CSTR                 f_k     -21.896802275281715000&lt;br /&gt;
                                       sum(|constr|)      0.000000001588897791&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -21.896802273692817000&lt;br /&gt;
                                              f(x_0)    -21.841502289865474000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   96 ConJacEv   96 Iter   91 MinorIter  378&lt;br /&gt;
CPU time: 0.436803 sec. Elapsed time: 0.436000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.53229 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Nonlinear CSTR                 f_k     -21.887245712611271000&lt;br /&gt;
                                       sum(|constr|)      0.000000000382798748&lt;br /&gt;
                              f(x_k) + sum(|constr|)    -21.887245712228474000&lt;br /&gt;
                                              f(x_0)    -21.896802275281715000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv  288 ConJacEv  288 Iter  272 MinorIter 1059&lt;br /&gt;
CPU time: 15.802901 sec. Elapsed time: 15.853000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
t  = subs(collocate(t),solution);&lt;br /&gt;
x1 = collocate(x1opt);&lt;br /&gt;
x2 = collocate(x2opt);&lt;br /&gt;
x3 = collocate(x3opt);&lt;br /&gt;
x4 = collocate(x4opt);&lt;br /&gt;
x5 = collocate(x5opt);&lt;br /&gt;
x6 = collocate(x6opt);&lt;br /&gt;
x7 = collocate(x7opt);&lt;br /&gt;
x8 = collocate(x8opt);&lt;br /&gt;
u1 = collocate(u1opt);&lt;br /&gt;
u2 = collocate(u2opt);&lt;br /&gt;
u3 = collocate(u3opt);&lt;br /&gt;
u4 = collocate(u4opt);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
figure(1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;,t,x4,&#039;*-&#039; ...&lt;br /&gt;
    ,t,x5,&#039;*-&#039;,t,x6,&#039;*-&#039;,t,x7,&#039;*-&#039;,t,x8/10,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;,&#039;x4&#039;,&#039;x5&#039;,&#039;x6&#039;,&#039;x7&#039;,&#039;x8/10&#039;);&lt;br /&gt;
title(&#039;Nonlinear CSTR state variables&#039;);&lt;br /&gt;
&lt;br /&gt;
figure(2)&lt;br /&gt;
plot(t,u1,&#039;+-&#039;,t,u2,&#039;+-&#039;,t,u3,&#039;+-&#039;,t,u4,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u1&#039;,&#039;u2&#039;,&#039;u3&#039;,&#039;u4&#039;);&lt;br /&gt;
title(&#039;Nonlinear CSTR control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:nonlinearCSTR_01.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:nonlinearCSTR_02.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
	<entry>
		<id>http://tomwiki.com/index.php?title=PROPT_Nondifferentiable_system&amp;diff=2232</id>
		<title>PROPT Nondifferentiable system</title>
		<link rel="alternate" type="text/html" href="http://tomwiki.com/index.php?title=PROPT_Nondifferentiable_system&amp;diff=2232"/>
		<updated>2011-11-09T12:10:21Z</updated>

		<summary type="html">&lt;p&gt;Mbot: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Part Of Manual|title=the PROPT Manual|link=[[PROPT|PROPT Manual]]}}&lt;br /&gt;
&lt;br /&gt;
Global Optimization of Chemical Processes using Stochastic Algorithms 1996, Julio R. Banga, Warren D. Seider&lt;br /&gt;
&lt;br /&gt;
Case Study IV: Optimal control of a nondifferentiable system&lt;br /&gt;
&lt;br /&gt;
==Problem description==&lt;br /&gt;
&lt;br /&gt;
This problem has been studied by Thomopoulos and Papadakis who report convergence difficulties using several optimization algorithms and by Luus using Iterative Dynamic Programming. The optimal control problem is:&lt;br /&gt;
&lt;br /&gt;
Find u(t) to minimize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; J = x_3(t_f) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Subject to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_1}{dt} = x_2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_2}{dt} = -x_1-x_2+u+d &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \frac{dx_3}{dt} = 5*x_1^2+2.5*x_2^2+0.5*u^2 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = 100*[U(t-0.5)-U(t-0.6)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where U(t-alpha) is the unit function such that U = 0 for t - alpha &amp;lt; 0 and U = 1 for t - alpha &amp;gt; 0. Hence d is a rectangular pulse of magnitude 100 from t=0.5 until t=0.6. These authors consider t_f = 2.0s and the initial conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x(t_0) = [0 \ 0 \ 0]&#039; &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem setup==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
toms t1&lt;br /&gt;
p1 = tomPhase(&#039;p1&#039;, t1, 0, 0.5, 30);&lt;br /&gt;
toms t2&lt;br /&gt;
p2 = tomPhase(&#039;p2&#039;, t2, 0.5, 0.1, 20);&lt;br /&gt;
toms t3&lt;br /&gt;
p3 = tomPhase(&#039;p3&#039;, t3, 0.6, 2-0.6, 50);&lt;br /&gt;
&lt;br /&gt;
x1p1 = tomState(p1,&#039;x1p1&#039;);&lt;br /&gt;
x2p1 = tomState(p1,&#039;x2p1&#039;);&lt;br /&gt;
x3p1 = tomState(p1,&#039;x3p1&#039;);&lt;br /&gt;
up1 = tomControl(p1,&#039;up1&#039;);&lt;br /&gt;
&lt;br /&gt;
x1p2 = tomState(p2,&#039;x1p2&#039;);&lt;br /&gt;
x2p2 = tomState(p2,&#039;x2p2&#039;);&lt;br /&gt;
x3p2 = tomState(p2,&#039;x3p2&#039;);&lt;br /&gt;
up2 = tomControl(p2,&#039;up2&#039;);&lt;br /&gt;
&lt;br /&gt;
x1p3 = tomState(p3,&#039;x1p3&#039;);&lt;br /&gt;
x2p3 = tomState(p3,&#039;x2p3&#039;);&lt;br /&gt;
x3p3 = tomState(p3,&#039;x3p3&#039;);&lt;br /&gt;
up3 = tomControl(p3,&#039;up3&#039;);&lt;br /&gt;
&lt;br /&gt;
% Initial guess&lt;br /&gt;
x0 = {icollocate(p1,{x1p1 == 0;x2p1 == 0;x3p1 == 0})&lt;br /&gt;
    icollocate(p2,{x1p2 == 0;x2p2 == 0;x3p2 == 0})&lt;br /&gt;
    icollocate(p3,{x1p3 == 0;x2p3 == 0;x3p3 == 0})&lt;br /&gt;
    collocate(p1,up1==-4-8*t1/0.5)&lt;br /&gt;
    collocate(p2,up2==-12)&lt;br /&gt;
    collocate(p3,up3==-12+14*t3/2)};&lt;br /&gt;
&lt;br /&gt;
% Box constraints&lt;br /&gt;
cbox = {&lt;br /&gt;
    icollocate(p1,{-100 &amp;lt;= x1p1 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x2p1 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x3p1 &amp;lt;= 100})&lt;br /&gt;
    icollocate(p2,{-100 &amp;lt;= x1p2 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x2p2 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x3p2 &amp;lt;= 100})&lt;br /&gt;
    icollocate(p3,{-100 &amp;lt;= x1p3 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x2p3 &amp;lt;= 100&lt;br /&gt;
    -100 &amp;lt;= x3p3 &amp;lt;= 100})&lt;br /&gt;
    collocate(p1,-15 &amp;lt;= up1 &amp;lt;= 2)&lt;br /&gt;
    collocate(p2,-15 &amp;lt;= up2 &amp;lt;= 2)&lt;br /&gt;
    collocate(p3,-15 &amp;lt;= up3 &amp;lt;= 2)};&lt;br /&gt;
&lt;br /&gt;
% Boundary constraints&lt;br /&gt;
cbnd = {initial(p1,{x1p1 == 0;x2p1 == 0;x3p1 == 0})&lt;br /&gt;
    final(p3,x3p3) &amp;lt;= 60};&lt;br /&gt;
&lt;br /&gt;
% ODEs and path constraints&lt;br /&gt;
ceq = {collocate(p1,{&lt;br /&gt;
    dot(p1,x1p1) == x2p1&lt;br /&gt;
    dot(p1,x2p1) == -x1p1-x2p1+up1&lt;br /&gt;
    dot(p1,x3p1) == 5*x1p1.^2+2.5*x2p1.^2+0.5*up1.^2})&lt;br /&gt;
    collocate(p2,{&lt;br /&gt;
    dot(p2,x1p2) == x2p2&lt;br /&gt;
    dot(p2,x2p2) == -x1p2-x2p2+up2+100&lt;br /&gt;
    dot(p2,x3p2) == 5*x1p2.^2+2.5*x2p2.^2+0.5*up2.^2})&lt;br /&gt;
    collocate(p3,{&lt;br /&gt;
    dot(p3,x1p3) == x2p3&lt;br /&gt;
    dot(p3,x2p3) == -x1p3-x2p3+up3&lt;br /&gt;
    dot(p3,x3p3) == 5*x1p3.^2+2.5*x2p3.^2+0.5*up3.^2})};&lt;br /&gt;
&lt;br /&gt;
% Objective&lt;br /&gt;
objective = final(p3,x3p3);&lt;br /&gt;
&lt;br /&gt;
% Link phase&lt;br /&gt;
link = {final(p1,x1p1) == initial(p2,x1p2)&lt;br /&gt;
    final(p1,x2p1) == initial(p2,x2p2)&lt;br /&gt;
    final(p1,x3p1) == initial(p2,x3p2)&lt;br /&gt;
    final(p2,x1p2) == initial(p3,x1p3)&lt;br /&gt;
    final(p2,x2p2) == initial(p3,x2p3)&lt;br /&gt;
    final(p2,x3p2) == initial(p3,x3p3)};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solve the problem==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
options = struct;&lt;br /&gt;
options.name = &#039;Nondiff System&#039;;&lt;br /&gt;
constr = {cbox, cbnd, ceq, link};&lt;br /&gt;
solution = ezsolve(objective, constr, x0, options);&lt;br /&gt;
&lt;br /&gt;
t = subs(collocate(p1,t1),solution);&lt;br /&gt;
t = [t;subs(collocate(p2,t2),solution)];&lt;br /&gt;
t = [t;subs(collocate(p3,t3),solution)];&lt;br /&gt;
x1 = subs(collocate(p1,x1p1),solution);&lt;br /&gt;
x1 = [x1;subs(collocate(p2,x1p2),solution)];&lt;br /&gt;
x1 = [x1;subs(collocate(p3,x1p3),solution)];&lt;br /&gt;
x2 = subs(collocate(p1,x2p1),solution);&lt;br /&gt;
x2 = [x2;subs(collocate(p2,x2p2),solution)];&lt;br /&gt;
x2 = [x2;subs(collocate(p3,x2p3),solution)];&lt;br /&gt;
x3 = subs(collocate(p1,x3p1),solution);&lt;br /&gt;
x3 = [x3;subs(collocate(p2,x3p2),solution)];&lt;br /&gt;
x3 = [x3;subs(collocate(p3,x3p3),solution)];&lt;br /&gt;
u = subs(collocate(p1,up1),solution);&lt;br /&gt;
u = [u;subs(collocate(p2,up2),solution)];&lt;br /&gt;
u = [u;subs(collocate(p3,up3),solution)];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Problem type appears to be: lpcon&lt;br /&gt;
Time for symbolic processing: 0.34745 seconds&lt;br /&gt;
Starting numeric solver&lt;br /&gt;
===== * * * =================================================================== * * *&lt;br /&gt;
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31&lt;br /&gt;
=====================================================================================&lt;br /&gt;
Problem: ---  1: Nondiff System                 f_k      58.065028469582899000&lt;br /&gt;
                                       sum(|constr|)      0.000030760924864613&lt;br /&gt;
                              f(x_k) + sum(|constr|)     58.065059230507764000&lt;br /&gt;
                                              f(x_0)      0.000000000000000000&lt;br /&gt;
&lt;br /&gt;
Solver: snopt.  EXIT=0.  INFORM=1.&lt;br /&gt;
SNOPT 7.2-5 NLP code&lt;br /&gt;
Optimality conditions satisfied&lt;br /&gt;
&lt;br /&gt;
FuncEv    1 ConstrEv   45 ConJacEv   45 Iter   38 MinorIter 1056&lt;br /&gt;
CPU time: 0.530403 sec. Elapsed time: 0.534000 sec. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot result==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
subplot(2,1,1)&lt;br /&gt;
plot(t,x1,&#039;*-&#039;,t,x2,&#039;*-&#039;,t,x3,&#039;*-&#039;);&lt;br /&gt;
legend(&#039;x1&#039;,&#039;x2&#039;,&#039;x3&#039;);&lt;br /&gt;
title(&#039;Nondiff System state variable&#039;);&lt;br /&gt;
&lt;br /&gt;
subplot(2,1,2)&lt;br /&gt;
plot(t,u,&#039;+-&#039;);&lt;br /&gt;
legend(&#039;u&#039;);&lt;br /&gt;
title(&#039;Nondiff System control&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:nondiffSystem_01.png]]&lt;/div&gt;</summary>
		<author><name>Mbot</name></author>
	</entry>
</feed>