二項分配與彈珠台
Author: 官長壽老師, 藍邦偉  老師

AutoStart

二項分配X∼B(n,p)實驗:

白努力試驗:n=

機率:p=

丟球次數:m=

p = 0.5 (slider from 0 to 1, step 0.01)
Reset = 0.5 (slider from 0 to 1, step 0.1)
m = 200 (slider from 1 to 200, step 1)
h = 200 (slider from 0 to m, step 1)
n = 5 (slider from 2 to 30, step 1)
matrix1 = Sequence(Sequence[Reset * 0 + random(), i, 1, n], t, 1, m)
matrix2 = Sequence(Sequence[If[Element[Element[matrix1, t], i] < p, 0, 1], i, 1, n], t, 1, m)
k = 0 (slider from 0 to n, step 1)
i = 1 (slider from 0 to 1, step 1)
list3 = Join({{(0, 0)}, Sequence[(Element[Element[matrix2, h + 1], i], 1 - Element[Element[matrix2, h + 1], i]), i, 1, n]})
a = true
speed = 15 (slider from 0 to 15, step 1)
list4 = Sequence(Sum[list3, i], i, 1, n + 1)
A = (-4.38, -1.86)
B = Point(Ray[A, A + (1, 0)])
P = Dilate(Rotate[B, 45*°, A], 0.7071067811865475, A)
u = Vector(P, P + (A - P) / n)
v = Vector(P, P + (B - P) / n)
list1 = Sequence(Segment[P + i * u, P + i * u + (n - i) * v], i, 0, n)
list2 = Sequence(Segment[P + i * v, P + i * v + (n - i) * u], i, 0, n)
C = Point(Ray[A, A + (0, -1)])
D = Translate(C, Vector[A, B])
list6 = Sequence(Sum[Element[matrix2, i]], i, 0, h)
list7 = Sequence(-0.5 + i, i, 0, n + 1)
list8 = Frequency(list7, list6)
d: (x(B) - x(A)) / (2 * n)
b = Segment(C, D)
list5 = Sequence(Vector[P + x(Element[list4, i]) * v + y(Element[list4, i]) * u, P + x(Element[list4, i + 1]) * v + y(Element[list4, i + 1]) * u], i, 1, k)
list10 = Sequence(A + i * (B - A) / n, i, 1, n - 1)
list11 = Sequence(C + i * (D - C) / n, i, 1, n)
e: abs(y(C) - y(A)) / (Max[Frequency[list7, Sequence[Sum[Element[matrix2, i]], i, 0, m]]] + 2)
list12 = Sequence(Text[Element[list8, t], C + (t - 1) * (D - C) / n + (-0.1, e * Element[list8, t] + 0.05)], t, 1, n + 1)
累積球數 = Sequence(Polygon[C + ((2 * i - 2.8) * d, 0), C + ((2 * i - 1.2) * d, 0), C + ((2 * i - 1.2) * d, Element[list8, i] * e), C + ((2 * i - 2.8) * d, Element[list8, i] * e)], i, 1, n + 2)
Ball: P + x(Element[list4, k + 1]) * v + y(Element[list4, k + 1]) * u
inputBox1 = Textfield(n)
text2: "$白努力試驗n=" + (LaTeX[n]) + "次$
$往左機率p=" + (LaTeX[p]) + "$
$往右機率1-p=" + (LaTeX[1 - p]) + "$
$ 丟球次數,設定:m=" + (LaTeX[m]) + "次$
$目前實驗到第" + (LaTeX[h]) + "次$"
inputBox2 = Textfield(p)
inputBox3 = Textfield(m)