Você está na página 1de 18

EE5321-Spring 2016

Homework 4: Free Final Time Optimal Control Due Mar 31


By
Mohammad Saifullah Shaikh
(1001107267)

Soln:Cost Value is 0.7707

Matlab Code:Main file


% EE 5231-OPtimal Control
% HW 4-Problem #1
clc;
clear all;
%% Creating time Vector
t=[0:0.01:1]';
%% Creating Input Vector
CL=-0.1*ones(length(t),1);
%% Final time
tfinal=42/100;
CL(end+1)=tfinal;
%% Lower and upper bound Values for Fmincon
lb = ones(length(t),1)*(-pi);
ub = ones(length(t),1)*(pi);
lb(end+1)=0.01;
ub(end+1)=42;
%% For displaying iteration and Optimiztion Plot
options = optimset('Display','iter','TolCon',1e4,'Algorithm','activeset','PlotFcns','optimplotx','MaxfunEvals',4000);
%% The FMINCON function
[CL_final, cost] = fmincon('hw4_cost',
CL,[],[],[],[],lb,ub,'hw4_constraint',options);
%% Sending Input Values to Simulink which were Calculated by
Fmincon
tfinal=CL_final(end);
[tf,yf]=sim('hw4_simulink',t,[],[t CL_final(1:end-1)]);
%% Plotting
figure
plot(yf(:,1)/6074,yf(:,2),'linewidth',2.5);
grid on;
xlabel('\bfX.(nm)');ylabel('h.(ft)');
title('\bfX v/s h');
%% Control
figure;
plot(t*CL_final(end)*100,CL_final(1:end-1),'linewidth',2.5);
grid on;
xlabel('\bfTime.(sec)'),ylabel('\bfCL');
title('\bfCL');
%% velocity
figure
plot(t*CL_final(end)*100,yf(:,4),'linewidth',2.5);
grid on

xlabel('\bfTime.(sec)');ylabel('\bfVelocity.(ft/sec)');
title('\bfVelocity');
%% Gamma
figure
plot(t*CL_final(end)*100,yf(:,3),'linewidth',2.5);
grid on
xlabel('\bfTime.(sec)');ylabel('\bfGamma.(degree)');
title('\bfGamma');
Cost function
function cost = hw4_cost(p)
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
cost=(0.0-yout(end,4))/11000;
end

Constraints:function[cineq, ceq] = hw4_constraint(p)


%% inequailty function
cineq=[];
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
%% Constraints
ceq(1)=(yout(end,1)-437480)/500000;
ceq(2)=yout(end,2)/100000;
end

Graphs:-

Conclusion:-CL is being optimized keeping Max velocity as the performance index, and hence
the max velocity at the target is achieved as 8498 ft/sec and all the constraints also have been
satisfied.

b) Determine the optimal control to minimize the performance index =. Plot height versus distance,
velocity as a function of time, and the flight path angle as a function of time. Also plot the control
versus time. (40 points).
Soln:-

Cost Value is 0.4393


Matlab Code:Main file
**Same As Problem 1.a)
Cost function
function cost = hw4_cost(p)
assignin('base','tfinal',p(end));

%% Creating time Vector


t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
cost=p(end);
end
Constraints:**Same as Problem 1.a)

Graphs:-

Conclusion:- -CL is being optimized keeping Min time as the performance index, and hence
the min time at the target is achieved which is 43.93 sec and all the constraints also have
been meet.
c) Compare the final velocity and final time determined in parts a) and b). (10 points) .
Soln:-

Matlab Code:Main file


% EE 5231-OPtimal Control
% HW 4-Problem #1
clc;
clear all;
%% Creating time Vector
t=[0:0.01:1]';
%% Creating Input Vector
CL=-0.1*ones(length(t),1);
%% Final time
tfinal=42/100;
CL(end+1)=tfinal;
%% Lower and upper bound Values for Fmincon
lb = ones(length(t),1)*(-pi);
ub = ones(length(t),1)*(pi);
lb(end+1)=0.01;
ub(end+1)=42;
%% For displaying iteration and Optimiztion Plot
options = optimset('Display','iter','TolCon',1e4,'Algorithm','activeset','PlotFcns','optimplotx','MaxfunEvals',4000);
%% The FMINCON function
[CL_final, cost] = fmincon('hw4_cost',
CL,[],[],[],[],lb,ub,'hw4_constraint',options);
%% Sending Input Values to Simulink which were Calculated by
Fmincon
tfinal=CL_final(end);
[tf,yf]=sim('hw4_simulink',t,[],[t CL_final(1:end-1)]);
%% Plotting
figure
plot(yf(:,1)/6074,yf(:,2),'linewidth',2.5);
grid on;
xlabel('\bfX.(nm)');ylabel('h.(ft)');
title('\bfX v/s h');

%% Control
figure;
plot(t*CL_final(end)*100,CL_final(1:end-1),'linewidth',2.5);
grid on;
xlabel('\bfTime.(sec)'),ylabel('\bfCL');
title('\bfCL');
%% velocity
figure
plot(t*CL_final(end)*100,yf(:,4),'linewidth',2.5);
grid on
xlabel('\bfTime.(sec)');ylabel('\bfVelocity.(ft/sec)');
title('\bfVelocity');
%% Gamma
figure
plot(t*CL_final(end)*100,yf(:,3),'linewidth',2.5);
grid on
xlabel('\bfTime.(sec)');ylabel('\bfGamma.(degree)');
title('\bfGamma');
%%%%%%%%%%%%%%%%%% The Second Fmincon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The FMINCON function
[CL_finalt, cost1] = fmincon('hw4_costt',
CL,[],[],[],[],lb,ub,'hw4_constraint',options);
%% Sending Input Values to Simulink which were Calculated by
Fmincon
tfinal=CL_finalt(end);
[tf,yft]=sim('hw4_simulink',t,[],[t CL_finalt(1:end-1)]);
%% Plotting
figure
plot(yft(:,1)/6074,yft(:,2),'linewidth',2.5);
grid on;
xlabel('\bfX.(nm)');ylabel('h.(ft)');
title('\bfX v/s h');
%% Control
figure;
plot(t*CL_finalt(end)*100,CL_finalt(1:end-1),'linewidth',2.5);
grid on;
xlabel('\bfTime.(sec)'),ylabel('\bfCL');
title('\bfCL');
%% velocity
figure
plot(t*CL_finalt(end)*100,yft(:,4),'linewidth',2.5);
grid on
xlabel('\bfTime.(sec)');ylabel('\bfVelocity.(ft/sec)');
title('\bfVelocity');
%% Gamma
figure

plot(t*CL_finalt(end)*100,yft(:,3),'linewidth',2.5);
grid on
xlabel('\bfTime.(sec)');ylabel('\bfGamma.(degree)');
title('\bfGamma');
%%%%%%%% Plotting Together%%%%%%%%%%%%%%%%
figure
plot(t*CL_finalt(end)*100,yft(:,4),'k','linewidth',2.5);
grid on
hold on
plot(t*CL_final(end)*100,yf(:,4),'r','linewidth',2.5);
xlabel('\bfTime.(sec)');ylabel('\bfVelocity.(ft/sec)');
title('\bfVelocity');
legend('\bfTime As Performance index','\bfVelocity As
Performance index')
a.Cost function(time as performance index)
function cost = hw4_cost(p)
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
cost=p(end);
end
b.Cost function(velocity as performance index)
function cost = hw4_cost(p)
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
cost=(0.0-yout(end,4))/11000;
end
Constraints:**Same As Problem 1.a)

Graphs:-

Conclusion:-In the Above diagram the velocity and time histories of part a) and part b) is
being compared, the following final velocity and time is obtained i.e.
Time as Performance index
Velocity as performance index

Velocity(ft/sec)
8446
8498

Time(sec)
43.94
44.01

So it is clearly visible from the graph and table that when the time is the performance index,
minimum time is being achieved and for velocity as performance index max velocity is
achieved.

d) Finally, check if the scale factors on the cost and constraints are really necessary by removing them
from your scripts and repeat the optimization where you maximize the performance index and hit the
target with maximum final velocity. Run that optimization again and show and discuss your results,
showing how well it did or didnt work and indicating if the scale factors were really necessary in this
case. (10 points)
Soln:-

Cost function is 9.4808e3


Matlab Code:Main file
Same as Problem 1a)
a.Cost function(with Scaling)
Same as Problem 1a)
b.Cost function(with Scaling)
function costd = hw4_costd(p)
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
costd=0.0-(yout(end,4));
a.Constraints(With Scaling):Same as Problem 1a)
b.Constraints(Without Scaling):function[cineq, ceq] = hw4_constraintd(p)
%% inequailty function
cineq=[];
assignin('base','tfinal',p(end));
%% Creating time Vector
t=[0:0.01:1]';
u=[p(1:end-1)];
% Sending Input Values to Simulink
[tout,yout] = sim('hw4_simulink',t,[],[t u]);
%% Constraints
ceq(1)=(yout(end,1)-437480);
ceq(2)=yout(end,2);
end

Graphs:-

Conclusion:-The Scaling Factors does make a big difference, it is being concluded after
comparing all the time histories of CL, Velocity. The graphs when there is no scaling are very
distorted as compared to with scaling ones, due to which it become more difficult to interpret
results.
Hence its my observation and conclusion that scaling plays a vital role in determining the
final results and hence it should be done.

Você também pode gostar