MATLAB 中积分函数的奇怪行为

Strange behaviour in integral function in MATLAB

我创建了两个函数 fx 和 fy,如下所示:

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

然后,我定义fs函数如下:

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

请注意,fs 始终为正(两个概率密度函数的乘积)。如果我计算:

integral(fs, -Inf, 100)

我得到真值0.0413,但是如果我计算

integral(fs, -Inf, 1000)

我得到0。为什么使用积分函数会发生这种奇怪的行为?请注意,如果我计算

integral(fs, -Inf, Inf) 

我得到真值0.0413.

"Numeric quadrature works by iteratively splitting the interval apart and approximating the integral of each partition. The approximation is done by discretizing the subintervals and using some form of integral approximation (Riemann sums etc.). Since there is some discretization, there will be some error and this is dependent on the partitioning, therefore we are best to keep our limits of integration closer to the points which will contribute most to the integral."、布伦丹·哈姆

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