|
Contents | Previous | Next | Subchapters |
| Syntax |
gaussleg(n, aout, wout) |
| See Also | gaussq , ode4rk |
+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.
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)