フィルターのクリア

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.
  1 件のコメント
Aknur
Aknur 2022 年 9 月 19 日
Thank you, Mr. @Walter Roberson for your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops 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