Figure 1: Trajectories for Example 1 (a)
For case (b), we substitute t
0
= 0, t
f
= 2 in the the general solution
to get a set of 4 algebraic equations with 4 arbitrary coefficients. Then
the four boundary conditions are supplied to determine these coefficients.
sol_b is a structure consists of four coefficients returned by solve. We get
the final symbolic solution to the ODE’s by substituting these coefficients
into the general solution. Figure 2 shows the results of both solutions from
MATLAB and [2].
It should be noted that we cannot get the solution by directly supplying
the boundary conditions with dsolve as we did in case (a). Because the
latter two boundary conditions: p
∗
1
(2) = x
∗
1
(t) − 5, p
∗
2
(2) = x
∗
2
(t) − 2 replaces
costates p
1
, p
2
with states x
1
, x
2
in the ODE’s which resulted in more ODE’s
than variables.
% case b: (a) x1(0)=x2(0)=0; p1(2) = x1(2) - 5; p2(2) = x2(2) -2;
eq1b = char(subs(sol_h.x1,’t’,0));
eq2b = char(subs(sol_h.x2,’t’,0));
eq3b = strcat(char(subs(sol_h.p1,’t’,2)),...
’=’,char(subs(sol_h.x1,’t’,2)),’-5’);
eq4b = strcat(char(subs(sol_h.p2,’t’,2)),...
’=’,char(subs(sol_h.x2,’t’,2)),’-2’);
sol_b = solve(eq1b,eq2b,eq3b,eq4b);
5