Solve linear tensor equation

5 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics and Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by