How can I do this summation formula in Matlab? The value of N = 0:2:32; Let P = (factorial(N)./(factorial(i).*factorial(N-i)))/(2.^N); Thanks.

답변 (1개)

Roger Stafford
Roger Stafford 2014년 2월 17일
편집: Roger Stafford 2014년 2월 17일

0 개 추천

Believe it or not, the following code will compute your H, and in fact is probably more accurate than using factorials. It uses a technique known as the "Pascal Triangle". It differs only in the division by 2 at each step in computing P.
N = 32;
P = zeros(N+1,N+2);
P(1,2) = 1;
for n = 1:N
P(n+1,2:n+2) = (P(n,1:n+1)+P(n,2:n+2))/2;
end
h = zeros(N+1,1);
for n = 0:N
h(n+1) = -sum(P(n+1,2:n+2).*log2(P(n+1,2:n+2)));
end
The array 'h' here is such that H(n) = h(n+1). It gets all H from H(0) to H(32). If you want it at 0:2:32 do:
h(1:2:33)

댓글 수: 1

Edy
Edy 2014년 2월 17일
What it would be like if I use factorial formula instead of Pascal Triangle?

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

카테고리

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

태그

질문:

Edy
2014년 2월 16일

댓글:

Edy
2014년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by