Activities 111
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.
Sampling without Replacement
Suppose an urn contains n1 balls of a color, n2 balls of a second color, n3
balls of a third color, etc. Simulate drawing balls without replacing them.
Using Vectors to Determine Velocity
A small fishing boat leaves from the south bank of the Allegheny River
and heads at a 80° angle with an engine speed of 20 knots. However, the
eastward force of the current carries the boat along so it actually travels
at a 60° angle with the shore.
How fast is the current, and how fast does the boat actually travel?
: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]N1!templist[j]
:Exit
:EndIf
:EndFor
:EndFor
:Return drawlist
:EndFunc
1. Enter a random seed using the
RandSeed
command.
2. Assuming the urn contains 10 red balls and
25 white balls, simulate picking 5 balls at
random from the urn without replacement.
Enter
drawball({10,25},5).
Result: 2 red balls and 3 white balls.