Hello! How to make for loop for cycle calculation using previous coordinates to calculate next one, etc
Afficher commentaires plus anciens
Hello! I am trying to apply for loop. I have x0, y0, z0 coordinates and wrote a function to calculate next x1, y1, z1
I need to make for loop and the previous calculated result of x1, y1, z1 will be considered for the next cycle ( instead of x0, y0, z0) and so on (x2, y2, z2 will , number of cycle will be 5. I tried to do it. Could you please help me with my code. Thank you in advance
function [x1, y1, z1, F] = reflection(x0,y0,z0, Theta, Phi)
disp(x1);
disp(y1);
disp(z1);
disp(F);
end
And here is my for loop attempt
x0 = 1.5;
y0 = 1.5;
z0 = 3.0;
for ii=1:10
r1 = 1i;
r2 = 1i + 1;
reflection(x(ii), y(ii), z(ii));
end
1 commentaire
Dyuman Joshi
le 13 Oct 2022
You can call the function in a loop -
x0 = [1.5 zeros(1,10)];
y0 = [1.5 zeros(1,10)];
z0 = [3.0 zeros(1,10)];
for ii=2:11
r1 = 1i;
r2 = 1i + 1;
[x0(ii),y0(ii),z0(ii),~]=reflection(x0(ii-1), y0(ii-1), z0(ii-1));
end
However, the function requires 5 inputs, of which 2 are missing from the function call above (Theta, Phi)
Also, what is the significance of r1 and r2 in the for loop?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!