00001 // QMcBeaver 00002 // 00003 // Constructed by 00004 // 00005 // Michael Todd Feldmann 00006 // and 00007 // David Randall "Chip" Kent IV 00008 // 00009 // Copyright 2000-2. All rights reserved. 00010 // 00011 // drkent@users.sourceforge.net mtfeldmann@users.sourceforge.net 00012 00013 #ifndef Polynomial_H 00014 #define Polynomial_H 00015 00016 #include "Array1D.h" 00017 #include "FunctionR1toR1.h" 00018 #include "Complex.h" 00019 #include "Exception.h" 00020 00028 class Polynomial : public FunctionR1toR1 00029 { 00030 private: 00035 Array1D<double> coefficients; 00036 00041 Array1D<double> firstDerivativeCoefficients; 00042 00047 Array1D<double> secondDerivativeCoefficients; 00048 00053 Array1D<double> thirdDerivativeCoefficients; 00054 00058 double f; 00059 00063 double df; 00064 00068 double d2f; 00069 00073 double d3f; 00074 00078 double x; 00079 00084 bool evaluatedF; 00085 00090 bool evaluatedDF; 00091 00096 bool evaluatedD2F; 00097 00098 public: 00102 Polynomial(); 00103 00109 Polynomial(Array1D<double> & coeffs); 00110 00116 void initialize(Array1D<double> & coeffs); 00117 00118 void evaluate(double x); 00119 double getFunctionValue(); 00120 00126 double getFunctionValue(double x); 00127 00128 double getFirstDerivativeValue(); 00129 double getSecondDerivativeValue(); 00130 double getThirdDerivativeValue(); 00131 00132 double get_p_a(int ai); 00133 double get_p2_xa(int ai); 00134 double get_p3_xxa(int ai); 00135 00140 Array1D<double> getCoefficients(); 00141 00149 Array1D<Complex> getRoots(); 00150 00156 void operator=(Polynomial rhs); 00157 00164 int getNumberCoefficients(); 00165 00179 double getCoefficient(int i); 00180 00184 void print(ostream & strm); 00185 00186 private: 00190 void initialize(); 00191 00202 double evaluate(double x, Array1D<double> & coeffs); 00203 00213 void evaluateAll(double x, Array1D<double> & coeffs); 00214 00232 void laguer(Array1D<Complex> &a, int m, Complex &x, int *its, bool *calcOK); 00233 00249 Array1D<Complex> zroots(Array1D<Complex> & a, bool polish, bool *calcOK); 00250 }; 00251 00252 #endif 00253 00254 00255