Integrate a polynomial in Python

Polynomial integration is a fundamental mathematical operation. In Python, the numpy.polynomial.polynomial.polyint() method integrates polynomial coefficients efficiently. The coefficients represent a polynomial from low to high degree, so [1, 2, 3] represents 1 + 2*x + 3*x².

Syntax

numpy.polynomial.polynomial.polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0)

Parameters

  • c ? 1-D array of polynomial coefficients, ordered from low to high degree
  • m ? Order of integration (default: 1)
  • k ? Integration constant(s) (default: [])
  • lbnd ? Lower bound of the integral (default: 0)
  • scl ? Scaling factor applied after each integration (default: 1)
  • axis ? Axis over which the integral is taken (default: 0)

Basic Integration Example

Let's integrate the polynomial 1 + 2x + 3x² ?

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

# Create polynomial coefficients for 1 + 2x + 3x²
coefficients = np.array([1, 2, 3])

print("Original polynomial coefficients:", coefficients)
print("Polynomial: 1 + 2x + 3x²")

# Integrate the polynomial
integrated = P.polyint(coefficients)
print("\nIntegrated coefficients:", integrated)
print("Integrated polynomial: 0 + 1x + 1x² + 1x³")
Original polynomial coefficients: [1 2 3]
Polynomial: 1 + 2x + 3x²

Integrated coefficients: [0. 1. 1. 1.]
Integrated polynomial: 0 + 1x + 1x² + 1x³

Integration with Custom Constant

You can specify an integration constant using the k parameter ?

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

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

# Integrate with constant k=5
integrated_with_constant = P.polyint(coefficients, k=5)
print("With integration constant k=5:", integrated_with_constant)

# Multiple integration (m=2) with constants
double_integrated = P.polyint(coefficients, m=2, k=[2, 3])
print("Double integration with k=[2, 3]:", double_integrated)
With integration constant k=5: [5. 1. 1. 1.]
Double integration with k=[2, 3]: [2.         3.         0.5        0.33333333 0.25      ]

Multiple Order Integration

The m parameter controls the order of integration ?

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

coefficients = np.array([6, 4, 2])  # 6 + 4x + 2x²

print("Original coefficients:", coefficients)

# First order integration
first_order = P.polyint(coefficients, m=1)
print("First order integration:", first_order)

# Second order integration
second_order = P.polyint(coefficients, m=2)
print("Second order integration:", second_order)
Original coefficients: [6 4 2]
First order integration: [0. 6. 2. 0.66666667]
Second order integration: [0.         0.         3.         0.66666667 0.16666667]

Comparison

Parameter Purpose Example
m=1 Single integration [1,2,3] ? [0,1,1,1]
k=5 Add constant [1,2,3] ? [5,1,1,1]
m=2 Double integration [1,2,3] ? [0,0,0.5,0.33,0.25]

Conclusion

The polyint() method provides flexible polynomial integration with support for multiple orders, integration constants, and scaling factors. Use m for integration order and k for integration constants.

Updated on: 2026-03-26T19:36:46+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements