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

Fifth Order Gaussian Quadrature Numerical Integration
 Syntax `gaussq(function `fvec`, `a`, `b`, `bound`)` See Also trapz , gaussq2d , gaussleg , quadint

Description
Returns a fifth-order (three point) Gaussian quadrature approximation for the integral of `f(x)` over the interval `[a, b]`. The return value is a scalar with the same type as a. The function call `fvec(xvec)` returns the column vector ```                                                T      [f(xvec(1)), f(xvec(2)), ... , f(xvec(n))] ```with the same type as xvec, where `n` is the dimension of the column vector xvec. The column vector xvec will have the same type as a. The real or double-precision scalar a specifies the lower limit for the integration. The scalar b has the same type as a and specifies the upper limit for the integration. The scalar bound has the same type as a and specifies an upper bound for the quadrature interval size. As this bound gets smaller, the integration becomes more accurate and the number of necessary function evaluations increases. ``` ```Example
The following example integrates the cosine function between 0 and `pi/2`. The integration interval is broken into sub-intervals each of which is at most 1 unit long and a fifth-order (three point) Gaussian quadrature approximation is used on each sub-interval. A special version of the cosine function is defined because O-Matrix intrinsic functions cannot be passed as arguments. ```      function cosine(x) begin            return cos(x)      end      a     = 0.      b     = pi / 2      bound = 1.       gaussq(function cosine, a, b, bound) ``` returns ```      1 ``` The exact integral is the difference in the sine function between 0 and `pi/2` which is 1.