Randomly select n numbers from the continuous interval (0,1) and order them from least to greatest.
Find the expected values, in terms of n, of the smallest, second smallest, ..., second greatest, greatest.
n average value of:
1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
2 0.3323 0.6626
3 0.2486 0.5002 0.7495
4 0.2027 0.4023 0.6017 0.8016
5 0.1667 0.3358 0.5025 0.6667 0.8325
6 0.1406 0.2843 0.4267 0.5695 0.7137 0.8557
7 0.1264 0.2532 0.3779 0.5004 0.6241 0.7509 0.8761
8 0.1106 0.2214 0.3337 0.4457 0.5567 0.6676 0.7778 0.8896
9 0.0995 0.2007 0.3004 0.4019 0.5015 0.6023 0.7031 0.8020 0.9001
10 0.0911 0.1814 0.2722 0.3642 0.4536 0.5433 0.6353 0.7263 0.8165 0.9092
and it appears the expected value of the mth smallest when n random numbers are chosen is m/(n+1). There were 10,000 trials at each value of n.
DefDbl A-Z
Dim crlf$
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
End Function
Private Sub Form_Load()
Text1.Text = ""
For sz = 2 To 10
ReDim v(sz), tot(sz)
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For tr = 1 To 10000
For i = 1 To sz
v(i) = Rnd(1)
Next
Do
done = 1
For i = 1 To sz - 1
If v(i) > v(i + 1) Then swap v(i), v(i + 1): done = 0
Next
Loop Until done = 1
For i = 1 To sz
tot(i) = tot(i) + v(i)
Next
If tr = 10000 Then
Text1.Text = Text1.Text & mform(sz,"#0")
For i = 1 To sz
Text1.Text = Text1.Text & mform(tot(i) / tr, " 0.0000")
Next
Text1.Text = Text1.Text & crlf$
DoEvents
End If
Next tr
Next sz
End Sub
Sub swap(a, b)
Dim h
h = a: a = b: b = h
End Sub
|
Posted by Charlie
on 2014-05-15 16:35:46 |