next up previous contents index
Next: Spline interpolation Up: Mathematical functions Previous: Poisson solver, PoissonCL   Contents   Index


Minimisation and root-finding

CCATSL contains three functions for finding the minima and zeros of a real-valued function: MinCL finds the minima of a unimodal function in a specified interval, CubicRootsCL solves a general cubic equation and ZeroCL solves $f(x)$ = 0 in a given interval when $f$ is monotone.


Minimisation of a unimodal function, MinCL

MinCL finds the location of the minimum of a unimodal function in a given interval, using a method combining golden section search and parabolic interpolation.

  double MinCL ( double (*f)(double x),
  double a,
  double b,
  double tol);

  f A user-defined function taking a single double argument and returning a double, giving the value of the function $f$ at the requested point.
  a The lower endpoint of the search interval.
  b The upper endpoint of the search interval.
  tol The acceptable tolerance in the location of the minimum.

A typical use of MinCL might look like

  
/*   /examples/chapter2/fminex.c   */
#include <catam.h>
double f(double x)
{
  return 2.1+(x-2.3)*(x-2.3);
}

int MainCL(void)
{
  double ans=MinCL(f,0,6,1e-5);
  printf("minimum occurs at %f",ans);
  return 0;
}


Cubic equation solver, CubicRootsCL

CubicRootsCL solves the cubic equation $x^3$ + $ax^2$ + $bx$ + $c$ = 0. It returns the number of roots, and the roots in non-decreasing order.

  void CubicRootsCL ( double a,
  double b,
  double c,
  int *nroots,
  double *r1,
  double *r2,
  double *r3);

  a, b, c The coefficients in the cubic equation $x^3$ + $ax^2$ + $bx$ + $c$ = 0.
  nroots Pointer to a variable to hold the number of roots when CubicRootsCL returns.
  r1, r2, r3 Pointers to variables to hold the roots, in non-decreasing order.


Finding the zero of a function, ZeroCL

The CCATSL routine ZeroCL locates the root of an equation of the form $f(x)$ = 0 when $f$ is a monotone function, using a combination of bisection and more powerful methods.

  double ZeroCL ( double (*f)(double x),
  double a,
  double b,
  double tol);

  f A user-defined function taking a double argument and returning a double, giving the value of the function $f$ at the requested point.
  a The lower endpoint of the search interval.
  b The upper endpoint of the search interval.
  tol The acceptable tolerance in the location of the root.


Finding the roots of a polynomial, PolyRootsCL()

The CCATSL routine PolyRootsCL finds all the roots of a polynomial with real coefficients by employing the Laguerre's Method.

  void PolyRootsCL( float *rcoeff,
  int deg,
  complex *roots,
  int polish);

  rcoeff vector with the coefficients of the polynomial. These must be real.
  deg degree of the polynomial.
  roots complex array with the computed roots.
  polish set to 1 for polishing the roots, 0 otherwise.


next up previous contents index
Next: Spline interpolation Up: Mathematical functions Previous: Poisson solver, PoissonCL   Contents   Index
CATAM admin 2010-02-23