# LQR Problem

Problem: LQR: RIOTS 95 Manual

## Problem Description

Find u(t) over t in [0; 1 ] to minimize subject to:  % Copyright (c) 2007-2008 by Tomlab Optimization Inc.


## 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);


## 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
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2010-02-05
=====================================================================================
Problem:  1: LQR Problem                        f_k       0.380797077977481140
sum(|constr|)      0.000000000041289582
f(x_k) + sum(|constr|)      0.380797078018770720
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.015000 sec.


## 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'); 