zero value in beronoulli trials !!!

Hi sir,I want to know,why some values in my program equal to zero
This is my program
N=10;
P=0.5;
for K=0:N;
format long e
M =exp((P)^K*((1-P)^N-K)*(factorial(N)/factorial(K)*factorial(N-K)))
display(M)
end
Thanks in advance

 Akzeptierte Antwort

Andrew Newell
Andrew Newell am 10 Apr. 2011

1 Stimme

The correct expression is
M =P.^K.*(1-P).^(N-K).*factorial(N)./(factorial(K).*factorial(N-K))
If you have the Statistics Toolbox, you can confirm that this gives the same output as
binopdf(0:N,N,P)

1 Kommentar

reem
reem am 10 Apr. 2011
Thank you so so much Oleg and Andrew
I will not forget your help forever
Kind regards

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Oleg Komarov
Oleg Komarov am 10 Apr. 2011

1 Stimme

Some other parenthesis mistakes corrected:
N=10;
P=0.5;
K=0:N;
M =exp(P.^K.*(1-P).^(N-K).*factorial(N)./(factorial(K).*factorial(N-K)))

1 Kommentar

reem
reem am 10 Apr. 2011
Thank you so much Oleg
I hope all best thing for you

Melden Sie sich an, um zu kommentieren.

bym
bym am 10 Apr. 2011

0 Stimmen

I think you want N!/(K!*(N-K)!)<--note parentheses

1 Kommentar

reem
reem am 10 Apr. 2011
Yes I want that,so what is the problem here in my program

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by