Getting Started Math 1180 - Mathematics for Life Scientists

advertisement
Math 1180 - Mathematics for Life Scientists
Lab 4 - Random Variables
Due Tuesday, March 6, 2006
Getting Started
As usual, create a directory for lab 4 by typing mkdir lab4. Open Maple and type restart; to start
fresh. Warm up Maple for today's problems with the commands
>
>
>
>
iread(histplot);
iread(draw);
with(stats):
iread(iter);
Problems
1. Recall the method for generating \random numbers" between 0 and 1:
> number := x -> stats[random,uniform[0,1]](1);
These numbers are associated with the p.d.f. ( ) = 1 for 0 1. Here are the commands to
make a data set of 50 such numbers called , and nd their average.
f x
x
dat
> dat := [seq(number(),i=1..50)]:
> describe[mean](dat);
(a) Find the average of your 50 numbers.
(b) Recall that to integrate a function, say ( ), with respect to where ranges from to ,
you use the following setup:
g x
x
x
a
b
> int(g,x=a..b);
Use the denition of expectation of a continuous random variable X with p.d.f. ( ) = 1
to nd the expectation of random numbers from 0 to 1. You will need to use the command
above. (Hint: ( ) is not simply equal to ( ).) How close is your answer to the average
found in part a?
(c) Try the same steps but make dat include 500 numbers instead. (Note, you denitely want
to end the dat line with a colon : or a huge list of numbers will be output that will waste
paper later.) Is the result closer to the expectation you found in part b?
f X
E X
f X
2. The command histplot can be used to plot a probability distribution as a histogram. To enter
a probability distribution, type
> a := [1,3,5,7];
> p := [.3,.1,.5,.1];
The array lists the possible values, and lists the probabilities. In this case, the random variable
takes the value 1 with probability 0.3, 3 with probability 0.1, and so forth. To plot a histogram,
type
a
p
> histplot(a,p);
To pick a random sample of these events, use the command
> draw(a,p);
This pulls a 1 with probability 0.3, a 3 with probability 0.1, and so on.
(a) Use the seq command to draw 50 events and save the result as 2:
dat
> dat2:=[seq(draw(a,p),i=1..50)];
Compare the fraction of 1's, 3's, 5's and 7's with what you see on the histogram. A clever
way to do this uses the transform command as follows
> transform[tally](dat2);
Divide the answers by 50 to answer what fraction of the trials each number arises.
(b) Find the average of your 50 numbers using the describe[mean] command.
(c) Use the denition of expectation to nd the average. (This time you will add instead of
integrating.) How close is it to the average?
3. Suppose that the p.d.f. for the time a molecule leaves a cell is equal to
( )=05 05
for 0.
(a) Use integration to compute the c.d.f. ( ) as follows. (We use a dummy variable to not
confuse Maple with the in the limits of integration.)
X
f x
: e
: x
x
F x
y
x
> F:=int(0.5*exp(-0.5*y),y=0..x);
(b) Plot and
f
F
on one graph for 0 3 by typing:
x
> f:=0.5*exp(-0.5*x);
> plot([f,F],x=0..3);
(c) Compute the probability that the time X lies between 1 and 1.5 two ways. First, integrate
the pdf from 1 to 1 5. Then, use the cdf to nd the probability by using the eval command
to nd (1 5) (1). These answers should match.
:
F
:
F
> eval(F,x=1.5)-eval(F,x=1);
Mark the associated area on your graph of .
(d) Use the cdf to compute the probability that the time X is less than 0.6 and indicate this on
your graph of .
(e) Find the median using the solve command
f
F
> solve(F=0.5);
(f) Use integration to nd the expectation. (Integrate
match the median?
( ) from 0 to
xf x
infinity.)
Does it
Download