I am building a fem code and want to solve an equation of the form
f= tensorprod(A,u,[2,4],[1,2])
where:
size(A)= n by n by 2 by 2
Size(u) = n by 2
Size(F) = n by 2.
A and f are known, u is to be solved
please note that n is a large number e.g order of 1e4 and this equation has to be solved often
n=5;
A=rand(n,n,2,2);
u=rand(n,2); %u is actually the variable that is to be solved while f is known
f=tensorprod(A,u,[2 4],[1 2])
f = 5×2
2.2134 2.4372 1.8815 2.0397 2.8814 2.2488 2.5063 2.0120 3.1808 1.7589

 採用された回答

Matt J
Matt J 2023 年 2 月 12 日
編集済み: Matt J 2023 年 2 月 12 日

0 投票

n=5;
A=rand(n,n,2,2);
utrue=rand(n,2);
f=tensorprod(A,utrue,[2 4],[1 2]);
A=permute(A,[1,3,2,4]);
A=reshape(A,2*n,2*n);
u=A\f(:); %solve
[u(:), utrue(:)]
ans = 10×2
0.2121 0.2121 0.7296 0.7296 0.3174 0.3174 0.5335 0.5335 0.6222 0.6222 0.8405 0.8405 0.3491 0.3491 0.2908 0.2908 0.8140 0.8140 0.1061 0.1061

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2023 年 2 月 12 日

編集済み:

2023 年 2 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by