keisoku

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_iWeight w_if(x_i)
10.408282680.181341890.84645796
20.23723380.156853320.94527454
30.101666760.111190520.9897171
40.019855070.050614270.99960585
50.980144930.050614270.38263105
60.898333240.111190520.44619348
70.76276620.156853320.55888459
80.591717320.181341890.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

  1. Home
  2. Gauss-Legendre Quadrature (Numerical Integration) Calculator