What is the Gauss-Kronrod Numerical Integration Calculator?
This tool computes the definite integral of a function f(x) over a finite interval [a, b] using Gauss-type quadrature. It evaluates the integrand at carefully chosen nodes, multiplies by precomputed weights, and sums the contributions. A higher-order estimate K is compared against a lower-order Gauss-Legendre estimate G to produce an error bound \(|K - G|\), giving you confidence in the result.
How to use it
Enter a math expression in x (for example 4/(1+x^2) or sin(x)), set the lower limit a and upper limit b, and choose the number of points n for the rule (odd, from 3 to 99). More points give higher accuracy for smooth integrands. Supported syntax includes + - * / ^, parentheses, and sin, cos, tan, asin, acos, atan, exp, ln, log, sqrt, abs, sinh, cosh, tanh, plus the constants pi and e.
The formula
Quadrature rules are defined on [-1, 1] as the weighted sum of integrand values. To integrate over [a, b], an affine change of variable is applied: \(x(t) = \frac{b-a}{2}\cdot t + \frac{a+b}{2}\) with \(dx = \frac{b-a}{2}\cdot dt\). Therefore the integral equals (b-a)/2 times the sum of weights w_i times f at the mapped nodes.
$$\int_{\text{a}}^{\text{b}} f(x)\,dx \;\approx\; \frac{b-a}{2}\sum_{i=1}^{\text{n}} w_i\, f\!\left(\frac{b-a}{2}x_i + \frac{a+b}{2}\right)$$The Gauss-Legendre nodes are the roots of the Legendre polynomial, found here by Newton's method, with weights \(w_i = \frac{2}{(1 - t_i^2)\cdot P'_m(t_i)^2}\).
Worked example
For f(x) = sin(x) on [0, pi], the exact integral is
$$[-\cos(x)]_{0}^{\pi} = -\cos(\pi) + \cos(0) = 1 + 1 = 2.$$The calculator returns approximately 2 with a tiny estimated error. Similarly f(x) = 4/(1+x^2) on [0, 1] returns \(\pi = 3.14159265\), since \(4\cdot\arctan(1) = \pi\).
FAQ
Why must n be odd? The embedded Gauss-Kronrod pair reuses \(m = \frac{n-1}{2}\) Gauss nodes, which requires an odd total node count.
What does the error estimate mean? It is the absolute difference between the high-order and low-order estimates; a small value indicates convergence.
What about singularities? Integrable endpoint singularities reduce accuracy. Non-finite evaluations are skipped, and a = b returns exactly 0.