Matlab is skipping over my while loop.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to calculate the thurst, velocity, and displacement of an aircraft approaching takeoff. Matlab is skipping over my while loop and I do not know why. If i take the loop away there are no errors and will give me the answer "0" since that is what it would be with no iterations. If you could please help it would be greatly appreciated.
Code:
%Question 2
clc, clear
%Constants
b=36;
Sw=175;
Hw=5.7;
AR=b^2/Sw;
e=2/((2-AR)+sqrt(4+AR^2));
AReff=AR*sqrt(b/(2*5.7));
CDG=(.65*4)^2/(3.14*e*AReff);
%Part A
CD=CDG+.02+.018
%Part B
T0=765;
rho=.002377;
Wto=3500;
Pmax=270;
g=32.2;
muroll=.023;
Dprop=84/12;
Clmax=4;
CLG=.65*Clmax;
deltat=.01;
Tguess=700;
Vcr=110;
Vstall=64.8;
V=1.2*Vstall;
n=1;
t(n)=0;
x(n)=0;
V(n)=0;
a(n)=0;
T=Groundroll(T0,V);
T(n)=T;
while V(n)<V
n=n+1;
T(n)=Groundroll(T0,V(n));
t(n)=t(n-1)+deltat;
V(n)=V(n-1)+a(n-1)*deltat;
q(n)=.5*V(n)^2*rho;
Daero(n)=CDG*q(n)*Sw;
L(n)=CLG*q(n)*Sw;
Droll(n)=muroll*(Wto-L(n));
Fx(n)=T(n)-Daero(n)-Droll(n);
a(n)=g*(Fx(n)/Wto);
x(n)=x(n-1)+.5*(V(n)+V(n-1))*deltat;
x=x(n)
V=V(n)
end
0 commentaires
Réponses (1)
Stephen23
le 15 Fév 2020
"Matlab is skipping over my while loop and I do not know why."
Because you told it to.
Lets have a look at what values V and n have before the loop runs:
>> V
V = 0
>> n
n = 1
Now lets look at your loop condition... But first, is zero less than zero? (hint: no). We can check that using MATLAB too:
>> V(n)<V
ans = 0
Ergo your condition is not true, and the loop never runs. Because that is exactly what you told MATLAB to do.
0 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!