【问题标题】:Finding the Roots of Chebyshev's polynomials in python在python中找到切比雪夫多项式的根
【发布时间】:2019-12-02 11:12:53
【问题描述】:

我想使用 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 即使我可以,它也不适用于高阶多项式。

【问题讨论】:

    标签: python numpy sympy polynomials mpmath


    【解决方案1】:

    您可以通过使用标题“基本评估”here 下的方法找到切比雪夫多项式的系数,然后在反向列表中使用np.roots 来生成多项式的根。

    使用 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]
    

    希望对您有所帮助。

    【讨论】:

    • 确实有帮助。这是我需要的。但是,正如在此链接 math.stackexchange.com/questions/12160/… 中所评论的那样,似乎根对于高阶多项式可能会失败。你能给我一些建议吗?
    • 抱歉,这个领域不是我的强项——你可能有更好的时间在 math.SE 上提问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2012-08-13
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多