Ekuation

purpose

Numerical Integration Calculator

Compare Simpson's rule, trapezoidal rule, and midpoint rule for numerical integration with method comparison.

Back to Integral Calculator
Your figures

Enter a mathematical expression using x as the variable.

Details: Most accurate (O(h^4))

Number of subdivisions for the numerical calculation.

Number of rectangles shown in the visualization.

Compute an Integral

Enter a function f(x) with bounds and click Calculate to see the numerical integral, error estimate, and interactive Riemann sum visualization.

The plate is drawn once you enter your figures.

Try an Example

Pick a scenario to see how the calculator works, then adjust the values

  1. Basic Polynomial

    Integrate x^2 from 0 to 1 using Simpson's rule. Exact answer: 1/3.

    Key values: x^2 · [0, 1] · Simpson's rule

  2. Trigonometric Integral

    Integrate sin(x) from 0 to pi. Exact answer: 2.

    Key values: sin(x) · [0, pi] · Exact: 2

  3. Area Under a Bell Curve

    Approximate the Gaussian integral e^(-x^2) from -3 to 3.

    Key values: e^(-x^2) · [-3, 3] · Gaussian

Documentation

Why Numerical Integration?

Many integrals have no closed-form antiderivative. Classic examples include:

∫e−x2dx∫sin⁡xx dx∫1+x3 dx\int e^{-x^2} dx \qquad \int \frac{\sin x}{x} \, dx \qquad \int \sqrt{1 + x^3} \, dx

For these functions, and for data given as discrete points (e.g., experimental measurements), numerical methods are the only option.


Method Comparison

MethodError orderFunction evalsBest for
Left/Right RiemannO(h)O(h)nConceptual understanding
Midpoint ruleO(h2)O(h^2)nQuick estimates
Trapezoidal ruleO(h2)O(h^2)n + 1Equally spaced data
Simpson's ruleO(h4)O(h^4)n + 1 (n even)Smooth functions
Gaussian quadratureO(h2n)O(h^{2n})nMaximum accuracy per eval

Here h=Δx=(b−a)/nh = \Delta x = (b-a)/n is the step size. Doubling nn (halving hh) cuts Simpson's error by a factor of 16, vs. only 4 for the trapezoidal rule.


Error Bounds

The error in each method depends on the function's higher derivatives:

∣ET∣≤(b−a)312n2max⁡∣f′′(x)∣(Trapezoidal)|E_T| \leq \frac{(b-a)^3}{12n^2} \max |f''(x)| \quad \text{(Trapezoidal)}
∣ES∣≤(b−a)5180n4max⁡∣f(4)(x)∣(Simpson’s)|E_S| \leq \frac{(b-a)^5}{180n^4} \max |f^{(4)}(x)| \quad \text{(Simpson's)}

Key insight: Simpson's rule is exact for polynomials of degree ≤ 3, even though it only uses parabolic approximations. This is because the error term depends on the 4th derivative, which is zero for cubics.


Adaptive Quadrature

Fixed-step methods waste evaluations on smooth regions and may miss sharp features. Adaptive quadrature automatically refines the step size where the function changes rapidly:

  1. Estimate the integral with nn intervals
  2. Re-estimate with 2n2n intervals
  3. If the estimates agree within tolerance, accept
  4. Otherwise, subdivide and recurse on each half

This is how production numerical libraries (SciPy, MATLAB) integrate functions efficiently.


Frequently Asked Questions

When do I need numerical integration?

Numerical integration is necessary when the integrand has no closed-form antiderivative (e.g., e−x2e^{-x^2}, sin⁡xx\frac{\sin x}{x}, 1+x3\sqrt{1 + x^3}), when you have discrete data points rather than a formula, or when the antiderivative is too complex to evaluate by hand.

Which numerical integration method should I use?

Simpson's rule is the best default for smooth functions due to its O(h4)O(h^4) convergence. Use the trapezoidal rule for equally spaced experimental data or periodic functions. Use the midpoint rule when the function has endpoint singularities.

What is the difference between O(h2)O(h^2) and O(h4)O(h^4) convergence?

O(h2)O(h^2) means halving the step size reduces the error by a factor of 4. O(h4)O(h^4) means halving the step size reduces the error by a factor of 16. Simpson's rule (O(h4)O(h^4)) converges much faster than trapezoidal or midpoint rules (O(h2)O(h^2)).

What is adaptive quadrature?

Adaptive quadrature automatically refines the step size in regions where the function changes rapidly while using fewer evaluations where the function is smooth. This is the approach used by production libraries like SciPy and MATLAB.

Can Simpson's rule integrate polynomials exactly?

Yes, Simpson's rule is exact for polynomials of degree 3 or less, even though it uses parabolic (degree 2) approximations. This is because the error bound depends on the fourth derivative, which is zero for cubics.

Plate

Related purpose calculators

Other purpose variations of this calculator

Further plates

More Math calculators

Explore the category

Calculator Search

Search and find calculators