## Problem description

Time-optimal positioning of a radio telescope with bounded control.

Programmers: Gerard Van Willigenburg (Wageningen University) Willem De Koning (retired from Delft University of Technology)

```% Copyright (c) 2009-2009 by Tomlab Optimization Inc.
```

## Problem setup

```% Array with consecutive number of collocation points
narr = [20 40];

% Free final time
toms t tf

for n=narr
```
```    p = tomPhase('p', t, 0, tf, n);
setPhase(p)

tomStates x1 x2 x3
tomControls u1

% Initial & terminal states
xi = [0; 0; 0];
xf = [1; 0; 0];

% Initial guess
if n==narr(1)
x0 = {tf == 5; icollocate({x1 == xi(1); x2 == xi(2)
x3 == xi(3)})
collocate({u1 == 0})};
else
x0 = {tf == tfopt; icollocate({x1 == xopt1; x2 == xopt2
x3 == xopt3})
collocate({u1 == uopt1})};
end

% Box constraints
cbox = {-1 <= collocate(u1) <= 1};

% Boundary constraints
cbnd = {initial({x1 == xi(1); x2 == xi(2); x3 == xi(3)})
final({x1 == xf(1); x2 == xf(2); x3 == xf(3)})};

% ODEs and path constraints
dx1 = x2;
dx2 = -0.5*x2-0.1*x2./sqrt(x2.*x2+1e-4)+x3;
dx3 = -2*x3+2*u1;

ceq = collocate({
dot(x1) == dx1
dot(x2) == dx2
dot(x3) == dx3});

% Objective
objective = tf;
```

## Solve the problem

```    options = struct;
options.name = 'Radio telescope';
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);

tfopt = subs(tf,solution);
xopt1 = subs(x1,solution);
xopt2 = subs(x2,solution);
xopt3 = subs(x3,solution);
uopt1 = subs(u1,solution);
```
```Problem type appears to be: lpcon
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2010-02-05
=====================================================================================
Problem: ---  1: Radio telescope                f_k       2.866900604245533400
sum(|constr|)      0.000000000314086783
f(x_k) + sum(|constr|)      2.866900604559620400
f(x_0)      5.000000000000000000

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

FuncEv    1 ConstrEv   43 ConJacEv   43 Iter   20 MinorIter  165
CPU time: 0.093750 sec. Elapsed time: 0.094000 sec.
```
```Problem type appears to be: lpcon
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2010-02-05
=====================================================================================
Problem: ---  1: Radio telescope                f_k       2.859991999288976800
sum(|constr|)      0.000002602280629781
f(x_k) + sum(|constr|)      2.859994601569606500
f(x_0)      2.866900604245533400

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

FuncEv    1 ConstrEv    5 ConJacEv    5 Iter    4 MinorIter  134
CPU time: 0.062500 sec. Elapsed time: 0.062000 sec.
```
```end

figure(1)
subplot(2,1,1);
ezplot([x1; x2; x3]); legend('x1','x2','x3'); 