Homework #3: As An Activity On The Course of
Homework #3: As An Activity On The Course of
Submitted by
ADALBERTO PEREZ
Code for Problem 3
The codes that suffered modifications have been annexed in this document.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Computer exercise in: %
% %
% 5B1872 Optimal Control %
% %
% Main file (main.m) %
% %
% Solves the optimal orbit transfer problem %
% with embedded shooting (Newton's method).' %
% %
% Matlab5 recommended (not tried for an older version) %
% %
% This problem is taken from the book: %
% Applied Optimal Control %
% Arthur E. Bryson and Yu-Chi Ho %
% Hemisphere Publishing Corporation, 1975 %
% %
% and is made into a computer exercise by %
% Henrik Rehbinder & Petter Ögren %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear, clc
global c1 c2 c3 ti x0 tf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Problem specific constants %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c1=0.1405;
c2=0.533;
c3=3.32;
ti = 0;
tf = 1;
x0 = [1;0;1];
% A starting guess
% (Consider what lambda_0 that are plausible.)
%
%
% Number of embeddings
%
N = 5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Use embedding to solve a set of equations %
% with good starting guesses instead of one %
% with a bad guess. %
% %
% %
% (after termination the optimal cost %
% can be derived from the z vector) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m_0=theta(lambda_0)
%return
lambda_k=lambda_0;
for k=1:N
iteration=k
m_k=(1-k/N).*m_0
lambda_k=newton_solver('theta',m_k,lambda_k);
th=theta(lambda_k)
l_k=lambda_k
[t,z] = ode45('fh',[ti tf],[x0;lambda_k]);
plotresults(t,z), hold on , drawnow
end
figure(2)
plotresults(t,z)
function xplp=fh(t,x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function xplp=fh(t,x)
% Right hand side to the differential equations governing
% the optimal orbit transfer in the omputer exercise for the
% course Optimal Control 5B1872
%
% x = x(1:3)
% lambda = x(4:6)
global c1 c2 c3
x1=x(1);
x2=x(2);
x3=x(3);
l1=x(4); %lambda1
l2=x(5); %lambda2
l3=x(6); %lambda3
global c1 c2 c3 %constants
nrm = sqrt(l2^2+(c3*l3)^2);
if nrm ~= 0
sinu=-l2/nrm;
cosu=-c3*l3/nrm;
else
sinu = 0;
cosu = 1;
end