loop to calculate time using previous values
조회 수: 1 (최근 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!