Open In App

Evaluate a Chebyshev series at points x in Python

Last Updated : 25 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to Evaluate a Chebyshev series at points x in Python. Numpy package provides us with the chebyshev.chebval() method to evaluate a Chebyshev series at points x.

Syntax: polynomial.chebyshev.chebval(x, c, tensor=True)

Parameters:

  • x: array like object.If x is a list or tuple, it will be converted to an ndarray; otherwise, it will be regarded as a scalar. In any scenario, x or its elements must be able to add and multiply among themselves as well as with the elements of c.
  • c: array like object. The coefficients for terms of degree n are stored in c[n], which is an array of coefficients sorted so that the coefficients for terms of degree n are contained in c[n]. The remaining indices enumerate numerous polynomials if c is multidimensional. The coefficients in the two-dimensional example can be thought of as being stored in the columns of c.
  • tensor: option parameter, boolean value. If True, the coefficient array’s structure is stretched to the right with ones, one for each dimension of x. For this action, scalars have no dimension.

Returns: an array is returned. 

The value returned is:

p(x)= c0*T0(x)+c1*T1(x)+c2*T2(x)+c3*T3(x)+....cn*Tn(x)

The Chebyshev Polynomials of the First Kind

  • T0(x) = 1
  • T1(x) = x
  • T2(x) = 2x^2 -1
  • T3(x) = 4x^3 − 3^x
  • T4(x) = 8x^4 − 8x^2 + 1
  • T5(x) = 16x^5 − 20x^3 + 5x

Example 1:

Import the required packages. create an array which is c which is the array of coefficients. the shape, dimension and datatype of the array is found using the .shape, .dimension and .dtype attributes.polynomial.chebyshev.chebval() method is used to evaluate the Chebyshev series.

Python3

# import packages
import numpy as np
from numpy.polynomial import chebyshev as Chev
 
# Creating an array
array = np.array([3, 1, 4])
print(array)
 
# shape of the array is
print("Shape of the array is : ", array.shape)
 
# dimension of the array
print("The dimension of the array is : ", array.ndim)
 
# Datatype of the array
print("Datatype of our Array is : ", array.dtype)
 
# evaluating Chebyshev series
print(Chev.chebval(1, array))

                    

Output:

[3 1 4]
Shape of the array is :  (3,)
The dimension of the array is :  1
Datatype of our Array is :  int64
8.0

Example 2:

when we change the x value the value changes. T2(x) = 2x^2 -1    is the function used when x is 2. the function changes as the x value changes. 

2(3)^2-1 +2(1)^2-1 +2(4)^2-1 = 33

Python3

# import packages
import numpy as np
from numpy.polynomial import chebyshev as Chev
 
# Creating an array
array = np.array([3, 1, 4])
print(array)
 
# shape of the array is
print("Shape of the array is : ", array.shape)
 
# dimension of the array
print("The dimension of the array is : ", array.ndim)
 
# Datatype of the array
print("Datatype of our Array is : ", array.dtype)
 
# evaluating Chebyshev series
print(Chev.chebval(2, array))

                    

Output:

[3 1 4]
Shape of the array is :  (3,)
The dimension of the array is :  1
Datatype of our Array is :  int64
33.0


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads