Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem in a 3DOF aircraft model from Stevens and Lewis

60 views
Skip to first unread message

vinsing

unread,
May 11, 2007, 11:15:41 AM5/11/07
to
Hi all
I am a newbie to MATLAB.

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.

vinsing

unread,
May 11, 2007, 3:09:04 PM5/11/07
to
I got the answer just had google search and got what I was looking
for in some older thread.

Dingjiang Zhou

unread,
Aug 3, 2012, 12:33:42 AM8/3/12
to
vinsing <vineet....@gmail.com> wrote in message <ef56...@webcrossing.raydaftYaTP>...

Dingjiang Zhou

unread,
Aug 3, 2012, 12:35:42 AM8/3/12
to
I found that the function "cost()" is predefined in matlab, also, in you cost.m, I found that, you wrote: x(3) = xu(2) + gamma;, but it is x(2) in the book instead of xu(2).
I would like to ask you, if you have done with this trim algorithm, I encountered some problem too, hope you can help me too.

vinsing <vineet....@gmail.com> wrote in message <ef56...@webcrossing.raydaftYaTP>...
0 new messages