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

 Akzeptierte Antwort

Matt J
Matt J am 12 Feb. 2023
Bearbeitet: Matt J am 12 Feb. 2023

0 Stimmen

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

Weitere Antworten (0)

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by