How can i use symbolic variables in a parallel Computing (parfor)?

6 ビュー (過去 30 日間)
asad
asad 2025 年 3 月 29 日
編集済み: Catalytic 2025 年 3 月 30 日
Hi guys,
I'm using 'parfor' instead of 'for' and performing some calculations with symbolic variables and matrices. However, I encountered some errors when using this function (figs belos).
Are there any solutions for this?
I attached the code.
thanks so much

採用された回答

Matt J
Matt J 2025 年 3 月 29 日
編集済み: Matt J 2025 年 3 月 29 日
Dlu_11_1= zeros([M,N,N,M], 'sym') ;
parfor t=1:(M*N)^2
[ki,kj,j,i]=ind2sub([M,N,N,M],t);
Dlu_11_1(t)=diff(dlU_11(ki,kj),U1(i,j));
end
Dlu_11_1=reshape( Dlu_11_1 , M*N, []);
  4 件のコメント
Matt J
Matt J 2025 年 3 月 29 日
This might be a little bit faster,
MN=M*N;
Dlu_11_1= zeros(MN, 'sym') ;
U1=U1.';
parfor t=1:(MN)^2
[I,J]=ind2sub([MN,MN],t);
Dlu_11_1(t)=diff(dlU_11(I),U1(J));
end
U1=U1.';
Dlu_11_1=reshape( Dlu_11_1 , MN, []);
asad
asad 2025 年 3 月 30 日
Thanks again Matt.

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

その他の回答 (1 件)

Catalytic
Catalytic 2025 年 3 月 30 日
編集済み: Catalytic 2025 年 3 月 30 日
Why not simply -
Dlu_11_1 = reshape( jacobian(dlU_11, U1) , M*N,N,M);

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by