zero value in beronoulli trials !!!

1 次查看(过去 30 天)
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

采纳的回答

Andrew Newell
Andrew Newell 2011-4-10
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 个评论
reem
reem 2011-4-10
Thank you so so much Oleg and Andrew
I will not forget your help forever
Kind regards

请先登录,再进行评论。

更多回答(2 个)

Oleg Komarov
Oleg Komarov 2011-4-10
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)))

bym
bym 2011-4-10
I think you want N!/(K!*(N-K)!)<--note parentheses
  1 个评论
reem
reem 2011-4-10
Yes I want that,so what is the problem here in my program

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by