Strange behavior in integral function in MATLAB

I create two functions fx and fy as follows:

fx = @(x) ncx2pdf(x, 10, 1); fy = @(y) ncx2pdf(y + 25, 10, 10); 

Then I define the fs function as follows:

 shift = 0 fs = @(s) fx(s) .* fy(shift - s) 

Note that fs is always positive (the product of two probability density functions). If I calculated:

 integral(fs, -Inf, 100) 

I get the true value 0.0413, but if I calculated

 integral(fs, -Inf, 1000) 

I get 0. Why does this weird behavior happen using an integral function? Please note that if I calculated

 integral(fs, -Inf, Inf) 

I get the true value of 0.0413.

+5
source share
1 answer

โ€œThe numerical quadrature works by iteratively splitting the interval and approximating the integral of each partition. The approximation is done by discretizing the subintervals and using some form of integral approximation (Riemann sum, etc.). Since there is some discretization, there will be some error, and this depends on the partition so weโ€™re best at limiting the limits of integration closer to the points that will make the greatest contribution to the integral. " Brendan Hamm

Link: http://www.mathworks.com/matlabcentral/answers/242910-strange-behaviour-in-integral-function-in-matlab#answer_192302

-1
source

All Articles