Is there a way to run many anonymous functions simultaneously?

1 回表示 (過去 30 日間)
KieranSQ
KieranSQ 2021 年 3 月 12 日
コメント済み: KieranSQ 2021 年 3 月 15 日
Hi All,
I have a problem where I need to evaluate 18 anonymous functions before combining them into three variables. This is incredibly slow and painful at points so I was wondering whether there is a way to run these simultaneously (on an 8 core desktop and cluster)?
The reason we have so many functions is we are evaluating our test problem exactly through integration. We plan to create some numerical quadratures in the near(ish) future but need to be sure our method works well first for our test cases. An example of my code is below:
Here all the f_i's are integrals in space and time for an arbitary function.
if conditions == 1
Tf1_1 = f1_1(arg1, arg2, arg3);
Tf1_2 = f1_2(arg1, arg2, arg3);
Tf1_3 = f1_3(arg1, arg2, arg3);
Tf1_4 = f1_4(arg1, arg2, arg3);
Tf1_5 = f1_5(arg1, arg2, arg3);
Tf1_6 = f1_6(arg1, arg2, arg3);
Tf2_1 = f2_1(arg1, arg2, arg3);
Tf2_2 = f2_2(arg1, arg2, arg3);
Tf2_3 = f2_3(arg1, arg2, arg3);
Tf2_4 = f2_4(arg1, arg2, arg3);
Tf2_5 = f2_5(arg1, arg2, arg3);
Tf2_6 = f2_6(arg1, arg2, arg3);
Tf3_1 = f3_1(arg1, arg2, arg3);
Tf3_2 = f3_2(arg1, arg2, arg3);
Tf3_3 = f3_3(arg1, arg2, arg3);
Tf3_4 = f3_4(arg1, arg2, arg3);
Tf3_5 = f3_5(arg1, arg2, arg3);
Tf3_6 = f3_6(arg1, arg2, arg3);
end
%Combining the integrals
loc_f1 = Tf1_1 + Tf1_2 + Tf1_3 + Tf1_4 + Tf1_5 + Tf1_6;
loc_f2 = Tf2_1 + Tf2_2 + Tf2_3 + Tf2_4 + Tf2_5 + Tf2_6;
loc_f3 = Tf3_1 + Tf3_2 + Tf3_3 + Tf3_4 + Tf3_5 + Tf3_6;
Any tips or ideas would be appreciated!

採用された回答

Matt J
Matt J 2021 年 3 月 12 日
  1 件のコメント
KieranSQ
KieranSQ 2021 年 3 月 15 日
Perfect, this worked well! Many thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by