Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
quad and integration

Subject: quad and integration

From: Dian

Date: 4 Oct, 2012 10:28:08

Message: 1 of 2

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,1e-7) %or
%CDF = quad(z,-Inf,Inf,1e-7)

>>CDF =

     0

 

Subject: quad and integration

From: Steven_Lord

Date: 4 Oct, 2012 13:18:19

Message: 2 of 2



"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,1e-7) %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.3211592146887327878e-86858895. 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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us