Using parfor for reflection function
조회 수: 1 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!