필터 지우기
필터 지우기

Using parfor for reflection function

조회 수: 1 (최근 30일)
Aknur
Aknur 2022년 9월 14일
댓글: Aknur 2022년 9월 19일
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);

채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 14일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by