Borrar filtros
Borrar filtros

Using "for" loop for summation of matrix product

4 visualizaciones (últimos 30 días)
Nir Vaishnav
Nir Vaishnav el 11 de Jul. de 2022
Comentada: Jeffrey Clark el 11 de Jul. de 2022
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.

Respuesta aceptada

Jeffrey Clark
Jeffrey Clark el 11 de Jul. de 2022
@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 comentarios
Nir Vaishnav
Nir Vaishnav el 11 de Jul. de 2022
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 el 11 de Jul. de 2022
@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)?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by