DigitHelm
Calculus

Numerical Integration Calculator | Simpson, Gaussian & Trapezoid

Integrate any function f(x) over an interval [a, b] using five methods side-by-side: Trapezoid rule, Simpson's 1/3 rule, Simpson's 3/8 rule, Boole's rule, and 5-point Gaussian quadrature. Compares all results, shows step-by-step working for the selected method, and estimates truncation error.

Instant Results100% FreeAny DeviceNo Sign-up
Use: x, sin, cos, tan, exp, log, sqrt, abs, PI, E, pow(x,n)

What Is the Numerical Integration Calculator | Simpson, Gaussian & Trapezoid?

Numerical integration approximates a definite integral ∫ₐᵇ f(x) dx when an analytic antiderivative is unavailable or expensive. All Newton-Cotes methods (Trapezoid, Simpson, Boole) divide [a,b] into n equal subintervals and combine weighted function values. Gaussian quadrature places nodes at optimal (non-equally-spaced) positions to achieve maximum accuracy for a given number of function evaluations.

Formula

∫ₐᵇ f(x) dx ≈ T (Trapezoid) ≈ S₁/₃ (Simpson 1/3) ≈ S₃/₈ (Simpson 3/8) ≈ B (Boole) ≈ G (Gaussian)

How to Use

  1. 1

    Type your function in the f(x) field using standard math notation: sin(x), exp(x), x*x, log(x), sqrt(x), etc.

  2. 2

    Enter the lower limit a and upper limit b of integration.

  3. 3

    Enter n, the number of subintervals. The calculator auto-adjusts n for each method as needed.

  4. 4

    Click "Integrate" to run all five methods simultaneously.

  5. 5

    Compare results in the table — methods with higher accuracy should agree closely.

  6. 6

    Click any row to view the evaluation points x_i and f(x_i) for that method.

  7. 7

    Use the preset buttons for known exact answers to verify accuracy.

Enter f(x) as a JavaScript-style expression (use x as the variable), the interval limits a and b, and the number of subintervals n. Click Integrate to see all five methods in parallel. Click any row in the results table to view step-by-step evaluation points for that method.

Example Calculation

∫₀¹ x² dx: exact = 1/3 ≈ 0.333333. With n=10: Trapezoid = 0.335000 (error ≈ 0.0017), Simpson 1/3 = 0.333333 (exact for polynomials ≤ degree 3), Boole = 0.333333, Gaussian = 0.333333. For ∫₀^π sin(x) dx = 2.0: with n=10 Trapezoid gives 1.983524, Simpson 1/3 gives 2.000007.

Understanding Numerical Integration | Simpson, Gaussian & Trapezoid

Method comparison

Methodn requirementError orderPoints usedBest for
TrapezoidAny n ≥ 1O(h²)n+1 equally spacedRough estimates, smooth functions
Simpson's 1/3n evenO(h⁴)n+1 equally spacedGeneral purpose, cubic polynomials exact
Simpson's 3/8n multiple of 3O(h⁴)n+1 equally spacedGroups of 3 intervals
Boole's Rulen multiple of 4O(h⁶)n+1 equally spacedHigh accuracy, degree 5 polynomials exact
Gaussian 5-ptFixed 5 pointsO(h¹⁰)5 Gaussian nodesDegree 9 polynomials exact, smooth functions

5-point Gaussian quadrature nodes and weights

iNode tᵢ (on [−1,1])Weight wᵢRole
1−0.90617984590.2369268851Outer left
2−0.53846931010.4786286705Inner left
300.5688888889Centre (highest weight)
4+0.53846931010.4786286705Inner right
5+0.90617984590.2369268851Outer right

To integrate over [a, b]: x = ((b−a)t + a+b)/2, scale factor = (b−a)/2. Sum of all weights = 2 (for [−1,1]).

When to use each method

  • Trapezoid rule: Use when you only have function values at equally spaced points, or when a rough answer is acceptable. Also use for periodic functions where it can achieve spectacular accuracy.
  • Simpson's 1/3 rule: The default choice for most problems: 4th-order accuracy with minimal complexity. Exact for polynomials up to degree 3. Requires an even number of subintervals.
  • Simpson's 3/8 rule: Useful when you need to combine with Simpson 1/3 to handle any n, or when your data naturally comes in groups of 3 intervals.
  • Boole's rule: Choose when you need 6th-order accuracy and can provide n as a multiple of 4. Exact for polynomials up to degree 5. Delivers roughly 100× smaller error than trapezoid for the same n.
  • Gaussian quadrature: Best when the integrand is smooth and analytic. Achieves 10th-order accuracy with only 5 function evaluations. Cannot be used when function values at specific equally spaced points are required (it picks its own optimal nodes).

Frequently Asked Questions

What is the difference between Simpson's 1/3 and 3/8 rules?

Both are Newton-Cotes formulas with O(h⁴) error. Simpson's 1/3 uses pairs of subintervals (n must be even) with coefficients 1, 4, 2, 4, 2, …, 4, 1 scaled by h/3. Simpson's 3/8 uses triples of subintervals (n multiple of 3) with coefficients 1, 3, 3, 2, 3, 3, …, 1 scaled by 3h/8. In practice, Simpson's 1/3 is more widely used; 3/8 is useful for combining with 1/3 to handle any n.

Why does Gaussian quadrature need so few points for high accuracy?

Gaussian quadrature selects both the node positions and weights optimally (using roots of Legendre polynomials). A k-point Gaussian rule is exact for all polynomials up to degree 2k−1. The 5-point rule is exact for degree 9 polynomials. Equally-spaced Newton-Cotes methods of order n are only exact up to degree n (or n+1 for even n). The trade-off is that Gaussian nodes cannot be reused if n is increased.

How do I write the function expression correctly?

Use JavaScript math syntax: multiplication requires * (write x*x not x²), exponentiation uses pow(x,n) or x**n. Available functions: sin, cos, tan, exp, log (natural log), sqrt, abs. Constants: PI (= π), E (= e). Examples: sin(x)*exp(-x), pow(x,3)+2*x, 1/(1+x*x), sqrt(1-x*x). The calculator wraps your expression in a safe Function constructor — no external libraries are needed.

What is error order and how fast does accuracy improve with n?

Error order O(hᵏ) means the error scales as hᵏ where h = (b−a)/n is the step size. Doubling n (halving h) reduces the Trapezoid error by 4×, Simpson errors by 16×, and Boole errors by 64×. For the Trapezoid rule the error ≈ −h²(b−a)/12 × f''(ξ); for Simpson 1/3 it is −h⁴(b−a)/180 × f⁽⁴⁾(ξ) for some ξ ∈ [a,b].

You Might Also Like

Explore 360+ Free Calculators

From math and science to finance and everyday life — all free, no account needed.