Storing multiple different values from an equation in a for loop

조회 수: 5 (최근 30일)
Hello,
do you have any advice to solve the following problem that I am facing?
The problem consists in the fact the using the following loop I get in each column of V the same value, while my intention is to give to each column the corresponding value of a mass' value calculated.
for k=1:-dm;
for m=MTOW:-1:MZFW
V(k)=sqrt((2*m*g)./(p1*S*Clmd));
end
end
Therefore, cheching all the values that fill the vector V,they are all the same number(222.1211,which should be the last result for the last time that the equation is computed).
The first number should be near 250 and it should slowly approach the last value 222.1211 hence all the columns of the vector should be filled with different and decreasing values.
This is the full MATLAB code:
g=9.81;
p1=0.4138
MTOW=93500;
MZFW=73800;
dm=MZFW-MTOW
S=122.6;
fj= 7.1824e-06;
CD0=0.0424;
k=0.1267;
Clmd= sqrt(CD0/k)
Cd= CD0+k*(Clmd^2);
for k=1:-dm;
for m=MTOW:-1:MZFW
V(k)=sqrt((2*m*g)./(p1*S*Clmd));
end
end

채택된 답변

Bob Thompson
Bob Thompson 2019년 1월 30일
Because you are running multiple two for loops, you likely need to have two dimensional indexing.
V(k,m) = ...
This should give your results of different m's as each column, and different k's as each row. As you have it now, you are only recording the final m value for each k value.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by