MATLAB Answers

# Double sum with upper limits

1 view (last 30 days)
Helena Walther Lange on 2 Mar 2020
Commented: Luna on 3 Mar 2020
Hi
I am trying to do the following calululation in matlab: But I do not how how to do the two sums in the front. Our data (d) is a 67x120 array.
Any suggestions would be appreciated :)
##### 2 CommentsShowHide 1 older comment
Luna on 2 Mar 2020
What have you done so far as coding? And what is d?

Sign in to comment.

### Accepted Answer

Guillaume on 2 Mar 2020
Edited: Guillaume on 2 Mar 2020
s = (1:size(d, 1)).';
result = sum(sum(d .* cos(s))) / sum(cos(s));
Loops not needed, they're just a waste of time.
##### 3 CommentsShowHide 2 older comments
Luna on 3 Mar 2020
You are right.

Sign in to comment.

### More Answers (1)

Luna on 2 Mar 2020
Maybe something like that would help:
d = rand(67,120);
sum_of_cos_s = 0;
result = 0;
for s = 1:67
for j = 1:120
sum_of_cos_s = sum_of_cos_s+cos(s);
result = result + (d(s,j)*cos(s))/sum_of_cos_s;
end
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!