Matlab积分的不连续性

Discontinuity in Matlab integral

我正在尝试在 Matlab 中对不连续函数进行数值积分。

fun = @(z) 1./((z+1).^2+4) * 1./(exp(-z)-1);
q = integral(fun,-Inf,Inf,'Waypoints',[0])

z=0 处有不连续性,但我不确定如何使用 Waypoints 选项来指定它。我收到一条错误消息:

Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.4e-01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.

如何准确计算这个积分?

来自文档 "Use waypoints to indicate any points in the integration interval that you would like the integrator to use."

可能是该等式中您不想使用零的唯一点....因为该函数在该值处未定义(它的左边和右边的极限不同,因此它不是无限的,它未定义)。

Wolfram Alpha claims that the integral does not exists.

所以,当 MATLAB 说

"The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy"

它是....因为它可能不存在!


我猜你总是可以这样做:

q = integral(fun,-Inf,-0.001)+integral(fun,0.001,Inf);

但我不确定这有多正确....

为@Ander Biguri 的正确答案添加备注。

还有其他具有奇异性的函数,例如1/((x+1)*sqrt(x))(看improper integrals

integral(@(x) 1./((x+1).*sqrt(x)), 0, inf)

ans =

    3.1416

甚至与不在积分范围边界处的奇点收敛的函数

integral(@(x) 1./(x.^2).^(1/3), -1, 1)

ans =

    6.0000

所以 MATLAB 做的一切都是正确的。你的函数不收敛。

也许您对 Cauchy's principal value 感兴趣,但这是另一个话题。