Improper Integrals & Numerical Integration Methods
Improper Integrals
Improper integrals are integrals with either infinite limits or discontinuous integrands. 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
- If is convergent and over , then is also convergent.
- Conversely, if is divergent and over , then is also divergent.
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 is a more accurate method that uses parabolic arcs to approximate the function between each pair of points. It requires the number of subintervals to be even.
The approximation given by Simpson's Rule is:
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):
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):
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 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.