I just wrote the code from the book of Stevens & Lewis, Aircraft
Control and Simulation, from chapter 3 of transport aircraft.
Now I have written the code as it is. The first one is cost.m which
calls another function of aircraft 3dof model:
% Cost Function for 3 DOF Aircraft
% The model has been take from Stvens & Lewis, Aircraft Control and
% Simulation, Chapter 3
function [f] = cost(s0)
global x u gamma
u(1) = s0(1);
u(2) = s0(2);
x(2) = s0(3);
x(3) = xu(2) + gamma;
x(4)=0;
time = 0.0;
[xd]= LASS3dof(time,xu,uu);
f = xd(1)^2 + 100*xd(2)^2 + 10*xd(4)^2;
The second is trim.m, which trims the aircraft using fminsearch and
passing the value in cost:
%Trim.m
% The model has been take from Stvens & Lewis, Aircraft Control and
% Simulation, Chapter 3
clear all
global x u gamma
x(1)= input('Enter Vt : ');
x(5) = input('Enter Height:');
gamma = input('Enter Gamma(deg.):')/57.29578;
name = input ('Name of Cost Function file? :','s');
u = [0.1 -10];
x(2) = 0.1; %initial guess, alpha
x(3) = x(2) +gamma;
x(4) = 0;
s0 = [u(1) u(2) x(2)];
%Now Initialize other states and get initial cost
disp(['Initial cost=',num2str(feval(cost,s0))])
[s,fval] = fminsearch(cost,s0);
x(2)=s(3);
x(3)=s(3)+gamma;
u(1)=s(1);
u(2)=s(2);
disp(['minimum cost =',num2str(fval)])
disp(['minimizing vector = ',num2str(s)])
temp = [lenght(x), lenght(u), c,u];
name = input('Name of output file?:','s');
dlmwrite (name,temp);
When you run the code trim.m name of cost function file which has to
be given by user, please type cost.
Now when I run the code trim.m above it gives error at:
Error in ==> cost at 6
u(1) = s0(1);
Error in ==> trim at 16
disp(['Initial cost =',num2str(feval(cost,s0))])
Its giving error in cost function.
If I just comment this statement dis(...) in trim, it gives the same
error that s0 is undefined in cost when I am using fminsearch in the
next line.
Basically, when I am using fminsearch(cost,s0), I assume cost take s0
as its starting point and inside cost (s0 should be defined which is
not the case here. What way shall I pass, I tried using Optimset and
options but the same error continues. Can anyone help me out there.
Can anyone tell whats wrong with the code.