calculate sum over n
Afficher commentaires plus anciens
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 commentaires
KSSV
le 16 Juil 2020
Is the given code working first?
Walter Roberson
le 16 Juil 2020
You should not have the period between K and the (
nn is not defined.
Ben Andersson
le 16 Juil 2020
Walter Roberson
le 16 Juil 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!