VBA サイコロの平均の収束
Sub サイコロの平均()
Dim n As Integer
Dim m As Integer
Dim X_n As Double
Dim E As Double
Dim Ex() As Double
Dim i As Integer
Dim j As Integer
Dim p As Single
Dim a As Double
Worksheets("sheet5").Activate
n = 1000
m = 2000
ReDim Ex(1 To n, m + 1)
Ex(1, 0) = n
For j = 1 To m
X_n = 0
For i = 1 To n '試行する
a = Int(6 * Rnd()) + 1 'サイコロ
X_n = a + X_n
Next i
E = X_n / n
Ex(1, j) = E
Next j
For i = 0 To m
Cells(i + 2, 1).Value = i
Cells(i + 2, 2).Value = Ex(1, i)
Cells(i + 2, 3).Value = (n) ^ (1 / 2) * (Ex(1, i) - 7 / 2) / (35 / 12) ^ (1 / 2)
Next i
End Sub