Reference no: EM13860284
The purpose of this assignment is to investigate a Monte Carlo Simulation to numerically calculate the area under a Gaussian PDF as in Figure 8.10-a of your text (the Q(y) function).
One of the most useful methods to determine the integral of function that cannot be performed in closed form are the so-called Monte Carlo methods. For the particular method that we are using here, matlab will generate a large number of gaussian distributed random numbers. The fraction of these numbers greater than a value. y will be the value of Q(y).
This works because the PDF for a gaussian is normalized, ie ∞∫∞Px(x)dx = 1
To generate a 1 dimensional array of gaussian random numbers in matlab use the randn(M,N) function.
For example to generate 10000 random numbers we can use
If we want to determine the number of values of x that are greater than zero we can use code similar to the following
x0=x ./abs(x); % converts the array elements to ±1
x1=(x0+1)/2; % converts the array elements to 1s and 0s
n0 = (z1*ones(N,1))/N;
% n0 is the fraction of array elements that are greater than 0
Of course, due to the symmetry of the pdf, the answer should be .5. Implementing this code should give one confidence that the method works. Note that the answer might not come out to be .5 unless N is big enough. Try for N=10, N=100, N=1000, N=10000;, N=100000;
N=1000000, and N=10000000;
randn(M, N) generates gaussian random numbers with 0 mean and unity variance. To change to a mean in and variance a. remember the new sequence can be formed form the orginal sequence, x, by
σx(x + m)
To compare to a value y rather than 0, just subtract y from the random variables and test for greater than zero.
1. Complete the code for arbitrary, m, σx and y.
2. Test when m = 0, σx = 1, and y = 0 and various N's to verify your answer is .5.
3. Rerun part 2 when σx = .01, .1, 10, and 100. Are your results what you expect? Why or why not?
4. Test when m = 5, σx = 1, and y = 5, 7, 9, 11. Are your results what you expect? Why or why not?
5. Reran part 5 when σx = .01, .1, 10, and 100. Are your results what you expect? Why or why not?
Note: this should be implemented using no for loops.