フィルターのクリア

Using "for" loop for summation of matrix product

4 ビュー (過去 30 日間)
Nir Vaishnav
Nir Vaishnav 2022 年 7 月 11 日
コメント済み: Jeffrey Clark 2022 年 7 月 11 日
I am using nested for loops to multiply matrices and do the summation of the same. But for Lk(k) variable its only taking the kth element instead of whole matrix Lk,
This is the code
Lk=kron(I,bk);
Gk=Hk;
Lkh=transpose(Lk);
Gkh=(Gk)';
B=zeros(M,M);
for k=1:M
for i=1:M
s=0;
for m=1:M
s= s+ inv(Lk(k)'*Gk(k,m)'*(Gk(k,m)*Lk(k))) * Lk(k)'*Gk(k,m)'*Gk(i,m)*Lk(i);
end
B(k,i)=s;
end
end
This is the warning given: Warning: Matrix is singular to working precision.

採用された回答

Jeffrey Clark
Jeffrey Clark 2022 年 7 月 11 日
@Nir Vaishnav, you don't say what any of the iputs are, but since kron will produce a matrix (unless both inputs I and bk are either column or row vectors), the indexed Lk(k) and Lk(i) are linear indexs to the a single element. If as you say you want the whole matrix Lk you should loose the subscripts or change them to appropriate row and col ranges.
  2 件のコメント
Nir Vaishnav
Nir Vaishnav 2022 年 7 月 11 日
Lk takes the input of identity matrix whose kronecker product is ones matrix so Lk has dimension M×M and Gk is randomly generated matrix having dimensions k×M
Jeffrey Clark
Jeffrey Clark 2022 年 7 月 11 日
@Nir Vaishnav, so Lk is a matrix, why do you take only one linerally addressed value from it (the indexed Lk(k) and Lk(i)) and expect a matrix when you are also only multiplying by single values from Gk(k,m) and Gk(i,m)?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by