[go: up one dir, main page]

Menu

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

Download this file

48 lines (38 with data), 1.3 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
41
42
43
44
45
46
#ifndef SUPERNEWTON_H_INCLUDED
#define SUPERNEWTON_H_INCLUDED 1
namespace libpetey {
//root-finding function which brackets the root
//and then approximates root by fitting a third-
//order polynomial
template <class real>
real supernewton(void (*funcd) (real, void *, real *, real *),
void *params, //function parameters
real x1, //first bracket
real x2, //second bracket
real xtol, //desired (absolute) tolerance
real ytol,
long maxiter, //maximum number of iterations
long &err, //returns number of iterations;
//returns 0 or less for failure
real &y1, //to avoid redundant calculation
real &dydx1, //returns final values in these two
real y2,
real dydx2);
template <class real>
inline real supernewton(void (*funcd) (real, void *, real *, real *),
void *params, //function parameters
real x1, //first bracket
real x2, //second bracket
real xtol, //desired (absolute) tolerance
real ytol,
long maxiter, //maximum number of iterations
long &err) //number of iterations/error code
{
real 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