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.

Answers (1)

Roger Stafford
Roger Stafford on 17 Feb 2014
Edited: Roger Stafford on 17 Feb 2014
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 Comment

What it would be like if I use factorial formula instead of Pascal Triangle?

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

Edy
on 16 Feb 2014

Commented:

Edy
on 17 Feb 2014

Community Treasure Hunt

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

Start Hunting!