Effacer les filtres
Effacer les filtres

Using parfor for reflection function

1 vue (au cours des 30 derniers jours)
Aknur
Aknur le 14 Sep 2022
Commenté : Aknur le 19 Sep 2022
Hi! I have light rays and their points (x0, y0, z0; x1, y1, z1; ) I want to apply parfor for calculation of reflection (x, y, z) for each point, and for end point (x, y, z ). Reflection points (x, y, z) of the first reflection will be the starting point for the next one, and so on. I am really absolutely new in Matlab. Here is my draft. And also I will calculate length of the ray (using Pythagorean theorem) Thank you for your help in advance
function [x,y,z] = reflection(x0, y0, z0, theta ... )
% Detailed explanation goes here
outputArg1 = inputArg1;
outputArg2 = inputArg2;
end
% number of reflection
Bk = 6;
parfor ii=1:Bk;
for ii = 1:5
x(ii), y(ii), z(ii) = reflection(x0,y0,z0, theta(ii))
length of the ray (using Pythagorean theorem)
% Ray1 1.5, 0 ,0
x0 = 1.5;
x1 = 1.5;
y0 = 1.5;
y1 = 0;
z0 = 3;
z1 = 0;
% length of ray
d1 = sqrt((x1-x0)^2 + (y1-y0)^2 + (z1-z0)^2);

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Sep 2022
You define a function. Inside the function you use parfor. Inside the function you call itself recursively. That would attempt to invoke parfor within the existing parfor, which is permitted but would treat the inner parfor as a plain for loop.
You do not have any termination test on your recursion so the function is going to invoke itself over and over again until you exceed the stack limit and generate an error.
  1 commentaire
Aknur
Aknur le 19 Sep 2022
Thank you, Mr. @Walter Roberson for your help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by