"Dian " <dian.nel@noenergy.com> wrote in message
news:k4jobo$dqi$1@newscl01ah.mathworks.com...
> Why is that I get zero when integrating a normal pdf which we know should
> give 1. Can someone please help me.
>
> mu = 100;
> sigma = 0.005;
>
> % z = @(x) normpdf(x,mu,sigma); %or
> z = @(x) 1/(sigma * sqrt(2*pi)) * exp( 0.5 * ( (x  mu)/sigma ).^2 );
>
> CDF = quad(z,1000,1000,1e7) %or
This attempts to evaluate your function at seven points in its first
iteration:
x =
Columns 1 through 4
1000 728.42 456.84
0
Columns 5 through 7
456.84 728.42
1000
At each of those points, the value of z underflows to 0 due to your small
value of sigma. Therefore to QUAD, your function "looks like" the constant
zero function and the integral of the constant zero function over any
interval is 0.
When I evaluate your expression symbolically for x = 0, I find that z(0) is
exp(200000000) or about 3.3211592146887327878e86858895. That's pretty
small. At x = 1000 it's even worse, z(1000) is exp(16200000000).
If I integrate over the region on which your function does NOT underflow to
0, say in the region 99 to 101, I receive a result that's close to 1.

Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
