Evaluate a Laguerre series at multidimensional array of points x in Python

To evaluate a Laguerre series at multi-dimensional array of points x, use the polynomial.laguerre.lagval() method in Python NumPy. This function allows you to evaluate Laguerre polynomials efficiently across multiple dimensions.

Function Parameters

The lagval() function accepts three parameters:

  • x: The evaluation points. If x is a list or tuple, it is converted to an ndarray. The elements must support addition and multiplication operations.
  • c: Array of coefficients where c[n] contains coefficients for terms of degree n. For multidimensional arrays, remaining indices enumerate multiple polynomials.
  • tensor: Boolean parameter (default True). When True, evaluates every column of coefficients for every element of x. When False, x is broadcast over columns of c.

Basic Example

Let's start with a simple example using a 2D array of evaluation points ?

import numpy as np
from numpy.polynomial import laguerre as L

# Create coefficient array for Laguerre series
coefficients = np.array([1, 2, 3])

print("Coefficients:", coefficients)
print("Dimensions:", coefficients.ndim)
print("Shape:", coefficients.shape)

# Create 2D array of evaluation points
x_points = np.array([[1, 2], [3, 4]])
print("Evaluation points:\n", x_points)

# Evaluate Laguerre series
result = L.lagval(x_points, coefficients)
print("Result:\n", result)
Coefficients: [1 2 3]
Dimensions: 1
Shape: (3,)
Evaluation points:
 [[1 2]
 [3 4]]
Result:
 [[-0.5 -4. ]
 [-4.5 -2. ]]

Understanding the Calculation

The Laguerre series with coefficients [1, 2, 3] represents the polynomial: 1×L?(x) + 2×L?(x) + 3×L?(x), where L?, L?, L? are the first three Laguerre polynomials ?

import numpy as np
from numpy.polynomial import laguerre as L

# Define coefficients
coeffs = np.array([1, 2, 3])

# Single point evaluation
x_single = 2.0
result_single = L.lagval(x_single, coeffs)
print(f"L(2) = {result_single}")

# Multiple points
x_multiple = np.array([0, 1, 2, 3])
result_multiple = L.lagval(x_multiple, coeffs)
print("Results for x = [0, 1, 2, 3]:")
print(result_multiple)
L(2) = -4.0
Results for x = [0, 1, 2, 3]:
[ 6.   -0.5 -4.  -4.5]

Multidimensional Coefficients

You can evaluate multiple Laguerre series simultaneously using multidimensional coefficient arrays ?

import numpy as np
from numpy.polynomial import laguerre as L

# Multiple series with different coefficients
coeffs_2d = np.array([[1, 2], [2, 1], [3, 0]])
print("Coefficient matrix:\n", coeffs_2d)

x_vals = np.array([1, 2, 3])
result_2d = L.lagval(x_vals, coeffs_2d)
print("Results for multiple series:\n", result_2d)
Coefficient matrix:
 [[1 2]
 [2 1]
 [3 0]]
Results for multiple series:
 [[-0.5  3. ]
 [-4.   0. ]
 [-4.5 -3. ]]

Tensor Parameter Effect

The tensor parameter controls how the evaluation is performed for multidimensional inputs ?

import numpy as np
from numpy.polynomial import laguerre as L

coeffs = np.array([[1, 2], [0, 1]])
x_vals = np.array([1, 2])

# With tensor=True (default)
result_tensor_true = L.lagval(x_vals, coeffs, tensor=True)
print("With tensor=True:\n", result_tensor_true)

# With tensor=False
result_tensor_false = L.lagval(x_vals, coeffs, tensor=False)
print("With tensor=False:\n", result_tensor_false)
With tensor=True:
 [[1. 2.]
 [1. 2.]]
With tensor=False:
 [1. 2.]

Conclusion

The lagval() function provides an efficient way to evaluate Laguerre series at multiple points simultaneously. Use multidimensional coefficient arrays to evaluate multiple series, and control the evaluation behavior with the tensor parameter.

Updated on: 2026-03-26T20:32:14+05:30

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements