loop to calculate time using previous values
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Dyuman Joshi
2023-3-31
编辑:Dyuman Joshi
2023-3-31
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 个评论
Dyuman Joshi
2023-3-31
编辑:Dyuman Joshi
2023-4-4
Apologies, @Alina Abdikadyr, there was a mistake in the formula of V which has been rectified. Please check my answer again.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!