Summation Problem Please Help!!!
Mostra commenti meno recenti

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.
Risposte (1)
Roger Stafford
il 17 Feb 2014
Modificato: Roger Stafford
il 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 Commento
Edy
il 17 Feb 2014
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!