Weights and abscissae of Gauss-Legendre quadrature

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


numeric::gldata(n, digits)


numeric::gldata(n, digits) returns the weights and the abscissae of the Gauss-Legendre quadrature rule with n nodes with a precision of digits decimal digits.

The Gauss-Legendre quadrature rule produces the exact integral for all polynomial integrands f(x) through degree 2 n - 1. The weights bi and abscissae ci are related to the roots of the n-th Legendre polynomial.

The weights and abscissae are computed by a straightforward numerical algorithm with a working precision set by the argument digits. The resulting floating-point numbers are correct to digits leading decimal places.

Typically, the argument digits is chosen as the current value of the environment variable DIGITS.

The data for n = 20, 40, 80, 160 with digits <= 200 are stored internally. They are returned immediately without any computational costs.

Due to the internal remember mechanism, only the first call to numeric::gldata leads to computational costs. For any further call with the same arguments, the data are returned immediately.

For odd n, the abscissa and the corresponding weight are rational numbers.

Environment Interactions

numeric::gldata is not sensitive to changes of the environment variable DIGITS, because the numerical working precision is specified by the second argument digits.

The function uses option remember.


Example 1

The following call computes the Gauss-Legendre data with a precision given by the current value of the environment variable DIGITS (the default value is DIGITS = 10):

[b, c] := numeric::gldata(4, DIGITS)

The Gauss-Legendre data with 4 nodes provide exact numerical quadrature results for polynomials through degree 7:

f := x -> x^7:
int(f(x), x= 0..1) = _plus(b[i]*f(c[i]) $ i=1..4)

delete b, c, f:

Example 2

For odd n, exact rational data for and are returned. The other data are computed as floating-point approximations:

DIGITS := 4: numeric::gldata(5, DIGITS)

delete DIGITS:



The number of nodes: a positive integer


The number of decimal digits: a positive integer

Return Values

List [b, c] is returned. The lists b = [b1, …, bn] and c = [c1, …, cn] are numerical approximations of the weights and abscissae with digits significant digits.


The numerical integrator numeric::quadrature calls numeric::gldata to provide the data for Gaussian quadrature.