Using "for" loop for summation of matrix product

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by