Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/numerics/rootsolve/rootsolve.h

Go to the documentation of this file.
00001 /*
00002  * lib/numerics/rootsolve/rootsolve.h
00003  * 
00004  * Numerics library root solving functions. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _LIB_NUMERICS_ROOTSOLVE_ROOTSOLVE_H_
00018 #define _LIB_NUMERICS_ROOTSOLVE_ROOTSOLVE_H_ 1
00019 
00020 #include <lib/numerics/num_math.h>
00021 #include <lib/salloc.h>
00022 
00023 
00024 namespace NUM  // numerics
00025 {
00026 
00034 class PolyRootSolver
00035 {
00036     private:
00037     public:
00038         PolyRootSolver() {}
00039         virtual ~PolyRootSolver() {}
00040         
00053         virtual int solve(int order,const dbl *c,dbl *r);
00054 };
00055 
00056 
00068 class PolyRootSolver_Direct : public PolyRootSolver
00069 {
00070     public:
00072         struct Params
00073         {
00075             dbl nearly_zero;
00076         };
00077         Params par;
00078         
00080         static const Params defaults;
00081         
00082     public:
00083         PolyRootSolver_Direct();
00084         ~PolyRootSolver_Direct();
00085         
00087         int solve(int order,const dbl *c,dbl *r);
00088         
00094         int Solve_1(const dbl *c,dbl *r);  // Simple
00095         int Solve_2(const dbl *c,dbl *r);  // Midnight formula
00096         int Solve_3(const dbl *c,dbl *r);  // Cardano's formula
00097         int Solve_4(const dbl *c,dbl *r);  // Vieta's "formula"
00098 };
00099 
00100 
00113 class PolyRootSolver_Sturm : public PolyRootSolver
00114 {
00115     public:
00117         struct Params
00118         {
00120             dbl nearly_zero;
00122             dbl relerror;
00124             int sbisect_maxit;
00126             int modrf_maxit;
00127         };
00128         Params par;
00129         
00131         static const Params defaults;
00132         
00133     private:
00139 #define PolyRootSolver_Sturm_BufOnStack 1
00140         
00142         struct poly
00143         {
00144             int ord;        
00145             dbl *coef;   
00146             
00147             inline poly() : ord(0),coef(NULL) {}
00148             
00149 #if !PolyRootSolver_Sturm_BufOnStack
00150             inline void AllocCoeffs(int order)
00151                 {  coef=REALLOC(coef,order+1);  }
00152             inline ~poly()  {  coef=FREE(coef);  }
00153 #else
00154             inline ~poly() {}
00155 #endif
00156         };
00157     
00159         int modrf(int ord,dbl *coef,dbl a,dbl b,dbl *val);
00161         int modp(poly *u,poly *v,poly *r);
00163         int buildsturm(int ord,poly *sseq);
00165         int numroots(int np,poly *sseq,int *atneg,int *atpos);
00167         int numchanges(int np,poly *sseq,dbl a);
00169         int sbisect(int np,poly *sseq,dbl min,dbl max,int atmin,
00170             int atmax,dbl *roots);
00171     public:
00172         PolyRootSolver_Sturm();
00173         ~PolyRootSolver_Sturm();
00174         
00183         int solve(int order,const dbl *c,dbl *r);
00184 };
00185 
00186 
00198 class PolyRootSolver_Bairstow : public PolyRootSolver
00199 {
00200     public:
00202         struct Params
00203         {
00205             dbl nearly_zero;
00207             int maxiter;
00209             int iter_chg;
00211             dbl initial_epsilon;
00213             dbl disc_epsilon;
00214         };
00215         Params par;
00216         
00218         static const Params defaults;
00219         
00220     private:
00221         int _QuadricRealRoots(dbl *a,int n,dbl *wr);
00222         int _QuadricRoots(dbl *a,int n,dbl *wr,dbl *wi);
00223         int _FindQuadFact(dbl *a,int n,dbl *b,dbl *quad,
00224             int red_fact,dbl *err_est);
00225         void _GetQuads(dbl *a,int n,dbl *quad,dbl *x);
00226         int _Recurse(dbl *a,int n,dbl *b,int m,dbl *quad,dbl *err);
00227         void _DiffPoly(dbl *a,int n,dbl *b);
00228         dbl _Deflate(dbl *a,int n,dbl *b,dbl *quad);
00229         
00230     public:
00231         PolyRootSolver_Bairstow();
00232         ~PolyRootSolver_Bairstow();
00233         
00235         int solve(int order,const dbl *c,dbl *r);
00236 };
00237 
00238 }  // end of namespace NUM
00239 
00240 #endif  /* _LIB_NUMERICS_ROOTSOLVE_ROOTSOLVE_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5