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
0 件のコメント
採用された回答
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 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!