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
Generate a Vandermonde matrix of the Laguerre polynomial in Python
To generate a pseudo Vandermonde matrix of the Laguerre polynomial, use the laguerre.lagvander() function in Python NumPy. The method returns the pseudo-Vandermonde matrix with shape x.shape + (deg + 1,), where the last index corresponds to the degree of the Laguerre polynomial. The dtype will match the converted x array.
The parameter x is an array of points, converted to float64 or complex128 depending on whether elements are complex. If x is scalar, it converts to a 1-D array. The parameter deg specifies the degree of the resulting matrix.
Syntax
numpy.polynomial.laguerre.lagvander(x, deg)
Parameters
The function accepts the following parameters ?
- x ? Array of points (scalar converted to 1-D array)
- deg ? Degree of the resulting matrix (non-negative integer)
Creating the Vandermonde Matrix
Let's create a complete example showing how to generate the Laguerre Vandermonde matrix ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create an array of points
x = np.array([0, 1, -1, 2])
# Display the array
print("Our Array...")
print(x)
# Check array properties
print("\nDimensions:", x.ndim)
print("Datatype:", x.dtype)
print("Shape:", x.shape)
# Generate Vandermonde matrix of degree 2
result = L.lagvander(x, 2)
print("\nVandermonde Matrix (degree 2):")
print(result)
Our Array... [ 0 1 -1 2] Dimensions: 1 Datatype: int64 Shape: (4,) Vandermonde Matrix (degree 2): [[ 1. 1. 1. ] [ 1. 0. -0.5] [ 1. 2. 3.5] [ 1. -1. -1. ]]
Understanding the Output
Each row corresponds to evaluating Laguerre polynomials L?(x), L?(x), L?(x) at each point ?
import numpy as np
from numpy.polynomial import laguerre as L
x = np.array([0, 1, -1, 2])
# Generate degree 3 matrix for more examples
result = L.lagvander(x, 3)
print("Vandermonde Matrix (degree 3):")
print(result)
print(f"\nMatrix shape: {result.shape}")
print(f"Each row evaluates L?, L?, L?, L? at x values")
Vandermonde Matrix (degree 3): [[ 1. 1. 1. 1. ] [ 1. 0. -0.5 -0.5 ] [ 1. 2. 3.5 4.5 ] [ 1. -1. -1. 0. ]] Matrix shape: (4, 4) Each row evaluates L?, L?, L?, L? at x values
Different Input Types
The function works with different array types and shapes ?
import numpy as np
from numpy.polynomial import laguerre as L
# Float array
x_float = np.array([0.5, 1.5, 2.5])
result_float = L.lagvander(x_float, 2)
print("Float input result:")
print(result_float)
# 2D array input
x_2d = np.array([[0, 1], [2, 3]])
result_2d = L.lagvander(x_2d, 1)
print(f"\n2D input shape: {x_2d.shape}")
print(f"Result shape: {result_2d.shape}")
print("Result:")
print(result_2d)
Float input result: [[ 1. 0.5 -0.125] [ 1. -0.5 -0.625] [ 1. -1.5 -0.625]] 2D input shape: (2, 2) Result shape: (2, 2, 2) Result: [[[ 1. 1.] [ 1. 0.]] [[ 1. 1.] [ 1. -2.]]]
Conclusion
The lagvander() function generates pseudo-Vandermonde matrices for Laguerre polynomials, useful in polynomial fitting and numerical analysis. The resulting matrix evaluates Laguerre polynomials L? through L_deg at each input point.
