这种递归关系在数学上很好,但在使用浮点数的有限精度表示来实现算法时数值不稳定.
考虑以下比较:
x = 0:20;
y1 = arrayfun(@(n)besselj(n,1), x); %# builtin function
y2 = arrayfun(@Bessel, x); %# your function
semilogy(x,y1, x,y2), grid on
legend('besselj','Bessel')
title('J_\nu(z)'), xlabel('\nu'), ylabel('log scale')
因此,您可以看到计算值在9之后开始显着不同.
根据MATLAB:
BESSELJ uses a MEX interface to a Fortran library by D. E. Amos.
并提供以下作为其实现的参考:
D. E. Amos, “A subroutine package for Bessel functions of a complex
argument and nonnegative order”, Sandia National Laboratory Report,
SAND85-1018, May, 1985.
D. E. Amos, “A portable package for Bessel functions of a complex argument and nonnegative order”, Trans. Math. Software, 1986.