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
= 0 in a given interval
when
is monotone.
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 |
|
| 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;
}
|
CubicRootsCL
CubicRootsCL solves the cubic equation
+
+
+
= 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 |
|
| 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. |
ZeroCL
The CCATSL routine ZeroCL locates the root of an equation of the
form
= 0 when
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 |
|
| 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. |
PolyRootsCL()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. |