next up previous contents index
Next: Matrix routines Up: Mathematical functions Previous: Ordinary Differential Equations   Contents   Index


Integration

CCATSL has two routines for computing definite integrals

\begin{displaymath}
\m I=\int_a^b f(x)\,dx.
\end{displaymath}

The simpler of the two, RombergCL, uses Romberg extrapolation to calculate an approximation to $I$ and to give an estimate of the error. Since it divides the interval $[a,b]$ into a pre-determined number of equal subintervals, it is likely to perform poorly when the integrand varies rapidly or is singular somewhere inside $[a,b].$ The alternative routine, QuadCL uses an adaptive method for subdividing the interval and copes much better with these integrands. It can also be required to try to achieve user-specified error tolerances.


Romberg Extrapolation, RombergCL

RombergCL tries to calculate a definite integral using Romberg extrapolation with a user-specified number of sub-intervals. This routine is easy to use but is unable to handle badly behaved integrands very accurately. (The routine QuadCL is more suitable for these problems.)

  double RombergCL ( double (*f)(double x),
  double a,
  double b,
  double *err,
  int n);

  f A user-defined function implementing the integrand.
  a The lower endpoint of the integration interval.
  b The upper endpoint.
  err A pointer to variable which will hold an estimate of the error in the integral when RombergCL returns.
  n Determines the number of subintervals to use: RombergCL will use a total of $2^n$ subintervals (and hence $2^n+1$ function evaluations). Try n=5 to start with; if the error (see err below) is too large, increase n further (if your function is badly behaved or singular in [a,b], you should consider using the more powerful routine QuadCL).

The return value is the estimate of the integral. A typical use of RombergCL might look like

  
/*   /examples/chapter2/romb.c   */
#include <catam.h>

double f(double x)
{
  return sqrt(1-exp(-x));
}

int MainCL(void)
{
  double errest;
  double answer;

  answer=RombergCL(f,0.0,1.0,&errest,5);
  printf("Integral is %f",answer);
  return 0;
}

A complete example can be found in a03romb.c.


Adaptive Quadrature, QuadCL

This routine uses an adaptive quadrature method to evaluate definite integrals, and should cope reasonably well with singular and badly behaved integrands.

  double QuadCL ( double (*f)(double x)
  double a,
  double b,
  double aberr,
  double relerr,
  double *err,
  double *flag);

  f A user-defined function implementing the integrand.
  a, b Respectively the lower and upper endpoints of the integration interval.
  aberr The acceptable absolute error.
  relerr The acceptable relative error. (QuadCL is satisfied if it can meet either of the specified error tolerances.)
  err Pointer to a variable which will hold an estimate of the actual (absolute) error in the integral when QuadCL returns.
  flag Pointer to a variable used as a `reliability indicator'. If, when QuadCL returns this variable is 0.0, all is well. Otherwise, the integer part gives the number of subintervals where convergence could not be achieved and the fractional part is the proportion of the interval [a,b] still to be integrated over.

The return value is the estimate of the integral.


next up previous contents index
Next: Matrix routines Up: Mathematical functions Previous: Ordinary Differential Equations   Contents   Index
CATAM admin 2010-02-23