applying for loop on variables

8 visualizaciones (últimos 30 días)
Jaehoon Bang
Jaehoon Bang el 2 de Jun. de 2021
Respondida: Rik el 2 de Jun. de 2021
for i=1:100
x(i+1)=x(i)+Ka*(Xf-x(i))-Kr*(1/rho_r1(i)-1/ro)/(rho_r1(i)^3)*(Xo1-x(i))-Kr*(1/rho_r2(i)-1/ro)/(rho_r2(i)^3)*(Xo2-x(i))-Kr*(1/rho_r3(i)-1/ro)/(rho_r3(i)^3)*(Xo3-x(i));
y(i+1)=y(i)+Ka*(Yf-y(i))-Kr*(1/rho_r1(i)-1/ro)/(rho_r1(i)^3)*(Yo1-y(i))-Kr*(1/rho_r2(i)-1/ro)/(rho_r2(i)^3)*(Yo2-y(i))-Kr*(1/rho_r3(i)-1/ro)/(rho_r3(i)^3)*(Yo3-y(i));
end
can anyone tell me how to apply for loop on variable "roh_r1&r2&r3"?
i tried to use 'eval', but failed
this is rho function.
rho_r1(1)=sqrt((Yo1-y(1))^2+(Xo1-x(1))^2);
rho_r2(1)=sqrt((Yo2-y(1))^2+(Xo2-x(1))^2);
rho_r3(1)=sqrt((Yo3-y(1))^2+(Xo3-x(1))^2);

Respuestas (1)

Rik
Rik el 2 de Jun. de 2021
You know how to do indexing, so why did you make the decision to store data in a variable name?
for k=1:3
rho_r{k}(1)=sqrt((Yo{k}-y(1))^2+(Xo{k}-x(1))^2);
% ^^^ ^^^ ^^^
end

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by