Convert a Chebyshev series to a polynomial in Python

PythonNumpyServer Side ProgrammingProgramming

To convert a Chebyshev series to a polynomial, use the chebyshev.cheb2poly() method in Python Numpy. Convert an array representing the coefficients of a Chebyshev series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the “standard” basis) ordered from lowest to highest degree.

The method returns a 1-D array containing the coefficients of the equivalent polynomial ordered from lowest order term to highest. The parameter c, is a 1-D array containing the Chebyshev series coefficients, ordered from lowest order term to highest.

Steps

At first, import the required library −

import numpy as np
from numpy import polynomial as P

Create an array using the numpy.array() method −

c = np.array([1, 2, 3, 4, 5])

Display the array −

print("Our Array...\n",c)

Check the Dimensions −

print("\nDimensions of our Array...\n",c.ndim)

Get the Datatype −

print("\nDatatype of our Array object...\n",c.dtype)

Get the Shape −

print("\nShape of our Array object...\n",c.shape)

To convert a Chebyshev series to a polynomial, use the chebyshev.cheb2poly() method −

print("\nResult (chebyshev to polynomial)...\n",P.chebyshev.cheb2poly(c))

Example

import numpy as np
from numpy import polynomial as P

# Create an array using the numpy.array() method
c = np.array([1, 2, 3, 4, 5])

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To convert a Chebyshev series to a polynomial, use the chebyshev.cheb2poly() method in Python Numpy
print("\nResult (chebyshev to polynomial)...\n",P.chebyshev.cheb2poly(c))

Output

Our Array...
   [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(5,)

Result (chebyshev to polynomial)...
   [ 3. -10. -34. 16. 40.]
raja
Updated on 01-Mar-2022 06:52:36

Advertisements