Differentiate a Legendre series using NumPy in Python
Last Updated :
01 May, 2022
In this article, we will cover how to differentiate a Legendre series in Python using NumPy.
legendre.legder method
In python, the Legendre module provides many functions like legder to perform arithmetic, and calculus operations on the Legendre series. It is one of the functions provided by the Legendre class. This method is used to generate the Legendre series and this method is available in the NumPy module in python, it returns a multi-dimensional coefficient array, Below is the syntax of the legder method.
Syntax: legendre.legder(x, m, axis)
Parameter:
- x: a list or tuple.
- m: Number of derivatives taken, must be non-negative. (Default: 1).
- axis: Axis over which the derivative is taken. (Default: 0).
Return: Legendre series
Example 1:
In this example, we are creating an array of 5 x 3 and, displaying the shape and dimensions of an array. Also, we are using legendre.legder() method to differentiate a Legendre series.
Python3
# import the numpy module
import numpy
# import legendre
from numpy.polynomial import legendre
# create array of coefficients with 5 elements each
coefficients_data = numpy.array(
[[1, 2, 3, 4, 5], [3, 4, 2, 6, 7], [43, 45, 2, 6, 7]])
# Display the coefficients
print(coefficients_data)
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
# using legendre.legder() method to differentiate
# a legendre series.
print("\nDifferentiated legendre series", legendre.legder(coefficients_data))
Output:
[[ 1 2 3 4 5]
[ 3 4 2 6 7]
[43 45 2 6 7]]
Shape of an array: (3, 5)
Dimension: 2
Differentiated legendre series [[ 3. 4. 2. 6. 7.]
[129. 135. 6. 18. 21.]]
Example 2:
In this example, we are creating an array of 5 x 2 and, displaying the shape and dimensions of an array. Also, we are using the number of derivatives=2, and the axis over which the derivative is taken is 1.
Python3
# import the numpy module
import numpy
# import legendre
from numpy.polynomial import legendre
# create array of coefficients with 5 elements each
coefficients_data = numpy.array([[1, 2, 3, 4, 5],
[43, 45, 2, 6, 7]])
# Display the coefficients
print(coefficients_data)
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
# using legendre.legder() method to differentiate
# a legendre series.
print("\nDifferentiated legendre series",
legendre.legder(coefficients_data, m=2, axis=1))
Output:
[[ 1 2 3 4 5]
[43 45 2 6 7]]
Shape of an array: (2, 5)
Dimension: 2
Differentiated legendre series [[ 59. 60. 175.]
[ 76. 90. 245.]]
Similar Reads
Differentiate a Legendre series and set the derivatives using NumPy in Python In this article, we will cover how to differentiate a Legendre series and set the derivatives using NumPy in Python. numpy.polynomial.legendre.legder The numpy.polynomial.legendre.legder() method from the NumPy library is used to differentiate a Legendre series and set the derivatives in Python. The
3 min read
Differentiate a Chebyshev series using NumPy in Python In this article, we will cover how to integrate a Chebyshev series and set the integration constant in Python using NumPy. chebyshev.chebder method The Chebyshev series has polynomials with the largest possible leading coefficient, whose absolute value on the interval [â1, 1] is bounded by 1. They a
3 min read
Integrate a Legendre series over axis 0 using NumPy in Python In this article, we will cover how to integrate a Legendre series over axis 0 using NumPy in Python. polynomial.legendre.legint method The polynomial.legendre.legint() method from the NumPy library is used to Integrate a Legendre series over axis 0 in python.The resulting series is multiplied by scl
3 min read
Differentiate a Hermite series in Python In this article, we will be looking at the step-wise procedure to differentiate a Hermite series in Python. Differentiate a Hermite series in Python: Here, we need to call the np.hermder() function from the NumPy package. And pass the parameter, the first parameter will be the c, which is an array o
2 min read
Integrate a Hermite_e series Over Axis 0 using Numpy in Python In this article, we will cover how to integrate a Hermite_e series over axis 0 using NumPy in Python. NumPy e.hermeint() method We use the hermite e.hermeint() function present in the NumPy module of python to integrate a Hermite e series. The first parameter 'arr' is an array of coefficients from
2 min read