Skip to content

gauleg.m

Basic Information

  SYNTAX: [x, w] = gauleg(n,x1,x2)

  PURPOSE: Compute the Gauss-Legendre quadrature abscissas and weights
           of n internal points for the integration range [x1, x2]

  INPUTS: n = number of points
          x1, x2 = lower and upper bound for the integral, defaults -1, +1

  OUTPUTS: x = points to evaluate the function at
           w = weights for each of the points

  EXAMPLE: [x, w] = gauleg(32, -1, +1);
           fx = @(x)sin(x).^2;
           Igl = w*fx(x)
           Ii = integral(fx, -1, +1)  compare Igl and Ii