Borrar filtros
Borrar filtros

loop to calculate time using previous values

1 visualización (últimos 30 días)
Alina Abdikadyr
Alina Abdikadyr el 31 de Mzo. de 2023
Editada: Dyuman Joshi el 4 de Abr. de 2023
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

Respuestas (1)

Dyuman Joshi
Dyuman Joshi el 31 de Mzo. de 2023
Editada: Dyuman Joshi el 31 de Mzo. de 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
t = 1×81
60.6664 60.9712 61.2792 61.5902 61.9045 62.2219 62.5427 62.8667 63.1941 63.5250 63.8593 64.1972 64.5387 64.8838 65.2327 65.5853 65.9417 66.3020 66.6663 67.0347 67.4071 67.7837 68.1645 68.5496 68.9391 69.3330 69.7315 70.1345 70.5423 70.9548
R = V.*t;
%new time
T = cumsum(t)
T = 1×81
1.0e+03 * 0.0607 0.1216 0.1829 0.2445 0.3064 0.3686 0.4312 0.4940 0.5572 0.6208 0.6846 0.7488 0.8134 0.8782 0.9435 1.0091 1.0750 1.1413 1.2080 1.2750 1.3424 1.4102 1.4784 1.5469 1.6158 1.6852 1.7549 1.8250 1.8956 1.9665
  2 comentarios
Alina Abdikadyr
Alina Abdikadyr el 31 de Mzo. de 2023
Thank you! but the results from loop and your method are different
Dyuman Joshi
Dyuman Joshi el 31 de Mzo. de 2023
Editada: Dyuman Joshi el 4 de Abr. de 2023
Apologies, @Alina Abdikadyr, there was a mistake in the formula of V which has been rectified. Please check my answer again.

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by