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

darova
darova 2020년 3월 2일
Luna
Luna 2020년 3월 2일
편집: Luna 2020년 3월 2일
What have you done so far as coding? And what is d?

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2020년 3월 2일
편집: Guillaume 2020년 3월 2일

1 개 추천

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

Luna
Luna 2020년 3월 2일
편집: Luna 2020년 3월 2일
My understanding of /Sigma[cos(s)] part, it should be divided into sum of cos(s) from 1 to what s is until that iteration. For example if s is 20 while j = 3;
d(20,3)*cos(20) / ( cos(1)+cos(2)+...+cos(20) )
so your result gives a vector (1x67). I assume that result must be a scalar.
Yes, I made a mistake, there was a sum missing in the denominator. I assumed that the could be taken out of the double sum, i.e. it's over the whole range. It's not clear and we didn't get an answer to Darova's question. So, my code implement:
If it's a partial sum as you think, then:
s = (1:size(d, 1)).';
result = sum(sum(d .* cos(s) ./ cumsum(cos(s))));
which implements
Luna
Luna 2020년 3월 3일
You are right.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Luna
Luna 2020년 3월 2일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2020년 3월 2일

댓글:

2020년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by