Simulation of sampling without replacement – Texas Instruments TITANIUM TI-89 User Manual
Page 775
Activities
775
Simulation of Sampling without Replacement
Simulation of Sampling without Replacement
Simulation of Sampling without Replacement
Simulation of Sampling without Replacement
This activity simulates drawing different colored balls from an urn without replacing them.
Detailed information about the steps used in this example can be found in the electronic
chapter Programming.
Sampling-without- Replacement Function
Sampling-without- Replacement Function
Sampling-without- Replacement Function
Sampling-without- Replacement Function
In the
Program Editor
, define
drawball( )
as a function that can be called with two
parameters. The first parameter is a list where each element is the number of balls of a
certain color. The second parameter is the number of balls to select. This function
returns a list where each element is the number of balls of each color that were selected.
:drawball(urnlist,drawnum)
:Func
:Local templist,drawlist,colordim,
numballs,i,pick,urncum,j
:If drawnum>sum(urnlist)
:Return “too few balls”
:dim(urnlist)
!
colordim
:urnlist
!
templist
:newlist(colordim)!drawlist
:For i,1,drawnum,1
:sum(templist)
!
numballs
:rand(numballs)
!
pick
(continued in next column)
:For j,1,colordim,1
:cumSum(templist)
!
urncum
:If pick
urncum[j] Then
:drawlist[j]+1
!
drawlist[j]
:templist[j]
N
1
!
templist[j]
:Exit
:EndIf
:EndFor
:EndFor
:Return drawlist
:EndFunc