Summation Problem Please Help!!!
이전 댓글 표시

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
2014년 2월 17일
편집: Roger Stafford
2014년 2월 17일
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)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!