模擬同時投兩枚硬幣
Author: 藍邦偉　老師

$ 兩正面 $

$ 一正一反 $

$ 兩反面 $

$ 投擲兩枚硬幣 $

$ 次$
$數 $

$X=%v$

n = 2000 (slider from 0 to 2000, step 1)
a = 0.57 (slider from 0 to 1, step 0.01)
k = 0 (slider from 0 to n, step 1)
list1 = Sequence(Random[0, 1] + a * 0, i, 1, n)
list2 = Sequence(Random[0, 1] + a * 0, i, 1, n)
list3 = Sequence(Element[list1, i] + Element[list2, i], i, 1, Min[k, n])
list4 = Sequence(CountIf[x ≟ i, list3], i, 0, 2)
e = Segment((0.0675, -0.135), (30.0675, -0.135))
m: floor(Max[list4] / 20) + 1
d = Segment((0, 0), (0, 20))
list5 = Sequence(Text["" + (Element[list4, i]), (10 * i - 6, Element[list4, i] / m + 1)], i, 1, 3)
A = (2.32123, 21.5702875)
B: A + (13, 0)
b = BarChart({5, 15, 25}, list4 / m, 7)
q: Element[list1, k] + Element[list2, k]
c = 1 (slider from 0 to 2, step 1)
ANS: Binomial[2, c] * 0.25
t_{Main}: "$ 共投擲" + (LaTeX[n]) + "次 $
$ 第" + (LaTeX[k]) + "次投擲，\;出現" + (LaTeX[q]) + "個正面" + (LaTeX[2 - q]) + "個反面$
$ 若隨機變數X表出現正面的次數 $
$P(X=" + (LaTeX[c]) + ")=C^2_" + (LaTeX[c]) + "\left(  \frac{1}{2} \right)^" + (LaTeX[c]) + "\left(\frac{1}{2}   \right) ^" + (LaTeX[2 - c]) + " =" + (LaTeX[FractionText[ANS]]) + "$
$E(X)=2\cdot \frac{1}{4}+1\cdot \frac{1}{2}=1$
$V(X)=[\;2^2\cdot \frac{1}{4}+1^2\cdot \frac{1}{2}\;]-1^2=\frac{1}{2}$
$\sigma=\sqrt{V(X)}=\frac{\sqrt{2}}{2}$"