Contents Previous Next Subchapters

Gauss-Legendre Quadrature Integration
Syntax [Ien] =  quadint(function fabmtoltrace)
See Also gaussleg , gaussq , trapz

Description
Computes I, an approximation for
     /b
     |  f(xdx
     /a
using the Gauss-Legendre quadrature weights and abscissas. These quadrature weights and abscissas are chosen so that the approximation is exact for a polynomial of degree m - 1 or less. If the function call f(x) returns a complex value, I is complex. Otherwise I is double-precision. The return value e is an estimate of the error in the integral. The return value n is the number of values of x at which the function f(x) was evaluated.

f(x)
This function call computes the element-by-element element-by-element value of the function f at the points specified by the vector x where x has the same type as a. The return value can be integer, real, double-precision or complex.

a
is a real or double-precision scalar that specifies the lower limit for the integration.

b
is a real or double-precision scalar that specifies the upper limit for the integration.

m
is a scalar that is equal to an integer and that specifies the number of weights and abscissas for each quadrature interval.

tol
is a real or double-precision vector with three elements. The first element of tol specifies the relative accuracy for the integration (relative to the integral of the absolute value of the function). The second element specifies an absolute accuracy for the integration. The total allowable error is the sum of the absolute and relative error. The third element specifies an absolute minimum for the size of a quadrature interval. Individual Quadrature interval sizes will be separately reduced until the accuracy requirement is met but will never be reduced below this value.

trace
is a scalar. If it is non-zero (true), each function value corresponds to a single symbol plotted in the current viewport at (xf(x)).

Example
The following example computes the value
         / pi
     2 = |   sin(xdx
         / 0
and plots the value of the integrand while doing so.

clear
function f(x) begin
     return sin(x)
end
a     = 0d0
b     = PI
m     = 3
tol   = 1d-5 * {1,1,1}
trace = true
quadint(function f, a, b, m, tol, trace)

Mlmode
In Mlmode , this function is accessed using the following syntax:
     
I = quad(funabtoltrace)
     
I = quad8(funabtoltrace)
The function quad uses
     m = 2
and the function quad8 uses
     m = 4
The argument fun is a string specifying the name of the function that is being integrated. The arguments a and b have the exact same meaning as for quadint. The arguments tol and trace need not be present in which case the default values
     tol   = [ 1e-3 , 0 , 1e-3 * (b - a) ]
     trace = 0
are used. The elements of the argument tol have the same meaning as for quadint except that not all the elements need to included and default values are used for ones that are not included.

Suppose that the file fun.m in the current directory contains the text
     function y = fun(x) 
     y = sin(x);
If in Mlmode you execute the program below,
     clear
     a     = 0;
     b     = pi;
     tol   = 1d-5;
     trace = 1;
     omgtitle('quad');
     quad('fun', a, b, tol, trace)
O-Matrix will trace the values of the sine function it used and print the value
     2
If you continue by entering
     omgaddwin;
     omgtitle('quad8');
     quad8('fun', a, b, tol, trace)
you will notice that few function values are plotted because fewer evaluations of f(x) are required.