Saturday, December 28, 2024
Google search engine
HomeLanguagesEvaluate 2-D Hermite series on the Cartesian product of x and y...

Evaluate 2-D Hermite series on the Cartesian product of x and y with 1d array of coefficient using NumPy in Python

In this article, we will discuss how to Evaluate a 2-D Hermite series on the Cartesian product of x and y with a 1d array of coefficients in Python using NumPy.

NumPy.polynomial.hermite.hermgrid2d method

Hermite polynomials are significant in approximation theory because the Hermite nodes are used as matching points for optimizing polynomial interpolation. To perform the Hermite cartesian product, NumPy provides a function called Hermite.hermgrid2d which can be used to evaluate the cartesian product of the 1D Hermite series. This function converts the parameters x and y to array only if they are tuples or a list, otherwise, it is left unchanged and, if it is not an array, it is treated as a scalar.

Syntax: polynomial.hermite.hermgrid2d(x, y, c)

Parameters:

  • x,y: array_like
  • c: array of coefficients

Returns: Two dimensional polynomials at points as cartesian products of x and y.

Example 1:

In the first example. let us consider a 1D array c that has 5 elements.  Let us consider a 2D series [1,2],[1,2] to evaluate against the 1D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.

Python3




import numpy as np
from numpy.polynomial import hermite
  
# coefficient array
c = np.array([1, 2, 3, 4, 5])
  
print(f'The co.efficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
  
# evaluating 1d co.eff array with a 2d
# hermite series
res = hermite.hermgrid2d([1, 2], [1, 2], c)
  
# resultant array
print(f'Resultant series ---> {res}')


Output:

The co.efficient array is [1 2 3 4 5]
The shape of the array is (5,)
The dimension of the array is 1D
The datatype of the array is int64
Resultant series ---> [1077. 2259.]

Example 2:

In the first example. let us consider a 1D array c that has 10 elements.  Let us consider a 2D series [2,1],[2,1] to evaluate against the 1D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.

Python3




import numpy as np
from numpy.polynomial import hermite
  
# coefficient array
c = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  
print(f'The co.efficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
  
# evaluating 1d coeff array with a 2d
# hermite series
res = hermite.hermgrid2d([2, 1], [2, 1], c)
  
# resultant array
print(f'Resultant series ---> {res}')


Output:

The co.efficient array is [ 1  2  3  4  5  6  7  8  9 10]
The shape of the array is (10,)
The dimension of the array is 1D
The datatype of the array is int64
Resultant series ---> [-45325. 189045.]

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments