Gauss-Legendre Quadrature (Numerical Integration) Calculator
Enter f(x), the interval [a, b] and the order n to evaluate the definite integral ∫f(x)dx with high accuracy using Gauss-Legendre quadrature. Shows the nodes, weights and function values.
Input
Enter the integrand f(x), the interval [a, b] and the order n to evaluate the definite integral with Gauss-Legendre quadrature.
e.g. exp(-x^2), sin(x)/x, x^2 + 1. See the method section for supported functions, constants and operators.
Number of nodes (1-256)
Result
Integral ∫ f(x) dx
0.7468241328
Interval [0, 1]
Order n
8
Nodes
8
Nodes, weights and values
Shows the nodes x_i (mapped to [a, b]), weights w_i and function values f(x_i).
| # | Node x_i | Weight w_i | f(x_i) |
|---|---|---|---|
| 1 | 0.40828268 | 0.18134189 | 0.84645796 |
| 2 | 0.2372338 | 0.15685332 | 0.94527454 |
| 3 | 0.10166676 | 0.11119052 | 0.9897171 |
| 4 | 0.01985507 | 0.05061427 | 0.99960585 |
| 5 | 0.98014493 | 0.05061427 | 0.38263105 |
| 6 | 0.89833324 | 0.11119052 | 0.44619348 |
| 7 | 0.7627662 | 0.15685332 | 0.55888459 |
| 8 | 0.59171732 | 0.18134189 | 0.70459692 |
How it works
- Gauss-Legendre quadrature approximates an integral on the reference interval [-1, 1] by sampling the integrand at the roots x_i of the degree-n Legendre polynomial P_n(x) and combining them with weights w_i = 2 / ((1 - x_i^2)(P_n'(x_i))^2), giving ∫_{-1}^{1} g(t)dt ≈ Σ w_i g(x_i).
- An arbitrary interval [a, b] is handled with the linear change of variable x = (b-a)/2·t + (a+b)/2 and dx = (b-a)/2·dt, so ∫_a^b f(x)dx ≈ (b-a)/2·Σ w_i f((b-a)/2·x_i + (a+b)/2).
- With n nodes the rule is exact (in exact arithmetic) for any polynomial integrand up to degree 2n-1, so smooth functions are integrated to very high accuracy even with relatively few nodes.
- The nodes (roots of the Legendre polynomial) are found by evaluating the polynomial through the recurrence (k+1)P_{k+1}(x) = (2k+1)xP_k(x) - kP_{k-1}(x) and refining initial approximations with Newton's method, exploiting the symmetry of the roots.
- The function expression is parsed by an independent expression parser (no eval). Supported operators are + - * / ^ (power) with parentheses, unary minus and implicit multiplication; constants pi and e; and functions sin cos tan asin acos atan sinh cosh tanh exp log ln log10 sqrt cbrt abs.
- Computations use double-precision floating point and are therefore subject to rounding error. Accuracy can degrade when the integrand has singularities or rapid oscillations inside the interval.
Reviews
Tell us what you think of this calculator.
Write a review
- Home
Gauss-Legendre Quadrature (Numerical Integration) Calculator