Question

In: Advanced Math

Matlab Code Illustrate the fact that the average of a large number of independent random variables...

Matlab Code
Illustrate the fact that the average of a large number of independent random variables will approximate a Gaussian by the following:
a) to generate n random integers from a uniform distribution U(xl , xu).
b) to choose xl and xu randomly, in the range −100 ≤ xl < xu ≤ 100 and the number of samples n randomly in the range 0 < n ≤ 1000.
c) Generate and plot a histogram of the accumulation of 10⁴ points sampled as just described.
d) Calculate the mean and standard deviation of your histogram, and plot it.
e) Repeat the above for 10⁵ and 10⁶ points. Discuss your results.

Solutions

Expert Solution

MATLAB Code:

close all
clear
clc

%% N = 1e4 number of samples
fprintf('For N = 10000 samples\n------------------------------------\n')
N_1 = 1e4; % Number of points
samples_1 = [];
while true
xl = randi([-100, 100], 1); % Random number between -100 and 100
xu = randi([-100, 100], 1);
n = randi(1000); % Random number between 1 and 1000
sorted_limits = sort([xl, xu]);
xl = sorted_limits(1); xu = sorted_limits(2);
new_samples = randi([xl, xu], 1, n);
new_length_of_samples = length(samples_1) + length(new_samples);
if new_length_of_samples > N_1
samples_1 = [samples_1, new_samples(1:length(new_samples) - (new_length_of_samples - N_1))];
break
else
samples_1 = [samples_1, new_samples];
end
end
M = mean(samples_1); % Mean
SD = std(samples_1); % Standard deviation
fprintf('Mean = %.8f, Standard Deviation = %.8f\n', M, SD)
figure, hist(samples_1, 1000)
title('Histogram (N = 10000 samples)')

%% N = 1e5 number of samples
fprintf('\nFor N = 100000 samples\n------------------------------------\n')
N_2 = 1e5; % Number of points
samples_2 = [];
while true
xl = randi([-100, 100], 1); % Random number between -100 and 100
xu = randi([-100, 100], 1);
n = randi([0, 1000]); % Random number between 0 and 1000
sorted_limits = sort([xl, xu]);
xl = sorted_limits(1); xu = sorted_limits(2);
new_samples = randi([xl, xu], 1, n);
new_length_of_samples = length(samples_2) + length(new_samples);
if new_length_of_samples > N_2
samples_2 = [samples_2, new_samples(1:length(new_samples) - (new_length_of_samples - N_2))];
break
else
samples_2 = [samples_2, new_samples];
end
end
M = mean(samples_2); % Mean
SD = std(samples_2); % Standard deviation
fprintf('Mean = %.8f, Standard Deviation = %.8f\n', M, SD)
figure, hist(samples_2, 10000)
title('Histogram (N = 100000 samples)')

%% N = 1e6 number of samples
fprintf('\nFor N = 1000000 samples\n------------------------------------\n')
N_3 = 1e6; % Number of points
samples_3 = [];
while true
xl = randi([-100, 100], 1); % Random number between -100 and 100
xu = randi([-100, 100], 1);
n = randi([0, 1000]); % Random number between 0 and 1000
sorted_limits = sort([xl, xu]);
xl = sorted_limits(1); xu = sorted_limits(2);
new_samples = randi([xl, xu], 1, n);
new_length_of_samples = length(samples_3) + length(new_samples);
if new_length_of_samples > N_3
samples_3 = [samples_3, new_samples(1:length(new_samples) - (new_length_of_samples - N_3))];
break
else
samples_3 = [samples_3, new_samples];
end
end
M = mean(samples_3); % Mean
SD = std(samples_3); % Standard deviation
fprintf('Mean = %.8f, Standard Deviation = %.8f\n', M, SD)
figure, hist(samples_3, 100000)
title('Histogram (N = 1000000 samples)')

Output:

For N = 10000 samples
------------------------------------
Mean = -0.98010000, Standard Deviation = 41.28366188

For N = 100000 samples
------------------------------------
Mean = 3.13892000, Standard Deviation = 48.93190457

For N = 1000000 samples
------------------------------------
Mean = -0.01954300, Standard Deviation = 47.89988022

Histograms:

From the last histogram, it can be observed that as we keep on increasing the number of points, the distribution does approach Gaussian.


Related Solutions

Assume that X, Y, and Z are independent random variables and that each of the random...
Assume that X, Y, and Z are independent random variables and that each of the random variables have a mean of 1. Further, assume σX = 1, σY = 2, and σZ = 3. Find the mean and standard deviation of the following random variables: a. U = X + Y + Z b. R = (X + Y + Z)/3 c. T = 2·X + 5·Y d. What is the correlation between X and Y? e. What is the...
Let X and Y be independent Gaussian(0,1) random variables. Define the random variables R and Θ,...
Let X and Y be independent Gaussian(0,1) random variables. Define the random variables R and Θ, by R2=X2+Y2,Θ = tan−1(Y/X).You can think of X and Y as the real and the imaginary part of a signal. Similarly, R2 is its power, Θ is the phase, and R is the magnitude of that signal. (b) Find the probability density functions of R and Θ. Are R and Θ independent random variables?
An insurance company insures large number of independent individual houses. The expected average loss for each...
An insurance company insures large number of independent individual houses. The expected average loss for each house for 1 year period is $600, and the standard deviation of the average loss is $100. Let us assume that the average loss follows the normal distribution. Using Normdist() function in Excel, calculate the probability that the average loss will exceed $850 (show the detailed steps)
Is the quotient of two independent geometric random variables a geometric random variable? If not, what...
Is the quotient of two independent geometric random variables a geometric random variable? If not, what is its distribution?
Previously, you studied linear combinations of independent random variables. What happens if the variables are not...
Previously, you studied linear combinations of independent random variables. What happens if the variables are not independent? A lot of mathematics can be used to prove the following: Let x and y be random variables with means μx and μy, variances σ2x and σ2y, and population correlation coefficient ρ (the Greek letter rho). Let a and b be any constants and let w = ax + by for the following formula. μw = aμx + bμy σ2w = a2σ2x +...
Previously, you studied linear combinations of independent random variables. What happens if the variables are not...
Previously, you studied linear combinations of independent random variables. What happens if the variables are not independent? A lot of mathematics can be used to prove the following: Let x and y be random variables with means μx and μy, variances σ2x and σ2y, and population correlation coefficient ρ (the Greek letter rho). Let a and b be any constants and let w = ax + by for the following formula. μw = aμx + bμy σ2w = a2σ2x +...
1. Let ?1, . . . ?? be ? independent random variables with normal distribution of...
1. Let ?1, . . . ?? be ? independent random variables with normal distribution of expectation 0 and variance ? 2 . Let ?̂︁2 1 be the sample variance ??, ?̂︁2 2 be 1 ? ∑︀ ? ?2 ? . (1) Show that the expectation of ?̂︁2 1 and ?̂︁2 2 are both ? 2 . In other words, both are unbiased point estimates of ? 2 . (2) Write down the p.d.f. of ?̂︁2 1 and ?̂︁2 2....
Which of these statements is false? If two random variables are independent, then their squares are...
Which of these statements is false? If two random variables are independent, then their squares are also independent random variables If the joint pdf of a random vector factorises into the product of functions of the single variables, then the random variables that compose the vector are mutually independent If the covariance between two random variables is zero, the random variables are independent If two random variables are independent, their correlation is always zero If X is independent from Y,...
Let ? and ? be two independent uniform random variables such that ?∼????(0,1) and ?∼????(0,1). A)...
Let ? and ? be two independent uniform random variables such that ?∼????(0,1) and ?∼????(0,1). A) Using the convolution formula, find the pdf ??(?) of the random variable ?=?+?, and graph it. B) What is the moment generating function of ??
Consider independent random variables X1, X2, and X3 such that X1 is a random variable having...
Consider independent random variables X1, X2, and X3 such that X1 is a random variable having mean 1 and variance 1, X2 is a random variable having mean 2 and variance 4, and X3 is a random variable having mean 3 and variance 9. (a) Give the value of the variance of X1 + (1/2)X2 + (1/3)X3 (b) Give the value of the correlation of Y = X1- X2 and Z = X2 + X3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT