



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Math 381 Greenbaum Solutions to HW #3 February 4, 2007
One way to make a discrete random variable K taking values 1... 6 from a uniform(0,1) variable U is to break the interval [0,1] into sixths and see which sixth K lands in. For convenience, I’ve put this in a function. This is placed in a separate file called roll fair die.m.
function [k] = roll_fair_die % rolls a fair die and returns 1, ..., 6 with equal probability
u = rand; if (u < 1/6) k = 1; elseif (u < 2/6) k = 2; elseif (u < 3/6) k = 3; elseif (u < 4/6) k = 4; elseif (u < 5/6) k = 5; else k = 6; end
Here’s the code to simulate rolling a fair die 1000 times and plot the number of 1’s, 2’s, etc.
bins = zeros(6,1); for count = 1: k = roll_fair_die; bins(k) = bins(k) + 1; % count the number of times each number is generated end; bar(bins); % plot the bins
This gives the plot
(^01 2 3 4 5 )
20
40
60
80
100
120
140
160
180
The expected value and variance of the random variable K are found by:
E(K) =
var(K) = E(K^2 ) − E(K)^2 =
Let A 1000 be the average value of rolling a die 1000 times. Then we can get a histogram for A 1000 by simulating it 100 times as follows:
A = zeros(100,1); for n_tries = 1: bins = zeros(6,1); for count = 1: k = roll_fair_die; A(n_tries) = A(n_tries) + k; % add each value k
elseif (u < 5/10) k = 5; else k = 6; end %%%% end of roll_loaded_die.m %%%%
bins = zeros(6,1); for count = 1: k = roll_loaded_die; bins(k) = bins(k) + 1; % count the number of times each number is generated end; bar(bins); % plot the bins
A = zeros(200,1); for n_tries = 1: bins = zeros(6,1); for count = 1: k = roll_loaded_die; A(n_tries) = A(n_tries) + k; % add each value k end; A(n_tries) = A(n_tries) / 1000; % divide by 1000 to get the average of k end; hist(A); % plot a histogram of the average values
This time, even though the probability density for a single die is very skewed, the central limit theorem still forces the average A 1000 to be approximately normal.
(^01 2 3 4 5 )
100
200
300
400
500
600
4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4. 0
5
10
15
20
25
30
35
40
45
In this case, we have:
var(K) = E(K^2 ) − E(K)^2 =
And by the Central Limit Theorem,
E(A 1000 ) = E(K) = 9/2 = 4. 5 var(A 1000 ) = var(K)/1000 = 0. 00325 stddev(A 1000 ) =
var(A 1000 ) = 0. 0570088
− 2 −1.5 − 1 −0.5 0 0.5 1 1.5 2 − 1
−0.
−0.
−0.
−0.
0
1
and (this time) we get 787/1000 inside, with an estimated area of 6.2960.
Now, to can see how good this estimate is. Let Xi be the random variable that is 1 if the ith point is in the ellipse and 0 otherwise. Since Xi is 1 with probability approximately 0.787 and 0 otherwise, we have:
E(Xi) = 0. 787 · 1 + 0. 213 · 0 = 0. 787 E(X i^2 ) = 0. 787 · 12 + 0. 213 · 02 = 0. 787 var(Xi) = E(X i^2 ) − E(Xi)^2 = 0. 167631 stddev(Xi) =
var(Xi) = 0. 409428
Now, let A 1000 = 10001
i=1 Xi. Then the Central Limit theorem gives E(A 1000 ) = E(Xi) = 0. 787 var(A 1000 ) = var(Xi)/1000 = 0. 000167631 stddev(A 1000 ) =
var(A 1000 = 0. 0129472
The quantity 8A 1000 estimates the area. We have:
E(8A 1000 ) = 8E(A 1000 ) = 6. 296 var(8A 1000 ) = 64var(A 1000 ) = 0. 0107284 stddev(8A 1000 ) =
var(A 1000 ) = 0. 103578
We can use this to make a confidence intervals for our estimated area. For example, with one-sigma (68%) confindence, the estimate will be within 0.103578 of the true value; with two-sigma (95%) confidence, our estimated area will be within 2 · 0 .103578 = 0.207 of the true area.