Using nested loops to solve kronecker product

dear all, my question is how do solve kronecker's product of a 10x10 matrix or any matrix size using nested loops rather than the conventional Kron function.
for eg,
aa=round(rand(10,10)*10-5)
bb=round(rand(10,10)*20-10)
what do i write in the script to solve the multiplication of aa*bb using kroneckers rule.
thanks!

 採用された回答

sixwwwwww
sixwwwwww 2013 年 12 月 8 日
編集済み: sixwwwwww 2013 年 12 月 8 日

0 投票

you can do it as follows(if you have square matrices of same size):
A = round(rand(10,10)*10-5);
B = round(rand(10,10)*20-10);
for i = 1:size(A, 1)
for j = 1:size(A, 2)
AB{i, j} = A(i, j) * B;
end
end
AB = cell2mat(AB);
disp(AB)
Good luck!

4 件のコメント

Wei Hern
Wei Hern 2013 年 12 月 8 日
the answer is given in sections. i would like my answer to be in one whole matrix. sorry..
any other methods to get the answer in one full matrix
sixwwwwww
sixwwwwww 2013 年 12 月 9 日
編集済み: sixwwwwww 2013 年 12 月 9 日
Try this code:
A = round(rand(3)*10-5);
B = round(rand(3)*20-10);
for i = 1:size(A, 1)
for j = 1:size(A, 2)
AB{i, j} = A(i, j) * B;
end
end
AB = cell2mat(AB);
disp(AB)
and its answer is a 9x9 matrix which is a full matrix. Did you try it? AB is the full matrix
Wei Hern
Wei Hern 2013 年 12 月 9 日
yes it works now! and I'm guessing that when i change the first value of the matrix, it would also be able to calculate no matter what the size of the matrix is? thanks heaps!
sixwwwwww
sixwwwwww 2013 年 12 月 9 日
you are welcome. you can accept this answer if it is helpful to you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

タグ

質問済み:

2013 年 12 月 8 日

コメント済み:

2013 年 12 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by