[go: up one dir, main page]

Menu

[r130]: / libpetey / supernewton.h  Maximize  Restore  History

Download this file

42 lines (33 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef SUPERNEWTON_H_INCLUDED
#define SUPERNEWTON_H_INCLUDED 1
//minimization function which brackets the root
//and then approximates root by fitting a third-
//order polynomial
double supernewton(void (*funcd) (double, void *, double *, double *),
void *params, //function parameters
double x1, //first bracket
double x2, //second bracket
double xtol, //desired (absolute) tolerance
double ytol,
long maxiter, //maximum number of iterations
long &err, //error code--zero for success
double &y1, //to avoid redundant calculation
double &dydx1, //returns final values in these two
double y2,
double dydx2);
inline double supernewton(void (*funcd) (double, void *, double *, double *),
void *params, //function parameters
double x1, //first bracket
double x2, //second bracket
double xtol, //desired (absolute) tolerance
double ytol,
long maxiter, //maximum number of iterations
long &err) //error code--zero for success
{
double y1, y2, dydx1, dydx2;
(*funcd) (x1, params, &y1, &dydx1);
(*funcd) (x2, params, &y2, &dydx2);
return supernewton(funcd, params, x1, x2, xtol, ytol, maxiter, err,
y1, dydx1, y2, dydx2);
}
#endif