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

alg_remez.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_ALG_REMEZ_H
00002 #define INCLUDED_ALG_REMEZ_H
00003 
00004 #include<config.h>
00005 
00006 #ifdef GMP        // If GMP is defined 
00007 
00008 #include <util/lattice.h>
00009 #include <util/smalloc.h>
00010 #include <util/pmalloc.h>
00011 #include <alg/common_arg.h>
00012 #include <alg/bigfloat.h>
00013 #include <alg/remez_arg.h>
00014 CPS_START_NAMESPACE
00015 //------------------------------------------------------------------
00016 //
00017 // alg_remez.h
00018 //
00019 // AlgRemez is relevant to the Rational Hybrid Molecular Dynamics
00020 // algorithm.  The Remez algorithm is used for generating the nth root
00021 // rational approximation.
00022 //
00023 // Note this class can only be used if
00024 // the gnu multiprecision (GNU MP) library is present.
00025 //
00026 //------------------------------------------------------------------
00027 
00028 #define JMAX 1000 //Maximum number of iterations of Newton's approximation
00029 
00030 class AlgRemez
00031 {
00032  private:
00033   char *cname;
00034 
00036   RemezArg *remez_arg;
00037 
00038   // The approximation parameters
00039   bigfloat *param, *roots, *poles;
00040   bigfloat norm;
00041 
00042   // The numerator and denominator degree (n=d)
00043   int n, d;
00044   
00045   // The bounds of the approximation
00046   bigfloat apstrt, apwidt, apend;
00047 
00048   // the numerator and denominator of the power we are approximating
00049   unsigned long power_num; 
00050   unsigned long power_den;
00051 
00052   // Variables used to calculate the approximation
00053   int nd1, iter;
00054   bigfloat *xx, *mm, *step;
00055   bigfloat delta, spread, tolerance;
00056 
00057   bigfloat delta_m;
00058 
00059   // The number of equations we must solve at each iteration (n+d+1)
00060   int neq;
00061 
00062   // The type of approximation
00063   RationalApproxType approx_type;
00064 
00065   // The precision of the GNU MP library
00066   long prec;
00067 
00068   // Initial values of maximal and minmal errors
00069   void initialGuess();
00070 
00071   // Solve the equations
00072   void equations();
00073 
00074   // Search for error maxima and minima
00075   void search(bigfloat *step); 
00076 
00077   // Initialise step sizes
00078   void stpini(bigfloat *step);
00079 
00080   // Calculate the roots of the approximation
00081   int root();
00082 
00083   // Evaluate the polynomial
00084   bigfloat polyEval(bigfloat x, bigfloat *poly, long size);
00085 
00086   // Evaluate the differential of the polynomial
00087   bigfloat polyDiff(bigfloat x, bigfloat *poly, long size);
00088 
00089   // Newton's method to calculate roots
00090   bigfloat rtnewt(bigfloat *poly, long i, bigfloat x1, bigfloat x2, bigfloat xacc);
00091 
00092   // Evaluate the partial fraction expansion of the rational function
00093   // with res roots and poles poles.  Result is overwritten on input
00094   // arrays.
00095   void pfe(bigfloat *res, bigfloat* poles, bigfloat norm);
00096 
00097   // Evaluate the rational form P(x)/Q(x) using coefficients from the
00098   // solution vector param
00099   bigfloat approx(bigfloat x);
00100 
00101   // Calculate function required for the approximation
00102   bigfloat func(bigfloat x);
00103 
00104   // Compute size and sign of the approximation error at x
00105   bigfloat getErr(bigfloat x, int *sign);
00106 
00107   // Solve the system AX=B
00108   int simq(bigfloat *A, bigfloat *B, bigfloat *X, int n);
00109 
00110  public:
00111   
00112   // Constructor
00113   AlgRemez(RemezArg &);
00114 
00115   // Destructor
00116   virtual ~AlgRemez();
00117 
00118   // Generate the rational approximation x^(pnum/pden)
00119   void generateApprox();
00120 
00121   // Return the partial fraction expansion of the approximation x^(pnum/pden)
00122   int getPFE(Float *res, Float *pole, Float *norm);
00123 
00124   // Return the partial fraction expansion of the approximation x^(-pnum/pden)
00125   int getIPFE(Float *res, Float *pole, Float *norm);
00126 
00127 };
00128 CPS_END_NAMESPACE
00129 
00130 #else             // If not defined GMP
00131 
00132 
00133 #include <alg/remez_arg.h>
00134 #include <util/error.h>
00135 #include <util/data_types.h>
00136 CPS_START_NAMESPACE
00137 
00138 
00139 // Dummy class for case when gmp is not present
00140 
00141 class AlgRemez
00142 {
00143  private:
00144   char *cname;
00145 
00146 
00147  public:
00148   
00149   AlgRemez(RemezArg&) {
00150     cname = "AlgRemez";
00151     char *fname = "AlgRemez(RemezArg&)";
00152     ERR.General(cname,fname,
00153                 "AlgRemez cannot be instantiated without GMP installed\n");
00154   }
00155 
00156   ~AlgRemez() {;}
00157 
00158   Float generateApprox() {return 0.0;}
00159   int getPFE(Float *res, Float *pole, Float *norm) {return 0;}
00160   int getIPFE(Float *res, Float *pole, Float *norm) {return 0;}
00161 
00162 };
00163 CPS_END_NAMESPACE
00164 
00165 #endif  // Ifdef GMP
00166 
00167 #endif  // Include guard
00168 
00169 
00170 

Generated on Sat Oct 10 14:11:09 2009 for Columbia Physics System by  doxygen 1.3.9.1