Вы находитесь на странице: 1из 12

HOMEWORK #3

As an activity on the course of

SF2852 OPTIMAL CONTROL THEORY

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.)
%

lambda_0(:,1) = [-1 ;-1 ;-1 ];

%
% Number of embeddings
%

N = 5;

% Plot the result of the starting guess.


figure(1), clf
[t,z] = ode45('fh',[ti tf],[x0;lambda_0]);
plotresults(t,z), hold on , drawnow

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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

% Control - thrust angle


% Antiparallell to (l2, c3*l3)

nrm = sqrt(l2^2+(c3*l3)^2);
if nrm ~= 0
sinu=-l2/nrm;
cosu=-c3*l3/nrm;
else
sinu = 0;
cosu = 1;
end

% Fuel consumption -> Mass decreasing with time


mt=(1/c1-c2*c3*t);

% xplp: xDotLambdaDot vector


% WRITE STUFF BELOW:
xplp=[(c3^2)*x(2) ; % x1dot
((x(3)^2)/x(1))-1/(x(1)^2)+(sinu)/(1/c1-c2*c3*t); % x2dot
-(x(2)*x(3)*(c3^2))/(x(1))+(c3*cosu)/(1/c1-c2*c3*t) ; % x3dot
l2*(((x(3)^2)/(x(1)^2))-(2/(x(1)^3)))-
l3*((c3^2)*x(2)*x(3)/(x(1)^2)) ; % l1dot
-l1*(c3^2)+l3*((c3^2)*x(3))/(x(1)) ; % l2dot
-2*l2*x(3)/x(1)+l3*(c3^2)*x(2)/x(1)]; % l3dot

function theta = theta(lambda_0)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% function theta = theta(lambda_0) %
% %
% Solving 0 = theta(lambda_0) gives a %
% candidate to initial values for lambda. %
% %
% Integrates FH(T,X) to get Z. %
% Calculates THETA based on Z. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global ti tf x0

% Integrate the differential equations


[t,z] = ode45('fh',[ti tf],[x0;lambda_0]);
z = z(length(z),:);
theta = [z(2); % radial speed = 0
z(3)-1/(z(1)^(1/2)); % force balance
z(4)+1-z(6)*0.5*1/(z(1)^(3/2))]; % lambda(tf) condition

Published with MATLAB® R2019a

Вам также может понравиться