我创建了两个函数 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。
“数值求积的工作原理是迭代地分割区间并近似每个分区的积分。近似是通过离散子区间并使用某种形式的积分近似(黎曼和等)来完成的。由于存在一些离散化,因此将有存在一些误差,这取决于划分,因此我们最好使积分限制更接近对积分贡献最大的点。”,Brendan Hamm