Contents Previous Next Subchapters Current Chapters-> trapz gaussq quad2d gaussq2d gaussleg quadint int2inf ode4rk expmat ode45rk odepade odestiff Parent Chapters-> Omatrix6 integration gaussleg Search Tools-> contents reference index search

 Syntax `gaussleg(`n`, `aout`, `wout`)` See Also gaussq , ode4rk
Determines the Gauss-Legendre weights, wout and abscissas aout such that ```       +1      /      | f(x) dx  =  wout  f(aout ) + ... + wout  f(aout )      /                 1       1              n       n      -1 ```where `f(x)` is any polynomial of degree `2 n - 1` or less. ``` ```The integer scalar n specifies the number of points in the quadrature. The input value of aout does not matter. Its output value is a double-precision column vector of length n containing the abscissas for the quadrature. The input value of wout does not matter. Its output value is a double-precision column vector of length n containing the weights for the quadrature.
The following example integrates the cosine function between zero and `pi/2` using one quadrature interval. The result of the integral is printed in the command window. ``` clear n     = 5                       # number of quadrature points aout  = novalue                 # quadrature points wout  = novalue                 # quadrature weights gaussleg(n, aout, wout) ratio = (pi / 2d0) / 2d0        # ratio of [0, pi/2] / [-1, +1]  x     = ratio * (aout + 1d0)    # abscissas in [0, pi/2] print "approximation for the integral =", ratio * wout' * cos(x) ```