# Integrate Legendre series and set the lower bound of the integral using NumPy in Python

• Last Updated : 02 Jun, 2022

In this article, we will see how to integrate a Legendre series and set the lower bound of the integral in Python using NumPy.

To perform Legendre integration, NumPy provides a function called legendre.legint which can be used to integrate Legendre series.

Syntax: legendre.legint(c, lbnd=0, scl=1, axis=0)

Parameters:

c – Array of Legendre series coefficients.
lbnd – The lower bound of the integral. (Default: 0)
scl – Following each integration the result is multiplied by scl before the integration constant is added. (Default: 1)
axis – Axis over which the integral is taken.

Example 1:

In the first example. let us consider a 1D array with 5 elements with an lbnd set to -2. Import the necessary packages as shown and pass the appropriate parameters as shown below. We are also displaying the shape, dimensions, and data type of created NumPy array.

## Python3

 `import` `numpy as np``from` `numpy.polynomial ``import` `legendre`` ` `# co.efficient array``c ``=` `np.array([``11``, ``12``, ``13``, ``14``, ``15``])`` ` `print``(f``'The shape of the array is {c.shape}'``)``print``(f``'The dimension of the array is {c.ndim}D'``)``print``(f``'The datatype of the array is {c.dtype}'``)`` ` `res ``=` `legendre.legint(c, lbnd``=``-``2``)`` ` `# integrated legendre series``# with  lbnd=-2``print``(f``'Resultant series ---> {res}'``)`

Output:

The shape of the array is (5,)

The dimension of the array is 1D

The datatype of the array is int64

Resultant series —> [220.5          8.4          2.           0.93333333   2.

1.66666667]

Example 2:

In this example. let us consider a 2D array with 5 elements each with a lbnd set to -1. Import the necessary packages as shown and pass the appropriate parameters as shown below. We are also displaying the shape, dimensions, and data type of created NumPy array.

## Python3

 `import` `numpy as np``from` `numpy.polynomial ``import` `legendre`` ` `# co.efficient array``c ``=` `np.array([[``11``, ``12``, ``13``, ``14``, ``15``], ``              ``[``56``, ``55``, ``44``, ``678``, ``89``]])`` ` `print``(f``'The shape of the array is {c.shape}'``)``print``(f``'The dimension of the array is {c.ndim}D'``)``print``(f``'The datatype of the array is {c.dtype}'``)`` ` `res ``=` `legendre.legint(c, lbnd``=``-``1``)`` ` `# integrated legendre series``# with  lbnd=-1``print``(f``'Resultant series ---> {res}'``)`

Output:

The shape of the array is (2, 5)

The dimension of the array is 2D

The datatype of the array is int64

Resultant series —> [[  -7.66666667   -6.33333333   -1.66666667 -212.          -14.66666667]

[  11.           12.           13.           14.           15.        ]

[  18.66666667   18.33333333   14.66666667  226.           29.66666667]]

My Personal Notes arrow_drop_up