quiz4 and ans

quiz4 and ans - AMSC/CMSC 660 Quiz 4 , Fall 2006 1. (10)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 02/05/2008 for the course CMSC 660 taught by Professor Oleary during the Fall '06 term at Maryland.

Page1 / 3

quiz4 and ans - AMSC/CMSC 660 Quiz 4 , Fall 2006 1. (10)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online