calculate sum over n
Mostrar comentarios más antiguos
Hello! I try to calculate a sum over n
of matrices K,L such as K(m,n)*L(n,t)*L(n,j). So far I have the code below, but I am doubing I wrote it correctly. Could you please give advise on that?
K=rand(20,20);
Ln=rand(20,20);
sum11=zeros(1,20);
for n=1:20
summ=K(:,n).*Ln(n,:).*Ln(n,:);
sum11(n)=sum11(n)+summ;
end
4 comentarios
KSSV
el 16 de Jul. de 2020
Is the given code working first?
Walter Roberson
el 16 de Jul. de 2020
You should not have the period between K and the (
nn is not defined.
Ben Andersson
el 16 de Jul. de 2020
Walter Roberson
el 16 de Jul. de 2020
K(:,n).*Ln(n,:).*Ln(n,:)
is
K(:,n).*Ln(n,:).^2
Are you sure that is what you want? K(:,n) would be 20 x 1, and Ln(n,:).^2 would be 1 x 20, and 20 x 1 .* 1 x 20 is going to give you a 20 x 20 result.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!