二項分布
Author: 藍邦偉老師

$ 二項分布 $

$ 若隨機變數X服從二項分配B(n,p) ，\;則\;P(X=k)=C^n_kp^k(1-p)^{n-k}$

$  成功次數$

$ 機 $
$率$

A = (0, 0)
C: A + (0, 5)
i = Segment(C - (1, 0), A - (1, 0))
b = 1 (slider from 1 to a, step 1)
a = 2 (slider from 1 to 30, step 1)
p: b / a
n = 8 (slider from 1 to 30, step 1)
list_4 = Sequence(p^(k) * (1 - p)^(n - k), k, 0, n)
list_3 = Sequence(Binomial[n, k], k, 0, n)
e = Max(list_3 * list_4)
k = 2 (slider from 0 to n, step 1)
ANS: Binomial[n, k] * p^(k) * (1 - p)^(n - k)
text1: "$ X∼B(" + (LaTeX[n]) + "," + (LaTeX[FractionText[p]]) + ") $
$P(X=" + (LaTeX[k]) + ")=C^{" + (LaTeX[n]) + "}_{" + (LaTeX[k]) + "}\left(" + (LaTeX[FractionText[p]]) + "   \right) ^{" + (LaTeX[k]) + "}\left(" + (LaTeX[FractionText[1 - p]]) + "   \right) ^{" + (LaTeX[n - k]) + "}$
                     $=" + (LaTeX[FractionText[ANS]]) + "$
                     $=" + (LaTeX[ANS]) + "$"
text2: "$ 成功的機率\;p=" + (LaTeX[FractionText[b / a]]) + " $"
text4: "$ 成功\;" + (LaTeX[k]) + "\;次 $"
text3: "$共試驗" + (LaTeX[n]) + "次 $"
f: floor(i / e)
B: A + (8, 0)
list_5: f * list_3 * list_4
list_1 = Sequence(Polygon[(k * 10 / (n + 1), 0), ((k + 1) * 10 / (n + 1), 0), ((k + 1) * 10 / (n + 1), Element[list_5, k + 1]), (10 * k / (n + 1), Element[list_5, k + 1])], k, 0, n)
list_2 = Sequence(((5 + k * 10) / (n + 1), 0), k, 0, n)
list_6 = Sequence(Text[k, Element[list_2, k + 1] + (-0.1, -0.4)], k, 0, n)
list_7 = Sequence((-1, k * y(C) / (floor(e * 10) + 1)), k, 1, floor(e * 10) + 1)
Poly1, g, h, i_1, j = Polygon((k * 10 / (n + 1), 0), ((k + 1) * 10 / (n + 1), 0), ((k + 1) * 10 / (n + 1), f * Binomial[n, k] * p^(k) * (1 - p)^(n - k)), (k * 10 / (n + 1), f * Binomial[n, k] * p^(k) * (1 - p)^(n - k)))
d = Segment(A - (1, 0), B + (2.6, 0))
list_8 = Sequence(Segment[(-1, y(Element[list_7, k])), (10.6, y(Element[list_7, k]))], k, 1, floor(e * 10) + 1)