Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Evaluate a Hermite series at tuple of points x in Python
To evaluate a Hermite series at points x, use the hermite.hermval() method in Python NumPy. This function evaluates a Hermite polynomial series at given points using the coefficients provided.
Syntax
hermite.hermval(x, c, tensor=True)
Parameters
The function accepts three parameters ?
- x − If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. The elements must support addition and multiplication with themselves and with the elements of c.
- c − An array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If c is multidimensional, the remaining indices enumerate multiple polynomials.
- tensor − If True (default), the shape of the coefficient array is extended with ones on the right, one for each dimension of x. If False, x is broadcast over the columns of c for the evaluation.
Example
Let's create a simple Hermite series evaluation ?
import numpy as np
from numpy.polynomial import hermite as H
# Create an array of coefficients
c = np.array([1, 2, 3])
# 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)
# Here, x is a tuple
x = (5, 10, 15)
# To evaluate a Hermite series at points x, use the hermite.hermval() method
print("\nResult...\n", H.hermval(x, c))
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [ 315. 1235. 2755.]
How It Works
The Hermite series is evaluated using the formula: H(x) = c[0] + c[1]*H?(x) + c[2]*H?(x) + ... where H?, H?, etc. are Hermite polynomials of increasing degree.
Example with Different Input Types
You can also evaluate the series with scalar input ?
import numpy as np
from numpy.polynomial import hermite as H
# Same coefficients
c = np.array([1, 2, 3])
# Scalar input
x_scalar = 5
result_scalar = H.hermval(x_scalar, c)
print("Result for scalar x=5:", result_scalar)
# Array input
x_array = np.array([1, 2, 3])
result_array = H.hermval(x_array, c)
print("Result for array x=[1,2,3]:", result_array)
Result for scalar x=5: 315.0 Result for array x=[1,2,3]: [15. 47. 99.]
Conclusion
The hermite.hermval() function efficiently evaluates Hermite polynomial series at single points, tuples, or arrays. It's particularly useful for mathematical computations involving Hermite polynomials in scientific applications.
