Storing multiple different values from an equation in a for loop
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dario Grazioli
el 30 de En. de 2019
Comentada: Dario Grazioli
el 30 de En. de 2019
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 comentarios
Respuesta aceptada
Bob Thompson
el 30 de En. de 2019
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!