sum of kronecker products(four loops)
2 ビュー (過去 30 日間)
古いコメントを表示
Hello! I would like to know if the following code:
function result = kron_test(var1,var2,var3,var4)
result = zeros(N^2,N^2);
for e=1:N
for f=1:N
for g=1:N
for h=1:N
result = result + kron(var1(:,:,e,g),var2(:,:,f,h))*var3(e,f)*var4(g,h);
end
end
end
end
end
and the following:
function result = kron_test(var1,var2,var3,var4)
Var1 = reshape(var1,N^2,N^2);
Var2 = reshape(var2,N^2,N^2);
tmp = num2cell( reshape( Var2*kron(var4,var3).'*Var1.', N, N, [] ), [1,2] );
result = cell2mat(reshape(tmp,N,N));
end
are the same. I need to use this code for N > 30.
Thank you.
1 件のコメント
回答 (1 件)
Matt J
2021 年 5 月 10 日
For me, the following test for N=20 gives a very low percent error, so I would bet that the two are equivalent.
N=20;
[var1,var2]=deal( rand(N,N,N,N));
[var3,var4]=deal( rand(N,N) );
d=norm(kron_test0(var1,var2,var3,var4)-kron_test(var1,var2,var3,var4),'inf')
d0=norm(kron_test(var1,var2,var3,var4),'inf');
percentError = d/d0*100 % 9.7209e-13
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!