Finding out roots of Chebyshev's polynomials - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Finding out roots of Chebyshev's polynomials (/thread-22899.html) |
Finding out roots of Chebyshev's polynomials - player1681 - Dec-02-2019 Hello everyone. I am constructing Chebyshev polinomials as specified here. I have replicated the fisrt part of the code succesfully as: import numpy as np import sympy as sp import mpmath as mp from mpmath import * 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])Now, I need to calculate the roots of said polynomials. I have found the function roots. To use it, I need to calculate the coefficients of the polynomial, that I do using the function dps as defined in the first link; the results are succesful and the coefficients are printed. However, I cannot send said output to roots. This is my code mp.dps = 25; mp.pretty = True for n in range(3): nprint(chop(taylor(lambda x: chebyt(n, x), 0, n))) nprint(np.roots(chop(taylor(lambda x: chebyt(n, x), 0, n))))This returns Which means that the coefficients are propperly calculated, but np.roots doesn't return the roots. Aditionally, I have found the following thread, which indicates that roots eventually fails if the order of the polynomial reaches a high enough number.Can someone please advice me on how to proceed to calculate the roots of a Chebyshev polynomial of order n with some guarantee of doing it well enough? Any answer is welcome. Regards. RE: Finding out roots of Chebyshev's polynomials - player1681 - Dec-02-2019 I have figured out how to do this. My new code is as follows: for n in range(10): nprint(chop(taylor(lambda x: chebyt(n, x), 0, n))) print(np.roots(chop(taylor(lambda x: chebyt(n, x), 0, n))[::-1]))It seems that there was some issue with the function nprint. I hope this is helpful RE: Finding out roots of Chebyshev's polynomials - scidam - Dec-02-2019 It seems that there is exact formula for Chebyshev polynomial roots/nodes. |