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!