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.
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
Type your function in the f(x) field using standard math notation: sin(x), exp(x), x*x, log(x), sqrt(x), etc.
- 2
Enter the lower limit a and upper limit b of integration.
- 3
Enter n, the number of subintervals. The calculator auto-adjusts n for each method as needed.
- 4
Click "Integrate" to run all five methods simultaneously.
- 5
Compare results in the table — methods with higher accuracy should agree closely.
- 6
Click any row to view the evaluation points x_i and f(x_i) for that method.
- 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
| Method | n requirement | Error order | Points used | Best for |
|---|---|---|---|---|
| Trapezoid | Any n ≥ 1 | O(h²) | n+1 equally spaced | Rough estimates, smooth functions |
| Simpson's 1/3 | n even | O(h⁴) | n+1 equally spaced | General purpose, cubic polynomials exact |
| Simpson's 3/8 | n multiple of 3 | O(h⁴) | n+1 equally spaced | Groups of 3 intervals |
| Boole's Rule | n multiple of 4 | O(h⁶) | n+1 equally spaced | High accuracy, degree 5 polynomials exact |
| Gaussian 5-pt | Fixed 5 points | O(h¹⁰) | 5 Gaussian nodes | Degree 9 polynomials exact, smooth functions |
5-point Gaussian quadrature nodes and weights
| i | Node tᵢ (on [−1,1]) | Weight wᵢ | Role |
|---|---|---|---|
| 1 | −0.9061798459 | 0.2369268851 | Outer left |
| 2 | −0.5384693101 | 0.4786286705 | Inner left |
| 3 | 0 | 0.5688888889 | Centre (highest weight) |
| 4 | +0.5384693101 | 0.4786286705 | Inner right |
| 5 | +0.9061798459 | 0.2369268851 | Outer 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.