NAIDU CAP 2
NAIDU CAP 2
The Hamiltonian is H(x; u; ¸) = 12 u2 +¸> (Ax+Bu). The Euler-Lagrange conditions for an extremal become
where, H is the Hamiltonian matrix and ? denotes unspeci¯ed terms. This is a TPBVP and its solution
can be obtained through the state transition matrix (STM) that describes solutions of the state-costate
equations. That is, letting w = (x; ¸), we have w_ = Hw and, therefore,
Next, partition ©(5) according to the state-costate vectors and solve for the unknown initial conditions ¸(0).
We have that x(5) = ©11 (5)x(0) + ©12 (5)¸(0), from which
μ ¶μ ¶ μ ¶
¡1 ¡1 ¡0:096 ¡0:24 2 0:672
¸(0) = ©12 (5)x(5) ¡ ©12 (5)©11 (5)x(0) = ¡ =
¡0:24 ¡0:8 2 2:08
t=[0:.01:5]';
H=[A -B*B';0*B*B' -A'];
p=expm(H*5);p11 = p(1:2,1:2);p12 = p(1:2,3:4);
1
S=ss(A,B,eye(2,2),zeros(2,1));
x0=[2;2;-(p12\p11)*[2;2]]
Sa=ss(-A',B,eye(2,2),zeros(2,1));
L=lsim(Sa,0*t,t,x0(3:4));plot(t,L),pause
u=-L*B; % lsim output: L rows are the costate transpose at each time instant
x=lsim(S,u,t,x0(1:2));
plot(t,x,t,u)
Not surprisingly, (the costate system is the homogeneous solution of a double integrator) the optimal
input is an a±ne function of time (straight line).
Alternatively, one can take advantage of the speci¯c form of equations to ¯nd the explicit solution:
¸1 (t) = c3 , ¸2 (t) = ¡c3 t + c4 , u(t) = ¡¸2 (t), etc., x2 (t) = ¢ ¢ ¢, x1 (t) = ¢ ¢ ¢. Then, the constants ci are found
by solving the four-equation, four-unknown linear system.
2
The minimum JT = x> (0)P (0)x(0). Letting F = ½I, ½ ! 1 we approximate the problem of the ¯xed
¯nal state x(T ) = 0.
The optimal cost depends both on T and F through the solution of the Riccati. Rewriting the Riccati
as a forward-in-time ODE, we get (using the same symbol P ) P_ = A> P + P A + Q ¡ P BR¡1 B > P ,
P (0) = F , for which the optimal solution is JT = x(0)> P (T )x(0) and u(t) = ¡R¡1 B > P (T ¡ t)x(t).
We can explore the behavior of JT by solving this ODE, for di®erent initial conditions F . In our case,
P_ = ¡2P + 1 ¡ P 2 , P (0) = F , for which the optimal solution is peasily computed in
p SIMULINK. The
steady state value is the positive root of 0 = ¡2P + 1 ¡ P 2 , i.e., 2 ¡ 1. For F > 2 ¡ 1 the solution
decays monotonically to the steady-state value. This implies that for any given F (large enough), the
minimum JT with respect to T will occur at in¯nity.
Thus, we conclude that the optimal control is the limiting solution for the in¯nite interval
tf= 1
p
P = 2¡1
u = ¡P x
p
and min J = x(0)> P x(0) = 25( 2 ¡ 1) = 10:355.
t=[0:.01:2]';
Q=[1 0;0 2];R=4;
H=[A -B*inv(R)*B';-Q -A'];
p=expm(H*2);p11 = p(1:2,1:2);p12 = p(1:2,3:4);
S=ss(A,B,eye(2,2),zeros(2,1));
3
x0=[1;2;p12\([4;6]-p11*[1;2])]
% x-lambda are coupled; produce u by solving the entire state-costate eqn.
Sh=ss(H,[B;B],[0*B' -inv(R)*B'],0);
u=lsim(Sh,0*t,t,x0);
x=lsim(S,u,t,x0(1:2)); % verify solution
plot(t,x,t,u)
Case 2: tf free, x(tf ) = [4; 6]. Here, the terminal cost (F; xf ) is again irrelevant. With the same setup
as in Case 1, we now have the additional condition H(tf ) = 0 = 12 x> Qx ¡ 12 ¸> BR¡1 B > ¸ + ¸> Axjt=tf =
44 ¡ 1:125¸22 (tf ) ¡ 8¸2 (tf ) + 6¸1 (tf ).
One procedure to solve this problem is to begin by ¯xing tf , evaluate the optimal solution, check the
above transversality condition at tf , and then adjust tf and repeat. Alternatively, we could also simply
solve the the ¯xed-time optimal control problem JT and minimize JT with respect to T . Performing the
evaluation, we ¯nd that the transversality condition is satsi¯ed at several times: 0.759, 2.098, 5.2495,...
These are points where the necessary conditions for extremals are satis¯ed. For identifying the minimum, we
need to evaluate the cost. Plotting JT as a function of T we indeed ¯nd several local minima and maxima
with the one at tf = 0:759 yielding the least cost, J0:759 = 31:53.
The following function is useful in performing the necessary computations:
function [ER,J]=p211(tf);
t=[0:.01:tf]';
A=[0 1;-2 0];B=[0;3];
xf=[4;6];x0=[1;2];
Q=[1 0;0 2];R=4;
H=[A -B*inv(R)*B';-Q -A'];
p=expm(H*tf);p11 = p(1:2,1:2);p12 = p(1:2,3:4);
xx0=[x0;p12\(xf-p11*x0)];
% x-lambda are coupled; produce u by solving the state-costate eqn.
Sh=ss(H,[B;B],[eye(4,4);0*B' -inv(R)*B'],zeros(5,1));
U=lsim(Sh,0*t,t,xx0);
u=U(:,5);Lf=U(length(U),3:4)';
ER=xf'*Q*xf/2-Lf'*B*inv(R)*B'*Lf/2+Lf'*A*xf;
S=ss(A,B,eye(2,2),zeros(2,1));
x=lsim(S,u,t,x0(1:2));
%plot(t,x,t,u);
J=(norm(x(:,1))^2+norm(x(:,2))^2*2+norm(u)^2*4)/2*.01;
£ ¤>
Case 3: tf = 2, x(tf ) = [?; 6], F = 0. Here, @S@x ¡ ¸ t=tf ±xf = 0 implying that ¸1 (tf ) = 0. Again, we
express the state-costate equations as w_ = Hw, where
0 1 0 1
μ ¶ 1 ?
A ¡BR¡1 B > B 2 C B 6 C
H= ; w(0) = B C B C
@ ? A ; w(2) = @ 0 A
¡Q ¡A>
? ?
The rest of the problem is completely analogous to Case 1, except that a di®erent partition of the state
transition matrix (rows 2-3) is needed to compute the unknown initial conditions for ¸(0).
Case 4: tf free, x(tf ) on [4; ¡5tf + 15], F = diag(3; 5), xf = [4; 6]. Now, the boundary conditions for
the state-costate equations w_ = Hw become
0 1 0 1
1 4
B 2 C B ¡5tf + 15 C
w(0) = B C
@ ? A ; w(2) = @
B C
? A
? ?
4
£ @S ¤>
and 0 = H(tf ) + @x ¡ ¸ t=t [0; ¡5] = H(tf ) + [F (x(tf ) ¡ xf ) ¡ ¸]>
t=tf [0; ¡5] = 0, yielding
f
This is a straightforward extension of Case 2, with the di®erence that the ¯nal states are functions of tf
instead of ¯xed constants. That presents no additional di±culty in the procedure outlined in Case 2.