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 3D Legendre series at points (x,y,z) with 2D array of coefficient in Python
To evaluate a 3D Legendre series at points (x,y,z), use the polynomial.legendre.legval3d() method in Python NumPy. The method returns the values of the multidimensional polynomial on points formed with triples of corresponding values from x, y, and z.
If the coefficient array c has fewer than 3 dimensions, ones are implicitly appended to its shape to make it 3D. The shape of the result will be c.shape[3:] + x.shape.
Syntax
numpy.polynomial.legendre.legval3d(x, y, z, c)
Parameters
x, y, z: The three dimensional series is evaluated at the points (x, y, z), where x, y, and z must have the same shape. If any of x, y, or z is a list or tuple, it is first converted to an ndarray.
c: Array of coefficients ordered so that the coefficient of the term of multidegree i,j,k is contained in c[i,j,k]. If c has dimension greater than 3, the remaining indices enumerate multiple sets of coefficients.
Example
Let's create a 2D array of coefficients and evaluate the 3D Legendre series ?
import numpy as np
from numpy.polynomial import legendre as L
# Create a 2D array of coefficients
c = np.arange(4).reshape(2,2)
# 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)
# Evaluate 3D Legendre series at points x, y, z
print("\nResult...\n", L.legval3d([1,2], [1,2], [1,2], c))
Our Array... [[0 1] [2 3]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [24. 42.]
How It Works
When the coefficient array c has only 2 dimensions (2,2), NumPy automatically extends it to 3D by adding a dimension. The evaluation computes the Legendre polynomial values at each point using the coefficient matrix.
For points [1,2] in each dimension, the method calculates the corresponding polynomial values [24., 42.].
Conclusion
The legval3d() method efficiently evaluates 3D Legendre series at specified points. It automatically handles dimension extension for coefficient arrays and returns polynomial values at the given coordinate points.
