laguerre多项式似乎没有以某些顺序收敛,运行以下代码可以证明这一点。在
import numpy as np
from sympy import mpmath as mp
from scipy.special import genlaguerre as genlag
from sympy.mpmath import laguerre as genlag2
from matplotlib import pyplot as plt
def laguerre(x, r_ord, phi_ord, useArbitraryPrecision=False):
if (r_ord < 30 and phi_ord < 30) and not useArbitraryPrecision:
polyCoef = genlag(r_ord, phi_ord)
out = np.polyval(polyCoef, x)
else:
fun = lambda arg: genlag2(r_ord, phi_ord, arg)
fun2 = np.frompyfunc(genlag2, 3, 1)
# fun2 = np.vectorize(fun)
out = fun2(r_ord, phi_ord, x)
return out
r_ord = 29
phi_ord = 29
f = lambda x, useArb : mp.log10(laguerre(x, 29, 29, useArb))
mp.plot(lambda y : f(y, True) - f(y, False), [0, 200], points = 1e3)
plt.show()
如果有人知道函数的精确性是什么?你建议我只使用mpmath
函数吗?一开始我想可能是在特定的命令之后它不起作用,但是对于(100,100),它似乎工作得很好。在
通过跑步
^{pr2}$您可以看到下面的图像,其中的差异变得非常明显。在
感谢任何帮助。在
如果有什么需要澄清的,请告诉我。在
将
polyval
与高阶多项式(大约n > 20
)一起使用通常是个坏主意,因为使用系数(以幂为基础)来计算多项式将开始在高阶浮点中产生较大误差。Scipy文档中的warning试图告诉您这一点。在您应该使用};它使用更稳定的数值算法来计算多项式。在
scipy.special.eval_genlaguerre(r_ord, phi_ord, float(x))
而不是{不要像pv建议的那样使用
scipy.special.eval_genlaguerre
来计算高次多项式,还可以使用numpy.polynomial.Laguerre
,如{a1}中所述。在不幸的是,它似乎没有为广义拉盖尔多项式提供函数。在
NumPy输出:0,0.5,2,4.5,8
相关问题 更多 >
编程相关推荐