ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/outil/src/ot_root_find.h
Revision: 27
Committed: Thu Jul 5 15:26:40 2007 UTC (18 years ago) by foucault
Content type: text/plain
Original Path: magic/lib/outil/outil/src/ot_root_find.h
File size: 2819 byte(s)
Log Message:

File Contents

# User Rev Content
1 foucault 27 //---------------------------------------------------------------------------
2    
3     #ifndef ot_root_findH
4     #define ot_root_findH
5     //---------------------------------------------------------------------------
6    
7     #include <math.h>
8     #include <stdio.h>
9    
10     #ifdef WINDOWS_VERSION
11     #ifdef BUILT_DLL_OUTIL
12     #define DLLPORTOUTIL __declspec(dllexport)
13     #else
14     #define DLLPORTOUTIL __declspec(dllimport)
15     #endif
16     #else
17     #define DLLPORTOUTIL
18     #endif
19    
20     class DLLPORTOUTIL OT_ROOT_FIND_1D {
21     public:
22    
23     typedef double (*Function)(double,void*);
24    
25     /** ZeroBracOut (fn, x1, x2)
26     given a function fn and an initial guessed range [x1, x2], this routine
27     expands the range geometrically until a root is bracketed by x1 & x2, in
28     which case it returns 1, or the range becomes too large, returning 0 */
29     static unsigned ZeroBracOut (Function fn, double &x1, double &x2, void* pvData = 0);
30     static unsigned ZeroBracOut (Function fn, double xStart, double xEnd, double &x1, double &x2, void* pvData);
31    
32     /** ZeroBracIn (fn, x1, x2, n, xb1, xb2, nb)
33     given a function fn defined on [x1, x2], subdivide the interval into n
34     equally spaced segments & search for zero crossings of the function. nb is
35     input as the maximum number of roots sought. output is the number of
36     bracketing pairs xb1[], xb2[] that are found. */
37     static unsigned ZeroBracIn (Function fn, const double &x1, const double &x2,
38     unsigned n, double xb1[], double xb2[], unsigned nb, void* pvData = 0);
39    
40     /** RootBisect (fn, x1, x2, xacc)
41     using bisection, find the root of fn known to lie between x1 and x2. the
42     returned root will be refined until its accuracy is +/- xacc. */
43    
44     static double RootBisect (Function fn, const double &x1, const double &x2, const double &xacc, void* pvData = 0);
45    
46     /** RootFlsPos (fn, x1, x2, xacc)
47     using the false position method, find the root of fn in [x1, x2] to an
48     accuracy of +/-xacc. */
49    
50     static double RootFlsPos (Function fn, const double &x1, const double &x2,
51     const double &xacc, void* pvData = 0);
52    
53     /* RootNewton (fn, df, x1, x2, xacc)
54     using the newton-raphson method, find the root of fn in [x1, x2] to an
55     accuracy +/-xacc. df gives the 1st derivative of fn. */
56    
57     static double RootNewton (Function fn, Function df,
58     const double &x1, const double &x2, const double &xacc, void* pvData = 0);
59    
60     /* RootSafe (fn, df, x1, x2, xacc)
61     using a combination of newton-raphson and bisection, find the root of fn
62     in [x1, x2] to an accuracy +/-xacc. df gives the 1st derivative of fn. */
63    
64     static double RootSafe (Function fn, Function df,
65     const double &x1, const double &x2, const double &xacc, void* pvData = 0);
66     };
67     #endif