Error "Not enough input arguments" error in Line 5

Im fairly new to Matlab and im trying to write a program that solve the 3 Degrees of Freedom Equations of Motion for an aircraft using ode23. I have the following equations
X=Ucos(Theta) (Calculates Horizontal Distance)
h=Usin(Theta) (Calculates Height)
U=(-D-mgsin(theta))/m (Calculates Speed)
theta=(-L-mgcos(theta))/(mU) (Calculates angle)
I have the following code.
Hi= 10; %Initial Height
Ui= 7.5; %Initial Speed
THi= -4; %Initial Theta
D= 10; % Drag
L= 15; % Lift
m= 40; %mass
g= 9.81; %Gravity
TSpan = [0 100]; %Time Range
[time,y] = ode23('EoM',TSpan,[0 Hi Ui THi]);
plot(time, y);
The EoM Function is
function v = EoM(D,L,m,g)
v= zeros(4,1);
v(1)=v(3)*cos(v(4)); % Distance Equation
v(2)=v(3)*sin(v(4)); % Height Equation
v(3)=(-D-(m*g*sin(v(4))))/(m); % Speed Equation
v(4)=(-L-(m*g*cos(v(4))))/(m*(v(3))); % Angle Equation
end
Im getting the following error
Not enough input arguments.
Error in EoM (line 5)
v(3)=(-D-(m*g*sin(v(4))))/(m);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in AeroEqOfMotion (line 9)
[time,y] = ode23('EoM',TSpan,[0 Hi Ui THi]);

 Akzeptierte Antwort

Torsten
Torsten am 10 Nov. 2015
Hi= 10; %Initial Height
Ui= 7.5; %Initial Speed
THi= -4; %Initial Theta
D= 10; % Drag
L= 15; % Lift
m= 40; %mass
g= 9.81; %Gravity
TSpan = [0 100]; %Time Range
[time,y] = ode23(@(t,y)EoM(t,y,D,L,m,g),TSpan,[0 Hi Ui THi]);
plot(time,y(:,1));
function dv = EoM(t,v,D,L,m,g)
dv= zeros(4,1);
dv(1)=v(3)*cos(v(4)); % Distance Equation
dv(2)=v(3)*sin(v(4)); % Height Equation
dv(3)=(-D-(m*g*sin(v(4))))/(m); % Speed Equation
dv(4)=(-L-(m*g*cos(v(4))))/(m*(v(3))); % Angle Equation
end
Best wishes
Torsten.

4 Kommentare

This worked, thanks very much.
MOSLI KARIM
MOSLI KARIM am 6 Nov. 2022
Bearbeitet: Torsten am 6 Nov. 2022
hello this my code
function mosli1
Hi= 10; %Initial Height
Ui= 7.5; %Initial Speed
THi= -4; %Initial Theta
D= 10; % Drag
L= 15; % Lift
m= 40; %mass
g= 9.81; %Gravity
% X=Ucos(Theta);% (Calculates Horizontal Distance)
% h=Usin(Theta);% (Calculates Height)
% U=(-D-mgsin(theta))/m ;%(Calculates Speed)
% theta=(-L-mgcos(theta))/(mU);% (Calculates angle)
% Hi= 10; %Initial Height
% Ui= 7.5; %Initial Speed
% THi= -4; %Initial Theta
% D= 10; % Drag
% L= 15; % Lift
% m= 40; %mass
% g= 9.81; %Gravity
TSpan = [0 ;100]; %Time Range
[t,v] = ode23(@EoM,TSpan,[0 ;Hi ;Ui ;THi]);
plot(t, v);
function dv= EoM(t,v )
dv= zeros(4,1);
dv(1)=v(3)*cos(v(4)); % Distance Equation
dv(2)=v(3)*sin(v(4)); % Height Equation
dv(3)=(-D-(m*g*sin(v(4))))/(m); % Speed Equation
dv(4)=(-L-(m*g*cos(v(4))))/(m*(v(3))); % Angle Equation
end
end
DGM
DGM am 6 Nov. 2022
@MOSLI KARIM What about it? Does it work? If not, how so? If it does work, what about it is different from what's been posted? If you're showing a working example, why include a bunch of unused lines?
MOSLI KARIM
MOSLI KARIM am 6 Nov. 2022
Bearbeitet: Torsten am 6 Nov. 2022
function mosli1
Hi= 10; %Initial Height
Ui= 7.5; %Initial Speed
THi= -4; %Initial Theta
D= 10; % Drag
L= 15; % Lift
m= 40; %mass
g= 9.81; %Gravity
TSpan = [0 ;100]; %Time Range
[t,v] = ode23(@EoM,TSpan,[0 ;Hi ;Ui ;THi]);
plot(t, v);
function dv= EoM(t,v )
dv= zeros(4,1);
dv(1)=v(3)*cos(v(4)); % Distance Equation
dv(2)=v(3)*sin(v(4)); % Height Equation
dv(3)=(-D-(m*g*sin(v(4))))/(m); % Speed Equation
dv(4)=(-L-(m*g*cos(v(4))))/(m*(v(3))); % Angle Equation
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by