Escolar Documentos
Profissional Documentos
Cultura Documentos
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
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:-
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:-
%% 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:-
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.