applying for loop on variables
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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);
0 Commenti
Risposte (1)
Rik
il 2 Giu 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!