## 119  Turbo Generator

OCCAL - A Mixed symbolic-numeric Optimal Control CALcluator

Section 4 Example 1

### 119.1  Problem Formulation

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

J =
 t 0
(alpha1*( (x1x1s)2 + (x4x4s)2) +
 alpha2*x22 + alpha3*(x3−x3s)2 +
 beta1*(u1−u1s)2 + beta2*(u2−u2s)2 ) dt

subject to:

 dx1 dt
= x2*x4
 dx2 dt
=
 1 M
 dx3 dt
= u2A*x3+c*x4
 dx4 dt
= −x1*x2

The initial condition are:

 x(0)  = [x1s  x2s  x3s  x4s]
 x1:4s = [0.60295  0.0  1.87243  0.79778]
 alpha = [2.5  1.0  0.1]
 beta = [1.0  1.0]
 M = 0.04225
 s4:5 = [0.0  0.0]
 c = 0
 A = 0.17
 u1:2s = [0.80  0.73962]

Reference: [28]

### 119.2  Problem setup

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

tomStates x1 x2 x3 x4
tomControls u1 u2

% Initial guess
x0i = [0.60295;0;1.87243;0.79778];
x0 = {icollocate({x1 == x0i(1); x2 == x0i(2)
x3 == x0i(3); x4 == x0i(4)})
collocate({u1 == 0; u2 == 0})};

% Boundary constraints
cbnd = initial({x1 == x0i(1); x2 == x0i(2)
x3 == x0i(3); x4 == x0i(4)});

% ODEs and path constraints
u1s     = 0.80;    u2s     = 0.73962;
A       = 0.17;    c       = 0;
s4      = 0;       s5      = 0;
M       = 0.04225; alpha1  = 2.5;
alpha2  = 1.0;     alpha3  = 0.1;
beta1   = 1.0;     beta2   = 1.0;
kappa_d = 0.02535;

ceq = collocate({dot(x1) == x2.*x4
dot(x2) == 1/M.*(u1-s4*x1.*x4-s5*x1.*x3-kappa_d*x2)
dot(x3) == u2-A*x3+c*x4; dot(x4) == -x1.*x2});

% Objective
objective = integrate(alpha1*( (x1-x0i(1)).^2 +  ...
(x4-x0i(4)).^2) + alpha2*x2.^2 + alpha3*(x3-x0i(3)).^2 + ...
beta1*(u1-u1s).^2 + beta2*(u2-u2s).^2);
```

### 119.3  Solve the problem

```options = struct;
options.name = 'Turbo Generator';
solution = ezsolve(objective, {cbnd, ceq}, x0, options);
t  = subs(collocate(t),solution);
x1 = subs(collocate(x1),solution);
x2 = subs(collocate(x2),solution);
x3 = subs(collocate(x3),solution);
x4 = subs(collocate(x4),solution);
u1 = subs(collocate(u1),solution);
u2 = subs(collocate(u2),solution);
```
```Problem type appears to be: qpcon
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2011-02-05
=====================================================================================
Problem: ---  1: Turbo Generator                f_k      15.019841547670836000
sum(|constr|)      0.000000000046598417
f(x_k) + sum(|constr|)     15.019841547717435000
f(x_0)    -57.012069754799995000

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

FuncEv    1 ConstrEv   35 ConJacEv   35 Iter   23 MinorIter  117
CPU time: 0.125000 sec. Elapsed time: 0.141000 sec.
```

### 119.4  Plot result

```subplot(2,1,1)
plot(t,x1,'*-',t,x2,'*-',t,x3,'*-',t,x4,'*-');
legend('x1','x2','x3','x4');
title('Turbo Generator state variables');

subplot(2,1,2)
plot(t,u1,'+-',t,u2,'+-');
legend('u1','u2');
title('Turbo Generator control');
```