MATLAB Answers

Double sum of a product

10 views (last 30 days)
Elia Guerra
Elia Guerra on 26 Apr 2018
Commented: James Tursa on 30 Apr 2018
Can anyone help me with this? I've just started to use Matlab and i don't know how to do it. Thanks in advance!

Accepted Answer

Stephan on 26 Apr 2018
Edited: Stephan on 26 Apr 2018
Use a nested for-loop for this. Outer loop counts up from i=1 to N and the inner loop from n=1 to N.
for n = 1:N
for k = 1:N
r_0 = sum(rho_kn * r_k0 * r_n0);
r_0 = sqrt(r_0);
I replaced "i" by "k" here, because you could get in trouble when using i for loop count in combination with complex numbers. So i isnt recommended to use as a variable in matlab code.
Best regards
James Tursa
James Tursa on 30 Apr 2018
This can't possibly work correctly. r_0 is replaced with each iteration instead of accumulating. The indexes n and k are not used inside the loops for anything. Etc.
Have you actually tried to use this "solution"?

Sign in to comment.

More Answers (0)



Community Treasure Hunt

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

Start Hunting!