AMSC/CMSC 660
Quiz 4
,
Fall 2006
1. (10) Write
Matlab
code using
rand
to generate a random number from
the following distribution:
The probability that the number is 0 is 0.6.
The probability that the number is 1 is 0.4.
(In other words, if
p
(
x
) is the probability density function, then
p
(0) = 0
.
6
and
p
(1) = 0
.
4
.)
Answer:
% In this code,
%
z is a sample from a uniform distribution on [0,1].
%
y is a sample from the desired distribution.
z = rand(1);
if (z < .6)
y = 0;
else
y = 1;
end
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
2.
(10) Write
Matlab
code to compute the volume of the unit sphere
x
2
1
+
x
2
2
+
x
2
3
≤
1 using Monte Carlo integration. (You may use any of our
three methods, although I suggest not using importance sampling because it
is harder to write down.)
Answer:
Here are implementations of “Method 1” (5 lines of
Matlab
code)
and “Method 2” (8 lines of code).
% "Method 1":
We compute the volume of the unit sphere
% as 8 times the volume of the piece of it in the 1st orthant
% (x_1 >= 0, x_2 >= 0, x_3 >= 0).
Call this piece Omega.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '06
 oleary
 Normal Distribution, Unit Circle, Probability theory, probability density function, Cumulative distribution function

Click to edit the document details