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
Subtract one Laguerre series from another in Python
To subtract one Laguerre series from another, use the polynomial.laguerre.lagsub() method in Python NumPy. The method returns an array of Laguerre series coefficients representing their difference c1 - c2. The sequences of coefficients are ordered from lowest order term to highest, i.e., [1,2,3] represents the series P_0 + 2*P_1 + 3*P_2.
Syntax
numpy.polynomial.laguerre.lagsub(c1, c2)
Parameters
The parameters c1 and c2 are 1-D arrays of Laguerre series coefficients ordered from low to high degree.
Example
Let's create two Laguerre series and subtract one from another ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create 1-D arrays of Laguerre series coefficients
c1 = np.array([1, 2, 3])
c2 = np.array([3, 2, 1])
# Display the arrays of coefficients
print("Array1:\n", c1)
print("\nArray2:\n", c2)
# Display the datatype
print("\nArray1 datatype:", c1.dtype)
print("Array2 datatype:", c2.dtype)
# Check the dimensions and shape
print("\nDimensions - Array1:", c1.ndim, "Array2:", c2.ndim)
print("Shape - Array1:", c1.shape, "Array2:", c2.shape)
# Subtract one Laguerre series from another
result = L.lagsub(c1, c2)
print("\nResult (c1 - c2):\n", result)
Array1: [1 2 3] Array2: [3 2 1] Array1 datatype: int64 Array2 datatype: int64 Dimensions - Array1: 1 Array2: 1 Shape - Array1: (3,) Array2: (3,) Result (c1 - c2): [-2. 0. 2.]
Working with Different Length Arrays
The lagsub() method can handle arrays of different lengths ?
import numpy as np
from numpy.polynomial import laguerre as L
# Arrays of different lengths
c1 = np.array([1, 2, 3, 4])
c2 = np.array([1, 1])
print("Array1:", c1)
print("Array2:", c2)
# Subtraction works with different lengths
result = L.lagsub(c1, c2)
print("Result:", result)
Array1: [1 2 3 4] Array2: [1 1] Result: [0. 1. 3. 4.]
How It Works
The subtraction is performed coefficient-wise. For arrays of different lengths, the shorter array is effectively padded with zeros at the higher-order terms. The result represents the coefficients of the polynomial c1 - c2 in Laguerre series form.
Conclusion
Use numpy.polynomial.laguerre.lagsub() to subtract Laguerre series coefficient-wise. The method handles arrays of different lengths automatically and returns the difference as a new coefficient array.
