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 Laguerre series at points x in Python
To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in NumPy. This function takes coefficients and evaluation points to compute Laguerre polynomial values.
Syntax
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
x: Points where the series is evaluated. Can be a scalar, list, or array.
c: Array of coefficients ordered so that coefficients for terms of degree n are in c[n]. For multidimensional arrays, remaining indices enumerate multiple polynomials.
tensor: If True (default), extends coefficient array shape for broadcasting. If False, x is broadcast over columns of c.
Basic Example
Let's evaluate a simple Laguerre series at a single point ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create coefficients array [1, 2, 3]
# Represents: 1*L?(x) + 2*L?(x) + 3*L?(x)
coefficients = np.array([1, 2, 3])
print("Coefficients:", coefficients)
print("Evaluating at x = 1:")
result = L.lagval(1, coefficients)
print("Result:", result)
Coefficients: [1 2 3] Evaluating at x = 1: Result: -0.5
Multiple Points Evaluation
You can evaluate the series at multiple points simultaneously ?
import numpy as np
from numpy.polynomial import laguerre as L
coefficients = np.array([1, 2, 3])
x_points = np.array([0, 0.5, 1, 2])
print("Coefficients:", coefficients)
print("Evaluation points:", x_points)
results = L.lagval(x_points, coefficients)
print("Results:", results)
Coefficients: [1 2 3] Evaluation points: [0. 0.5 1. 2. ] Results: [ 6. 1.375 -0.5 -5. ]
Multidimensional Coefficients
For multiple polynomials, use a 2D coefficient array where each column represents a different polynomial ?
import numpy as np
from numpy.polynomial import laguerre as L
# Two polynomials: [1,2,3] and [0,1,2]
coefficients = np.array([[1, 0], [2, 1], [3, 2]])
x_point = 1
print("Coefficient matrix:")
print(coefficients)
print(f"\nEvaluating at x = {x_point}:")
results = L.lagval(x_point, coefficients)
print("Results for both polynomials:", results)
Coefficient matrix: [[1 0] [2 1] [3 2]] Evaluating at x = 1: Results for both polynomials: [-0.5 -1. ]
Understanding Laguerre Polynomials
The first few Laguerre polynomials are:
- L?(x) = 1
- L?(x) = 1 - x
- L?(x) = 1 - 2x + x²/2
import numpy as np
from numpy.polynomial import laguerre as L
# Verify L?(1) = 1 - 1 = 0
result_L1 = L.lagval(1, [0, 1]) # Only L? term
print("L?(1) =", result_L1)
# Verify L?(1) = 1 - 2(1) + 1²/2 = -0.5
result_L2 = L.lagval(1, [0, 0, 1]) # Only L? term
print("L?(1) =", result_L2)
L?(1) = 0.0 L?(1) = -0.5
Conclusion
The lagval() function efficiently evaluates Laguerre series at given points using coefficient arrays. It supports both single and multiple polynomial evaluation, making it useful for scientific computing applications involving Laguerre polynomials.
