loop to calculate time using previous values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone!
Could you please help me with a code.
I have a loop and calculated time, so the values of time are the increments between the current and previous values. So how to generate the loop for the time where the previous ones can be added. For example, my first t values are 60.6664, 60.9712, 61.2792, 61.5902, 61.9045........ In the result of new time will be 60.9712, (60.9712+61.2792), (60.9712+61.2792+61.5902)......
W_takeoff = 10000;
W_landing=6000;
S = 20;
AR = 5;
cd0 = 0.02;
k = 1/pi/AR;
RC=0.51;
clalpha = 2*pi;
amin=2;
astall=12;
rho=1;
ct=0.001;
alpha_max=2.95;
cl_max=clalpha*alpha_max*pi/180;
cd_max = cd0 + k * cl_max * cl_max;
delta_w=50;
j=0;
for w=W_takeoff:-delta_w:W_landing
j=j+1;
V(j) = sqrt(2*w/rho/S/cl_max);
D(j) = 0.5 * rho * V(j) * V(j) * S * cd_max;
Thrust(j)=D(j); %for steady level flight condition
F(j)=ct*Thrust(j); %fuel consumption
Weight(j)=w;
t(j)=delta_w/F(j);
R(j)=V(j)*t(j);
end
0 commentaires
Réponses (1)
Dyuman Joshi
le 31 Mar 2023
Modifié(e) : Dyuman Joshi
le 31 Mar 2023
You can vectorize the loop -
W_takeoff = 10000;
W_landing = 6000;
S = 20;
AR = 5;
cd0 = 0.02;
k = 1/pi/AR;
RC=0.51;
clalpha = 2*pi;
amin=2;
astall=12;
rho=1;
ct=0.001;
alpha_max=2.95;
cl_max=clalpha*alpha_max*pi/180;
cd_max = cd0 + k * cl_max * cl_max;
delta_w=50;
j=0;
w=W_takeoff:-delta_w:W_landing;
V = (2*w/rho/S/cl_max).^(1/2);
D = 0.5*rho*V.^2*S*cd_max;
Thrust = D;
F = ct*Thrust;
Weight = w;
t = delta_w./F
R = V.*t;
%new time
T = cumsum(t)
2 commentaires
Dyuman Joshi
le 31 Mar 2023
Modifié(e) : Dyuman Joshi
le 4 Avr 2023
Apologies, @Alina Abdikadyr, there was a mistake in the formula of V which has been rectified. Please check my answer again.
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!