## 61  LQR Problem

Problem: LQR: RIOTS 95 Manual

### 61.1  Problem Description

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

J =
 1 0
(0.625*x2 + 0.5*x*u +0.5*u2dt

subject to:

 dx dt
=
 1 2
*x + u
 x(0) = 1

Reference: [29]

### 61.2  Problem setup

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

tomStates x
tomControls u

% Initial guess
x0 = icollocate(x == 1-t);

% ODEs and constraints
ceq = {collocate(dot(x) == 0.5*x+u)
initial(x == 1)};

% Objective
objective = integrate(0.625*x.^2+0.5*x.*u+0.5*u.^2);
```

### 61.3  Solve the problem

```options = struct;
options.name = 'LQR Problem';
solution = ezsolve(objective, ceq, x0, options);
t = subs(collocate(t),solution);
x = subs(collocate(x),solution);
u = subs(collocate(u),solution);
```
```Problem type appears to be: qp
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2011-02-05
=====================================================================================
Problem:  1: LQR Problem                        f_k       0.380797077977577230
sum(|constr|)      0.000000000046131558
f(x_k) + sum(|constr|)      0.380797078023708770
f(x_0)      0.000000000000000000

Solver: CPLEX.  EXIT=0.  INFORM=1.
CPLEX Barrier QP solver
Optimal solution found

FuncEv    3 GradEv    3 ConstrEv    3 Iter    3
CPU time: 0.015625 sec. Elapsed time: 0.016000 sec.
```

### 61.4  Plot result

```subplot(2,1,1)
plot(t,x,'*-');
legend('x');
title('LQR Problem state variable');

subplot(2,1,2)
plot(t,u,'+-');
legend('u');
title('LQR Problem control');
```