# Integrate a Legendre series over axis 1 in Python

PythonNumpyServer Side ProgrammingProgramming

To integrate a Legendre series, use the polynomial.legendre.legint() method in Python. The method returns the Legendre series coefficients c integrated m times from lbnd along axis. At each iteration the resulting series is multiplied by scl and an integration constant, k, is added. The scaling factor is for use in a linear change of variable.

The 1st parameter, c is an array of Legendre series coefficients. If c is multidimensional the different axis correspond to different variables with the degree in each axis given by the corresponding index. The 2nd parameter, m is an order of integration, must be positive. (Default: 1). The 3rd parameter, k is an integration constant(s). The value of the first integral at lbnd is the first value in the list, the value of the second integral at lbnd is the second value, etc. If k == [] (the default), all constants are set to zero. If m == 1, a single scalar can be given instead of a list.

The 4th parameter, lbnd is the lower bound of the integral. (Default: 0). The 5th parameter, scl is a scalar. Following each integration the result is multiplied by scl before the integration constant is added. (Default: 1). The 6th parameter, axis is an Axis over which the integral is taken. (Default: 0).

## Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import legendre as L

Create a multidimensional array of coefficients −

c = np.arange(4).reshape(2,2)

Display the array −

print("Our Array...
",c)

Check the Dimensions −

print("
Dimensions of our Array...
",c.ndim)

Get the Datatype −

print("
Datatype of our Array object...
",c.dtype)

Get the Shape −

print("
Shape of our Array object...
",c.shape)

To integrate a Legendre series, use the polynomial.legendre.legint() method in Python −

print("
Result...
",L.legint(c, axis = 1))

## Example

import numpy as np
from numpy.polynomial import legendre as L

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...
",c)

# Check the Dimensions
print("
Dimensions of our Array...
",c.ndim)

# Get the Datatype
print("
Datatype of our Array object...
",c.dtype)

# Get the Shape
print("
Shape of our Array object...
",c.shape)

# To integrate a Legendre series, use the polynomial.legendre.legint() method in Python
print("
Result...
",L.legint(c, axis = 1))

## Output

Our Array...
[[0 1]
[2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
[[0.16666667 0. 0.33333333]
[0.5 2. 1. ]]
Updated on 09-Mar-2022 05:41:17