Code about paper airplane simulation cannot be run
Mostra commenti meno recenti
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 Commenti
Steven Lord
il 20 Dic 2019
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
il 21 Dic 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
.png)
