Python Forum

Full Version: Finding out roots of Chebyshev's polynomials
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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

``````Output:[1.0]
[]
[0.0, 1.0]
[]
[-1.0, 0.0, 2.0]
[ 1.41421356 -1.41421356]``````
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?

```for n in range(10):