|See Also||gaussq , ode4rk|
| f(x) dx = wout f(aout ) + ... + wout f(aout )
/ 1 1 n n
f(x)is any polynomial of degree
2 n - 1or 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.
pi/2using one quadrature interval. The result of the integral is printed in the command window.
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)