Improper Integrals and Numerical Integration
An improper integral uses a limit at infinity or at an unbounded singularity. A bounded function with finitely many jump discontinuities can be an ordinary Riemann integral; a discontinuity alone does not make it improper. In the definitions below, every truncated integral must exist, and convergence means that each required limit exists and is finite. See Paul Dawkins’s improper-integral treatment.
In the power-tail test assume . Near zero the criterion is different: converges exactly when . For , integrate to get and take the relevant endpoint limit; for , use . Thus
But diverges. Comparison gives another useful case: for , so its tail converges. The compared functions must be integrable on finite truncated intervals.
Do not cancel infinities across a singularity. For on , the left and right integrals diverge. Equal cutoffs give zero, but that is a Cauchy principal value, not convergence of the improper integral.
Improper Integrals
Improper integrals are integrals with either infinite limits or unbounded singularities. They help extend the concept of integration beyond the traditional bounds. Here's how they are defined and evaluated:
Infinite Limits
-
Integral from a to infinity:
-
Integral from negative infinity to b:
-
Integral from negative infinity to infinity:
Discontinuous Integrand
-
Discontinuity at a:
-
Discontinuity at b:
-
Discontinuity within the interval (a < c < b):
Comparison Test for Improper Integrals
For nonnegative functions on :
- If and converges, then also converges.
- If and diverges, then also diverges.
Useful Fact
For , the integral converges if and diverges for .
Numerical Integration Methods
Numerical integration methods are used to approximate the value of a definite integral when it is difficult or impossible to calculate it analytically. The following are common numerical integration rules:
Midpoint Rule
The Midpoint Rule estimates the integral of a function by summing the value of the function at the midpoint of each interval, multiplied by the width of the intervals.
For subintervals, the approximation is:
where and is the midpoint of the -th subinterval.
Trapezoid Rule
The Trapezoid Rule calculates the integral by averaging the function values at the endpoints of each interval, effectively estimating the area under the curve using trapezoids.
The formula is:
Simpson's Rule
Simpson's Rule uses a quadratic through three consecutive sample points on each pair of subintervals; for sufficiently smooth functions it has a higher convergence order. It requires the number of subintervals to be even.
The approximation given by Simpson's Rule is:
Open full-size imageOn the left, one quadratic passes through three sampled points across two subintervals. On the right, the construction repeats with another quadratic. These pairs explain why composite Simpson integration needs an even number of subintervals. Compare the curved tops with the flat rectangles and straight trapezoid edges described above.
Practical Use
These rules are particularly useful in Computer Science for solving problems that require numerical solutions, such as in simulations, optimization problems, and areas where the function cannot be integrated symbolically.
Implementation
Here are Python functions that implement each of these rules:
import numpy as np
def midpoint_rule(f, a, b, n):
if isinstance(n, bool) or not isinstance(n, int) or n <= 0:
raise ValueError("n must be a positive integer")
dx = (b - a) / n
x_mid = np.linspace(a + dx/2, b - dx/2, n)
return np.sum(f(x_mid)) * dx
def trapezoid_rule(f, a, b, n):
if isinstance(n, bool) or not isinstance(n, int) or n <= 0:
raise ValueError("n must be a positive integer")
dx = (b - a) / n
x = np.linspace(a, b, n + 1)
return dx/2 * np.sum(f(x[:-1]) + f(x[1:]))
def simpsons_rule(f, a, b, n):
if isinstance(n, bool) or not isinstance(n, int) or n <= 0:
raise ValueError("n must be a positive integer")
if n % 2 == 1:
raise ValueError("n must be even for Simpson's Rule")
dx = (b - a) / n
x = np.linspace(a, b, n + 1)
y = f(x)
return dx/3 * np.sum(y[0:-1:2] + 4*y[1::2] + y[2::2])
Notes:
fis the integrand function.aandbare the limits of integration.nis the number of subintervals.dxis the width of each subinterval.- For
simpsons_rule, an even number of subintervals is necessary.
Error bounds and a reproducible check
For , write . The composite-rule error bounds are
The first two require a continuous second derivative bounded in absolute value by ; Simpson requires a continuous fourth derivative bounded by and even . Bounds describe discretization error, not floating-point rounding. Halving the step divides these bounds by 4 or 16. Simpson is exact for cubic polynomials in exact arithmetic, but is not universally more accurate for nonsmooth functions.
For on and , , , , while . The absolute errors are , , and zero, matching the bounds with , . To guarantee trapezoid error at most here, choose .
The implementation requires installed NumPy, finite bounds and a function that accepts an array and returns an array of the same shape. For a constant use lambda x: np.ones_like(x), not lambda x: 1. These are fixed-grid teaching routines, not adaptive singular-integral solvers.
f = lambda x: x**2
assert np.isclose(midpoint_rule(f, 0, 1, 2), 5/16)
assert np.isclose(trapezoid_rule(f, 0, 1, 2), 3/8)
assert np.isclose(simpsons_rule(f, 0, 1, 2), 1/3)
Compare results at to look for convergence, but agreement alone is not a certified bound: a grid can miss a narrow peak. Do not evaluate a singular endpoint with trapezoid or Simpson. Split or transform the integral first. For an infinite interval, truncation adds a separate tail error: replacing by loses exactly , regardless of how fine the grid is.