Would you please tell me what do I have to fix in Binomial distribution code?

조회 수: 2 (최근 30일)
for n = 2:30
for x=1:n;
p(x) = (factorial(n)/(factorial(x)* factorial(n-x)))*((10/230)^x)*(1-(10/230).^(n-x));
end
end
plot(p)
The graph should come out as one plot that is decreasing, but my graph now has several rising graphs. Would you tell me what do I have to change please?
  댓글 수: 1
Paul
Paul 2022년 10월 13일
x should start at 0.
It looks like you're trying to get p for different vaues of n. But each time through the loop overwrites the previous computation of p. So you'll either need to put the plot(0:n,p) command (with a hold) inside the loop, save each p in some sort of data structure and the plot after the loop.
Also, might be interested in this function: nchoosek

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2022년 10월 13일
Note, factorial(30) will not be exact since it has more digits than floating point. The plot is constantly decreasing.
for n = 2:30
for x=1:n;
p(x) = (factorial(n)/(factorial(x)* factorial(n-x)))*((10/230)^x)*(1-(10/230).^(n-x));
end
end
diff(p)<0
ans = 1×29 logical array
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by