用python求Chebyshev多项式的根

2024-10-01 22:44:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用Python求任意阶Chebysev多项式的根。我看过勒让德多项式的similar threads。但是,我已经使用定义为here的方法构造了多项式

import numpy as np 
import sympy as sp 

f0 = lambda x: chebyt(0,x)
f1 = lambda x: chebyt(1,x)
f2 = lambda x: chebyt(2,x)
f3 = lambda x: chebyt(3,x)
f4 = lambda x: chebyt(4,x)
plot([f0,f1,f2,f3,f4],[-1,1])

我尝试使用np.roots(f4),但收到以下错误:TypeError: float() argument must be a string or a number, not 'function'。另外,it seems that即使我可以,它也不适用于高阶多项式。你知道吗


Tags: lambdaimporthere定义asnpf2f1
1条回答
网友
1楼 · 发布于 2024-10-01 22:44:06

您可以通过使用标题为“基本求值”here下的方法来查找切比雪夫多项式的系数,然后使用反向列表上的^{}来生成多项式的根。你知道吗

使用np.roots(f4)无效,因为roots函数只接受多项式系数列表,而不是lambda函数。你知道吗

代码:

from mpmath import chebyt, chop, taylor
import numpy as np

for n in range(5):
    print(np.roots(chop(taylor(lambda x: chebyt(n, x), 0, n))[::-1]))

输出:

[]
[0.]
[ 0.70710678 -0.70710678]
[ 0.8660254 -0.8660254  0.       ]
[-0.92387953  0.92387953 -0.38268343  0.38268343]

希望有帮助。你知道吗

相关问题 更多 >

    热门问题