MATLAB: Area under gaussian curve between two known points

gaussianintegratingintegrating gaussian function

Hi All,
I have another question.
How can you calculate the area underneath a gaussian curve? (Between two know points).
-2.5 <X<2.5
Y=-2e^(-(x)^2)
I have tried gaussmf. But I do not have licience for it.
Thank you
H

Best Answer

You use normcdf. Found in the stats toolbox.
diff(normcdf([-2.5 2.5]))
ans =
0.987580669348448
If you lack that toolbox (IMHO, not a good idea, as it is one of multiple toolboxes that I find terrbibly valuable) then you can do it using a transformation of the special function erf:
erftrans = @(x) (erf(x/sqrt(2)) +1)/2
erftrans =
function_handle with value:
@(x)(erf(x/sqrt(2))+1)/2
diff(erftrans([-2.5 2.5]))
ans =
0.987580669348448
And if you want a Gaussian with some other mean and variance than the standard N(0,1), that too is just a simple transformation away, or even less effort, as long as you have the stats toolbox.