- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Integrate a polynomial in Python

To Integrate a polynomial, use the polynomial.polyint() method in Python. Returns the polynomial 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 argument c is an array of coefficients, from low to high degree along each axis, e.g., [1,2,3] represents the polynomial 1 + 2*x + 3*x**2 while [[1,2],[1,2]] represents 1 + 1*x + 2*y + 2*x*y if axis=0 is x and axis=1 is y.

The method returns the coefficient array of the integral. The 1st parameter, c is a 1-D array of polynomial coefficients, ordered from low to high. The 2nd parameter, m is Order of integration, must be positive. (Default: 1). The 3rd parameter, k is Integration constant(s). The value of the first integral at zero is the first value in the list, the value of the second integral at zero 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 is scl. Following each integration the result is multiplied by scl before the integration constant is added. (Default: 1). The 6th parameter is axis. It's the axis over which the integral is taken. (Default: 0).

## Steps

At first, import the required libraries −

import numpy as np from numpy.polynomial import polynomial as P

Create an array of polynomial coefficients −

c = np.array([1,2,3])

Display the coefficient array −

print("Our coefficient Array...\n",c)

Check the Dimensions −

print("\nDimensions of our Array...\n",c.ndim)

Get the Datatype −

print("\nDatatype of our Array object...\n",c.dtype)

Get the Shape −

print("\nShape of our Array object...\n",c.shape)

To Integrate a polynomial, use the polynomial.polyint() method in Python −

print("\nResult...\n",P.polyint(c))

## Example

import numpy as np from numpy.polynomial import polynomial as P # Create an array of polynomial coefficients c = np.array([1,2,3]) # Display the coefficient array print("Our coefficient Array...\n",c) # Check the Dimensions print("\nDimensions of our Array...\n",c.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",c.dtype) # Get the Shape print("\nShape of our Array object...\n",c.shape) # To Integrate a polynomial, use the polynomial.polyint() method in Python print("\nResult...\n",P.polyint(c))

## Output

Our coefficient Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [0. 1. 1. 1.]

- Related Questions & Answers
- Integrate a polynomial and set the order in Python
- Integrate a polynomial and set the Integration constant in Python
- Integrate a polynomial and set the lower bound of the integral in Python
- Integrate a polynomial and multiply the result by a scalar before the integration constant is added in Python
- Integrate a Laguerre series in Python
- Integrate a Hermite series in Python
- Integrate a Hermite_e series in Python
- Integrate a Chebyshev series in Python
- Integrate a Legendre series in Python
- Differentiate a polynomial in Python
- Raise a polynomial to a power in Python
- Integrate a Hermite series over axis 0 in Python
- Integrate a Chebyshev series over specific axis in Python
- Integrate a Chebyshev series over axis 0 in Python
- Integrate a Chebyshev series over axis 1 in Python