We say x is a normal or Gaussian random variable with parameter mu and sigma^2if
ID: 3406222 • Letter: W
Question
We say x is a normal or Gaussian random variable with parameter mu and sigma^2if its density function is given by: f(x; mu, sigma^2) = 1/Squareroot 2 pi sigma^2 e^-(x - mu)^2/2 simga^2 and its distribution function is given by: F(x; mu, sigma^2) = integral_-infinity^x f(y; mu, sigma^2) dy We can express F(x; mu, sigma^2) in term of the error function (erf) as follows: F(x; mu, sigma^2) = 1/2 erf(x - mu/Squareroot 2 sigma^2) = 1/2 The probability density function (pdf) and cumulative distribution function (cdf) of normal distribution can be calculated using two built-in functions norm pdf and normcdf in matlab. Write two Matlab function on your own based on above equations, one for calculating normal pdf and one for calculating normal cdf. (treating x, mu, sigma^2 as inputs of the functions) With x=[-6, 6], plot the pdf and cdf for the following pairs of (mu, sigma^2):(0, 1), (0, 10^-1), (0, 10^-2), (-3, 1), (3, 10^-1), (-3, 10^-2). (Please plot them in two figures: one contains all the pdf curves, and one contains all the cdf curves) What can you observe about the affect of mu and sigma^2 on normal pdf and cdf curves?Explanation / Answer
Answer a:
Mu = input('Mean of the function');
Sigma = input('Enter deviation ');
x = -6:0.0001:6;
g = g_d(Mu,Sigma);
c = c_d(Mu,Sigma);
function g = g_d(Mu,Sigma)
a = 1/sqrt(2*3.1412*Sigma*Sigma);
g1 = (x - Mu)/(sqrt(2)*Sigma);
g = a*exp(-(g1*g1));
plot(x,g);
end
function c = c_d(Mu,Sigma)
b = (x - Mu) / (sqrt(2*Sigma*Sigma));
c = 0.5*(1 + erf(b));
plot(x,c);
end
Answer b:
x = -6:0.0001:6;
function g = g_d(Mu,Sigma)
a = 1/sqrt(2*3.1412*Sigma*Sigma);
g1 = (x - Mu)/(sqrt(2)*Sigma);
g = a*exp(-(g1*g1));
plot(x,g);
end
function c = c_d(Mu,Sigma)
b = (x - Mu) / (sqrt(2*Sigma*Sigma));
c = 0.5*(1 + erf(b));
plot(x,c);
end
u1 = 0, s1 = 1,u2=0,s2=0.1,u3=0,s3=0.01,u4=-3,s4=1,u5=-3,s5=0.1,u6=-3,s6=0.01;
figure 1
subplot(2,3,1);
y1 = g_d(u1,s1);
plot(x,y1);
subplot(2,3,2);
y2 = g_d(u2,s2);
plot(x,y2);
subplot(2,3,3);
y3 = g_d(u3,s3);
plot(x,y3);
subplot(2,3,4);
y4 = g_d(u4,s4);
plot(x,y4);
subplot(2,3,5);
y5 = g_d(u5,s5);
plot(x,y5);
subplot(2,3,6);
y6 = g_d(u6,s6);
plot(x,y6);
figure 2
subplot(2,3,1);
z1 = c_d(u1,s1);
plot(x,z1);
subplot(2,3,2);
z2 = c_d(u2,s2);
plot(x,z2);
subplot(2,3,3);
z3 = c_d(u3,s3);
plot(x,z3);
subplot(2,3,4);
z4 = c_d(u4,s4);
plot(x,z4);
subplot(2,3,5);
z5 = c_d(u5,s5);
plot(x,z5);
subplot(2,3,6);
z6 = c_d(u6,s6);
plot(x,z6);
Answer c:
effect of u shift the plot in axis accordinly and sigma effects in spreadness of the plot / function. More the value of sigma more spread.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.