15.1 Write some statements to simulate spinning a coin 50 times
using 0-1 vectors

instead of a forloop. Hints:Generate a vector of 50 random
numbers, set up

0-1 vectors to represent the heads and tails, and
usedoubleandcharto

display them as a string ofHs andTs.

15.2 In a game of Bingo the numbers 1 to 99 are drawn at
random from a bag.

Write a script to simulate the draw of the numbers (each
number can be drawn

only once), printing them ten to a line.

15.3 Generate some strings of 80 random alphabetic letters
(lowercase only). For

fun, see how many real words, if any, you can find in the
strings.

15.4 A random number generator can be used to estimateπas
follows (such a

method is called aMonte Carlomethod). Write a script which
generates random points in a square with sides of length 2, say,
and which counts what

proportion of these points falls inside the circle of unit
radius that fits exactly

into the square. This proportion will be the ratio of the
area of the circle to that

of the square. Hence estimateπ. (This is not a very efficient
method, as you

will see from the number of points required to get even a
rough

approximation.)

15.5 Write a script to simulate the progress of the
short-sighted student in Chapter

16 (Markov Processes). Start him at a given intersection, and
generate a

random number to decide whether he moves toward the internet
cafe or home,

according to the probabilities in the transition matrix. For
each simulated walk,

record whether he ends up at home or in the cafe. Repeat a
large number of

times. The proportion of walks that end up in either place
should approach the

limiting probabilities computed using the Markov model
described in Chapter

16.Hint:If the random number is less than 2/3 he moves toward
the cafe

(unless he is already at home or in the cafe, in which case
that random walk

ends), otherwise he moves toward home.

15.6 The aim of this exercise is to simulate bacteria growth.

Suppose that a certain type of bacteria divides or dies
according to the

following assumptions:

(a) during a fixed time interval, called ageneration, a
single bacterium

divides into two identical replicas with probabilityp;

(b) if it does not divide during that interval, it dies;

(c) the offspring (called daughters) will divide or die
during the next

generation, independently of the past history (there may well
be no

offspring, in which case the colony becomes extinct).

Start with a single individual and write a script which
simulates a number of

generations. Takep=0.75. The number of generations which you
can

simulate will depend on your computer system. Carry out a
large number (e.g.

100) of such simulations. The probability of ultimate
extinction,p(E), may be

estimated as the proportion of simulations that end in
extinction. You can also

estimate the mean size of thenth generation from a large
number of

simulations. Compare your estimate with the theoretical mean

of (2p)

n

.

Statistical theory shows that the expected value of the
extinction probability

p(E) is the smaller of 1, and (1−p)/p.Soforp=0.75,p(E) is
expected to be

1/3. But forp≤0.5,p(E) is expected to be 1, which means that
extinction is

certain (a rather unexpected result). You can use your script
to test this

theory by running it for different values ofp, and
estimatingp(E)in

each case.

### Other samples, services and questions:

When you use PaperHelp, you save one valuable — TIME

You can spend it for more important things than paper writing.