フィルターのクリア

Use of tensorprod function to compute multilinear forms

39 ビュー (過去 30 日間)
Zeno Pavanello
Zeno Pavanello 2024 年 5 月 21 日 0:10
編集済み: Matt J 2024 年 5 月 29 日 11:19
Hi everyone,
I have to compute the multilinear form of a tensor and a vector. Suppose for example we have a 4-dimensional tensor A and a vector v. The 4-linear form is the multiplication of A by v 4 times. The only way that I found to do this is to use "for" loops. I think there must be a way to use the "tensorprod" function to perform the operation more efficiently but I can't find it. Thank you in advance to anyone who can help.
Cheers
n = 3;
A = rand(n,n,n,n);
v = rand(n,1);
for j = 1:n
for k = 1:n
G(:,k,j) = squeeze(v'*A(:,:,k,j));
end
end
for j = 1:n
J(:,j) = squeeze(v'*G(:,:,j));
end
res = v'*J*v;

回答 (3 件)

Matt J
Matt J 2024 年 5 月 21 日 0:27
編集済み: Matt J 2024 年 5 月 21 日 0:54
n = 3;
A = rand(n,n,n,n);
v = rand(n,1);
J=pagemtimes(v',pagemtimes(A,v));
res=v'*reshape(J,[n,n])*v
res = 2.4327

Matt J
Matt J 2024 年 5 月 21 日 0:37
編集済み: Matt J 2024 年 5 月 29 日 11:19
res=A;
while ~isvector(res)
res=pagemtimes(v',squeeze(res));
end
res=res*v

Catalytic
Catalytic 2024 年 5 月 21 日 0:57
res=A;
for i=1:ndims(A)
res = tensorprod(res,v,1);
end
res

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by