# Contradiction in Variance and Standard deviation values in Octave

I am defining a Normal Distribution in Octave by using this command "y = normpdf(x,0,2)". The standard deviation is 2 and x is independent uniform variable values. When I calculate standard deviation from std(y) then I do not get answer 2. Why is that so ?

• What is the distribution of x? Commented Aug 7, 2016 at 12:10
• Can you add a full reproducible example, i.e., containing also code that generates x Commented Aug 7, 2016 at 12:15
• @Juho : x = (-5:0.01:5); y = normpdf(x); std_y = std(y) Commented Aug 7, 2016 at 12:28

normpdf(X,0,2) returns the probability density function at all values of X (be it a scalar, vector, or matrix) of a Normal random variable having mean = 0 and standard deviation = 2.

It does not return sample (simulated) values of such a Normal random variable. For that, either

A) use normrnd

or

B) generate uniform random variables and use them as arguments for the inverse Normal cdf.

So here is what I think you wanted to do:

>> % Method A
>> % Generates 1e6 Normal random numbers with mean 0, standard deviation 2
>> y = normrnd(0,2,1e6,1);
>> disp(std(y))
1.9994


or

>> % Method B
>> % Generate 1e6 U[0,1} r.v.s, apply inverse normal CDF, and multiply by standard deviation
>> u = rand(1e6,1);
>> y = 2*norminv(u);
>> disp(std(y))
1.9991


Edit: Here is a plot of what you generated, which of course is the pdf:

>> x=-5:.01:5;
>> plot(x,normpdf(x,0,2))