quiz4 and ans

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

• Homework Help
• PresidentHackerCaribou10582
• 3

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

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.

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern