HG-MD
1
|
00001 #ifndef POLY_H 00002 #define POLY_H 00003 00004 #include <cmath> 00005 #include <sstream> 00006 00017 template <StatType T> 00018 class NORMALIZED_POLYNOMIAL 00019 { 00020 00021 //definition of member variables 00022 00023 private: 00024 00026 string name; 00027 00029 unsigned int dim; 00030 00032 vector<Mdouble> coefficients; //starting with the highest order 00033 00035 vector<Mdouble> averaged_coefficients; 00036 00037 //definition of member functions 00038 00039 public: 00040 00042 NORMALIZED_POLYNOMIAL () { 00043 set_name("Polynomial"); 00044 coefficients.resize(0); 00045 dim = 0; 00046 } 00047 00049 void set_polynomial(vector<Mdouble> new_coefficients, unsigned int new_dim); 00050 00052 void set_polynomial(Mdouble* new_coefficients, unsigned int num_coeff, unsigned int new_dim); 00053 00054 00055 private: 00066 void set_polynomial(); 00067 00068 public: 00070 void set_name(const char* new_name) {name = new_name;} 00071 00073 string get_name() {return name;} 00074 00085 Mdouble get_volume(); 00086 00089 void set_average(); 00090 00093 void set_average_1D(); 00094 00097 void set_average_2D(); 00098 00100 Mdouble evaluate(Mdouble r); 00101 00103 Mdouble evaluate_1D(Mdouble r); 00104 00106 Mdouble evaluate_2D(Mdouble r); 00107 00111 Mdouble evaluateIntegral(Mdouble a, Mdouble b, Mdouble t); 00112 00115 Mdouble evaluateIntegral_1D(Mdouble a, Mdouble b, Mdouble t); 00116 00119 Mdouble evaluateIntegral_2D(Mdouble a, Mdouble b, Mdouble t); 00120 00121 private: 00123 Mdouble operator[](int i) const { 00124 return coefficients[i]; 00125 } 00126 00127 public: 00129 int order (void) { 00130 return coefficients.size()-1; 00131 } 00132 00134 friend inline std::ostream& operator<<(std::ostream& os, const NORMALIZED_POLYNOMIAL &P) { 00135 unsigned int N = P.coefficients.size(); 00136 for (unsigned int i=0; i<N; i++) { 00137 if (!P[i]) continue; 00138 if (P[i]>=0) os << "+"; 00139 os << setprecision(2) << P[i]; 00140 if (N-1-i>1) os << "r^" << N-1-i; 00141 else if (N-1-i==1) os << "r"; 00142 } 00143 return os; 00144 } 00145 00146 }; 00147 #include "Polynomial.hcc" 00148 #endif 00149