Code about paper airplane simulation cannot be run

1 次查看(过去 30 天)
I am not that proficient in programming. The error occured on the line "function sdot = PaperHoriz(t,s)", and I am not sure how to solve this error. The name of this M file is "PaperHoriz.m".
%paper airplane simulation
global CL CD S m g rho
S = 0.017;
m = 0.003;
g = 9.81;
rho = 1.225;
CD = 0.04; %lift and drag coeff simply given
CL = 0.22; %for this flight regime
gamma0 = -atan(CD/CL); %-ve sign because decent angle
v0 = sqrt(2*m*g/(rho*S*sqrt(CL^2+CD^2))); %initial velocity for min descent angle
%various initial flight condition
H = 2;
R = 0;
t0 = 0;
tf = 6;
tspan = [t0 tf];
%a) trimmed flight case
%initial angle is min angle of descent
s0 = [H;R;v0;gamma0]; %state vector's initial state
[ta, sa] = ode23('PaperHoriz',tspan,s0);
%b) same initial velocity but release at horizontal angle
gamma0 = 0;
s0 = [H;R;v0;gamma0];
[tb, sb] = ode23('PaperHoriz',tspan,s0);
%c) release at horizontal angle, double min-descent speed
newv0 = 2*v0;
s0 = [H;R;newv0;gamma0];
[tc, sc] = ode45('PaperHoriz',tspan,s0);
%d) release at horizontal angle, triple min-descent speed
newv0 = 3*v0;
s0 = [H;R;newv0;gamma0];
[td, sd] = ode45('PaperHoriz',tspan,s0);
%plot all the results
plot(sa(:,2),sa(:,1),sb(:,2),sb(:,1),sc(:,2),sc(:,1),sd(:,2),sd(:,1))
grid on;
ylim([0 5]);
xlim([-0.5 18]);
%invoked file with dynamics in it called PaperHoriz.m
function sdot = PaperHoriz(t,s) %error occured in this line
global CL CD S m g rho
v = s(3);
gamma = s(4);
q = rho/2*v^2;
%state vector = [H;R;v;gamma]
sdot = [v*sin(gamma);v*cos(gamma);1/m*(-q*S*CD-m*g*sin(gamma));1/(m*v)*(q*S*CL-m*g*cos(gamma))];
end
  2 个评论
Steven Lord
Steven Lord 2019-12-20
What is the full and exact text of the error message you receive (all the text displayed in red and/or orange, exactly as it's displayed in the Command Window)?
Which release of MATLAB are you using?
Lau Pei Shan
Lau Pei Shan 2019-12-21
I am using R2019a version of matlab and this is the error I received.
79869318_506490076742227_3268526616845746176_n.jpg

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-12-21
The name of this M file is "PaperHoriz.m".
Name the file something else, like PaperHorizDriver.m .
When you have a script that defines a function, the script name cannot be the same as the name of the function you are defining.
  6 个评论
Lau Pei Shan
Lau Pei Shan 2019-12-24
My programme worked well finally. I am very thankful and appreciated with your guidances. Thank you so much!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by