# Compute the roots of a Chebyshev series with given complex roots using NumPy in Python

• Last Updated : 03 Jun, 2022

In this article, we will see how to compute the roots of a Chebyshev series with given complex roots using NumPy in python.

## chebyshev.chebroots() method

The chebyshev.chebroots() in python that is available in the NumPy module is used to compute the roots of a Chebyshev series with given complex roots in python. The root estimates are obtained as the eigenvalues of the given companion matrix,  Roots with a multiplicity greater than 1 will return larger errors. It will return an array of the roots of the given Chebyshev series. If all the roots are real, then the output is also real, otherwise, the output is it is complex. It will take one parameter coefficient (c) array of 1 Dimensional.

Synatx: polynomial.chebyshev.chebroots(c)

Parameter:

• c: 1-D array of coefficients.

Return: Array of the roots of the series. real/complex.

### Example 1:

In this example, we are creating a complex root – (0,1) as an array of coefficients in a 1D array and get the roots of the Chebyshev series. So the output is complex roots. and also we are displaying the datatype using dtype method and getting the shape using the shape method.

## Python3

 `from` `numpy.polynomial ``import` `chebyshev`` ` `# consider the coefficient``j ``=` `complex``(``2``)`` ` `# datatype``print``(chebyshev.chebroots((``-``j, j)).dtype)`` ` `# shape``print``(chebyshev.chebroots((``-``j, j)).shape)`` ` `# get the roots of chebyshev series``print``(chebyshev.chebroots((``-``j, j)))`

Output:

```(2+0j)
complex128
(1,)
[1.+0.j]```

### Example 2:

In this example, we are creating a complex root – (2,5)  as an array of coefficients in a 1D array and get the roots of the Chebyshev series. So the output is complex roots. and also we are displaying the datatype using dtype method and getting the shape using the shape method.

## Python3

 `from` `numpy.polynomial ``import` `chebyshev`` ` `# consider the coefficient``j ``=` `complex``(``1``,``3``)``print``(j)`` ` `# datatype``print``(chebyshev.chebroots((``-``j, j)).dtype)`` ` `# shape``print``(chebyshev.chebroots((``-``j, j)).shape)`` ` `# get the roots of chebyshev series``print``(chebyshev.chebroots((``-``j, j)))`

Output:

```(1+3j)
complex128
(1,)
[1.+0.j]```

My Personal Notes arrow_drop_up