-
Notifications
You must be signed in to change notification settings - Fork 16
/
BrysonDenham_Solution_Control.m
53 lines (50 loc) · 1.92 KB
/
BrysonDenham_Solution_Control.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%--------------------------------------------------------------------------
% BrysonDenham_Solution_Control.m
% Calculates the optimal control for the Bryson-Denham problem
%--------------------------------------------------------------------------
% Valid when 0 < l <= 1/6
% See pages 120–123 of A. E. Bryson and Y.-C. Ho, Applied Optimal Control,
% revised printing ed. Taylor & Francis, 1975.
%--------------------------------------------------------------------------
% Primary Contributor: Daniel R. Herber, Graduate Student, University of
% Illinois at Urbana-Champaign
% https://github.com/danielrherber/optimal-control-direct-method-examples
%--------------------------------------------------------------------------
function U = BrysonDenham_Solution_Control(t,l)
U = zeros(length(t),1);
%----------------------------------------------------------------------
if (l > 0) && (l <= 1/6)
for i = 1:length(t)
if (t(i) <= 3*l)
u = -2/(3*l)*(1-t(i)/(3*l));
elseif (t(i) >= 1-3*l)
u = -2/(3*l)*(1 - (1-t(i))/(3*l));
else
u = 0;
end
% create the control matrix
U(i,:) = u;
end
%----------------------------------------------------------------------
elseif (l >= 1/6) && (l <= 1/4)
for i = 1:length(t)
if (t(i) <= 1/2)
u = -8*(1-3*l) + 24*(1-4*l)*t(i);
else
u = -8*(1-3*l) + 24*(1-4*l)*(1-t(i));
end
% create the control matrix
U(i,:) = u;
end
%----------------------------------------------------------------------
elseif (l >= 1/4)
for i = 1:length(t)
u = -2;
% create the control matrix
U(i,:) = u;
end
%----------------------------------------------------------------------
else
U = nan(length(t),1);
end
end