Evaluate a Laguerre series at points x with multidimensional coefficient array in Python

To evaluate a Laguerre series at points x with a multidimensional coefficient array, use the polynomial.laguerre.lagval() method in Python NumPy. This method allows you to evaluate multiple Laguerre polynomials simultaneously using a 2D coefficient matrix.

Syntax

numpy.polynomial.laguerre.lagval(x, c, tensor=True)

Parameters

The function accepts three parameters ?

  • x − Points at which to evaluate the series. Can be scalar, list, or array
  • c − Coefficient array where coefficients for degree n are in c[n]. For multidimensional arrays, additional indices represent multiple polynomials
  • tensor − Boolean flag controlling evaluation behavior (default True)

Creating and Evaluating Laguerre Series

Let's create a multidimensional coefficient array and evaluate the Laguerre series at specific points ?

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

# Create a multidimensional array of coefficients
coefficients = np.array([[1, 2], [3, 4]])
print("Coefficient Array:")
print(coefficients)
print("\nArray Shape:", coefficients.shape)
print("Array Dimensions:", coefficients.ndim)
Coefficient Array:
[[1 2]
 [3 4]]

Array Shape: (2, 2)
Array Dimensions: 2

Evaluating at Multiple Points

Now we'll evaluate the Laguerre series at points x = [1, 2] using our coefficient matrix ?

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

coefficients = np.array([[1, 2], [3, 4]])
points = [1, 2]

# Evaluate Laguerre series
result = L.lagval(points, coefficients)
print("Evaluation points:", points)
print("Result shape:", result.shape)
print("Result:")
print(result)
Evaluation points: [1, 2]
Result shape: (2, 2)
Result:
[[ 1. -2.]
 [ 2. -2.]]

How It Works

With a 2D coefficient array, each column represents a separate polynomial. The Laguerre polynomial for degree n is defined as:

L?(x) = 1 L?(x) = 1 - x For polynomial: c?L?(x) + c?L?(x)

Understanding the Output

The result matrix shows evaluations for each polynomial column at each input point ?

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

coefficients = np.array([[1, 2], [3, 4]])

# Manual calculation for verification
# First column: [1, 3] ? 1*L?(x) + 3*L?(x) = 1*1 + 3*(1-x) = 4-3x
# Second column: [2, 4] ? 2*L?(x) + 4*L?(x) = 2*1 + 4*(1-x) = 6-4x

print("Manual calculation for x=1:")
print("First polynomial: 4 - 3*1 =", 4 - 3*1)
print("Second polynomial: 6 - 4*1 =", 6 - 4*1)

print("\nNumPy result:")
result = L.lagval([1, 2], coefficients)
print(result)
Manual calculation for x=1:
First polynomial: 4 - 3*1 = 1
Second polynomial: 6 - 4*1 = 2

NumPy result:
[[ 1. -2.]
 [ 2. -2.]]

Conclusion

The lagval() method efficiently evaluates multiple Laguerre polynomials simultaneously using coefficient matrices. Each column represents a different polynomial, and the function returns evaluations for all combinations of points and polynomials.

---
Updated on: 2026-03-26T20:08:05+05:30

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements