Please show all work and your entire code! 6. [15] Generate a Gaussian random va
ID: 2990252 • Letter: P
Question
Please show all work and your entire code!
6. [15] Generate a Gaussian random variable, X, with mean zero and variance 1 using MATLAB's randn function. Let Y = 2X + 5, find the mean and variance of Y both theoretically and through MATLAB using the mean and std functions. Compare your results. Find the correlation coefficient between X and Y both theoretically and through MATLAB using corrcoef function. Compare your results. Verify that Y is also a Gaussian random variable through MATLAB's hist function. Include your code and output results.Explanation / Answer
clc;
clear;
%mean
N = 1000;
x = [-20:20];
samples = 2 + 4*randn(N, 1);
ySamples = histc(samples,x) / N;
temp =0;
for i=1:1000
temp=temp + samples(i);
end
temp=temp/1000
%variance
temp1=0;
for i=1:1000
temp1=(samples(i)-temp)^2+temp1;
end
temp1/1000
%var(samples)
samples1 = 2 + 4*randn(N, 1);
samples4=2* samples1+5 % Y = 2*X +5
ySamples = histc(samples4,x) / N;
yTheoretical = pdf('norm', x, 2, 4);
%plot(x, yTheoretical, x, ySamples)
plot(x, yTheoretical, x, ySamples)
%proved e
% f
%mean
temp =0;
for i=1:1000
temp=temp + samples4(i);
end
mean_f=temp/1000
%variance
temp1=0;
for i=1:1000
temp1=(samples4(i)-mean_f)^2+temp1;
end
variance_f=temp1/1000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.