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.
The numpy.polynomial.legendre.legder() method from the NumPy library is used to differentiate a Legendre series and set the derivatives in Python. The Legendre series coefficients c differed m times along the axis are returned. The result is multiplied by scl at each iteration . The c argument is an array of coefficients ranging in degree from low to high along each axis, such as [4,3,2]. indicates the series 4 *L 0 + 3*L 1 + 2*L 2, whereas [[2,1],[2,1]] indicates 2 *L 0(x)*L 0(y) + 2*L 1(x)*L 0(y) + 1*L 0(x)*L 1(y) + 1*L 1(x)*L 1(y) .If axis=0 is x and axis=1 is y.
Syntax: polynomial.legendre.legder(c, m=1, scl=1, axis=0)
- c: array like object.
- m: int , optional. The total number of derivatives taken must not be negative. It is set to 1 by default.
- axis: optional value, int. The axis on which the derivative is computed. It is set to 0 by default.
Returns: Legendre series of the derivative.
Here, we will create a NumPy array and use polynomial.legendre.legder() to differentiate a Legendre series where the series is an array of coefficients. The shape of the array is found by the .shape attribute, the dimension of the array is found by .ndim attribute, and the data type of the array is .dtype attribute.
[10 20 30 40] Shape of the array is : (4,) The dimension of the array is : 1 [ 90. 600.]
In this example, a 2d array of Coefficients is given as input and the axis parameter is given a value of ‘1’ which specifies that the derivative is computed on the columns.
[[10 20] [30 40]] Shape of the array is : (2, 2) The dimension of the array is : 2 [[20.] [40.]]