Write a program (MATLAB) which generates exponential random variables, and use i
ID: 2267149 • Letter: W
Question
Write a program (MATLAB) which generates exponential random variables, and use it to test the Central Limit Theorem as follows. For various values of n (say, 5, 10, 20, 50, 100, 1000), generate samples of the random variable Mn = 1/n iny sum Xi where Xi are iid exponential random variables. A very simple method for generating exponential random variables is given on page 196 of the textbook (read that section). Plot the discretized CDF for Mn (an approximation of the CDF using discrete bins) for each n superimposed on the theoretical Gaussian CDF according to the Central Limit Theorem (or plot them next to each other). Calculate the sample mean and variance according to the material in the book and compare these to the theoretical values. Comment briefly on your results. Show all graphs and calculations. Include a copy of your code. Remember, you will need to generate a large number of samples of Mn for each n in order to get decent histograms. I suggest at least 100+ samples. 100 samples of M1000 require 100,000 exponential samples. You may choose any mean and variance you want for your exponential random numbers, but keep these fixed for all samples so that the results are comparable. Using the program written for the previous problem, repeat the whole experiment, but now choose a random mean and variance for each exponential sample. Thus, the Mn now will not be sums of identically distributed random variables. Show your results and comment. For this case, make sure that the distributions you use to choose your mean and variance at each sample are xed throughout. Write the code in MATLAB.
Explanation / Answer
% Distribution of Random variables % Initialization clear all;clc; % Rate (Exponential Distribution) lambda=4; % Probability for bernoulli distributons prob=0.6; % maximum number of iterations maxItr=10e3; % Uniform Distribution (Linear Congruential Generator, LCG) u=zeros(maxItr,1); for i=1:maxItr % parameters of LCG t = datetime('now'); z=minute(t)+randi([1,10]); c=second(t)+randi([1,10]); m=hour(t)+randi([1,10]); a=second(t)+randi([1,10]); u(i)=(mod((a*z+c),m))/m; end figure histogram(u) % Exponential Distribution % Inverse transform method exp=-log(u)/lambda; figure histogram(exp) % Erlang Distribution sum=0;num_dist=10; for i=1:num_dist % Generate exponential random numbers exp=exprnd(lambda,maxItr,1); sum=sum+exp; end erlang=sum/num_dist; figure histogram(erlang) % Bernoulli Distribution ber(uRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.