00001 // QMcBeaver 00002 // 00003 // Constructed by 00004 // 00005 // Michael Todd Feldmann 00006 // and 00007 // David Randall "Chip" Kent IV 00008 // 00009 // Copyright 2000. All rights reserved. 00010 // 00011 // drkent@users.sourceforge.net mtfeldmann@users.sourceforge.net 00012 00013 #ifndef CubicSpline_H 00014 #define CubicSpline_H 00015 00016 #include <iostream> 00017 #include <string> 00018 #include <math.h> 00019 00020 #include "Array1D.h" 00021 #include "FunctionR1toR1.h" 00022 00023 using namespace std; 00024 00030 class CubicSpline : public FunctionR1toR1 00031 { 00032 public: 00037 CubicSpline(); 00038 00039 00046 void operator=( const CubicSpline & rhs ); 00047 00048 00059 void initializeWithFunctionValues(const Array1D<double> &xInput, 00060 const Array1D<double> &yInput, 00061 double yPrimeFirst, double yPrimeLast); 00062 00063 00073 void initializeWithDerivativeValues(const Array1D<double> &xInput, 00074 const Array1D<double> &yPrimeInput, 00075 double yFirst); 00076 00077 void evaluate(double x); 00078 double getFunctionValue(); 00079 double getFirstDerivativeValue(); 00080 double getSecondDerivativeValue(); 00081 00090 double integrate(int indexStart, int indexStop); 00091 00098 void toXML(ostream& strm); 00099 00104 friend ostream& operator <<(ostream& strm, CubicSpline & rhs); 00105 00106 protected: 00114 void evaluate(double x, int index); 00115 00116 private: 00117 Array1D<double> x_list; //domain values 00118 Array1D<double> y_list; //function values for each x 00119 Array1D<double> yp_list; //1st derv of y at each point 00120 Array1D<double> a0_list; //poly coeff of f at each point 00121 Array1D<double> a1_list; //poly coeff of f at each point 00122 Array1D<double> a2_list; //poly coeff of f at each point 00123 Array1D<double> a3_list; //poly coeff of f at each point 00124 00125 Array1D<double> row_right; 00126 Array1D<double> row_middle; 00127 Array1D<double> row_left; 00128 Array1D<double> col_rhs; 00129 00130 double y0; //y for smallest x 00131 double yp0; //y prime for smallest x 00132 double ypend; //y prime for largest x 00133 int n; //number of input data points; 00134 00135 double f; 00136 double dfdx; 00137 double ddfddx; 00138 00139 void solve_tridiagonal_system(); 00140 void solve_tridiagonal_system2(); 00141 }; 00142 00143 00144 #endif 00145 00146 00147 00148