Files Classes Functions Hierarchy
00001 #ifndef NINTEGRATION_H 00002 #define NINTEGRATION_H 00003 00004 #include <cassert> 00005 #include <iostream> 00006 using namespace std; 00007 00008 #include <print.h> 00009 00015 template< typename D, typename T > 00016 class nintegrationEuler 00017 { 00018 public: 00019 00021 D yDorder; 00022 00024 nintegrationEuler(T * xi_, T * yi_) 00025 : yDorder(xi_,yi_) {} 00026 00028 // void operator ++ () 00029 // { ++yDorder; } 00030 00032 void eval 00033 ( 00034 T & dz, 00035 T const h, 00036 T const z, 00037 T const x 00038 ) 00039 { yDorder(dz,z,x); dz*=h; } 00040 }; 00041 00042 00046 template< typename D, typename T > 00047 class nintegrationTrapezoidEuler 00048 { 00049 public: 00050 00052 D yDorder; 00053 00055 nintegrationTrapezoidEuler(T * xi_, T * yi_) 00056 : yDorder(xi_,yi_) {} 00057 00059 void operator ++ () 00060 { ++yDorder; } 00061 00063 void eval 00064 ( 00065 T & dy, 00066 T const h, 00067 T const y, 00068 T const x 00069 ) 00070 { 00071 // Estimate the implicit variable y[n+1] by Eulers method. 00072 // w1 is y[n+1] interpolated: y[n+1] = y[n]+h*y'[n] 00073 00074 T yD; 00075 yDorder(yD,y,x); 00076 T w1 = y + h*yD; 00077 00078 T x1 = x+h; 00079 T y1D; 00080 yDorder(y1D,w1,x1); 00081 00082 dy = (y1D+yD)*h/2.0; 00083 } 00084 00085 }; 00086 00087 00093 template< typename D, typename T > 00094 class nintegrationRK 00095 { 00096 public: 00097 00099 D yDorder; 00100 00102 nintegrationRK(T * xi_, T * yi_) 00103 : yDorder(xi_,yi_) {} 00104 00106 void operator ++ () 00107 { ++yDorder; } 00108 00110 void eval 00111 ( 00112 T & dy, 00113 T const h, 00114 T const y, 00115 T const x 00116 ) 00117 { 00118 T c1; 00119 yDorder(c1,y,x); 00120 c1 *= h; 00121 00122 T x1 = x + h*0.5; 00123 T y1 = y + c1*0.5; 00124 00125 T c2; 00126 yDorder(c2,y1,x1); 00127 c2 *= h; 00128 00129 T y2 = y+c2*0.5; 00130 T c3; 00131 yDorder(c3,y2,x1); 00132 c3 *= h; 00133 00134 T x2 = x + h; 00135 T y3 = y + c3; 00136 T c4; 00137 yDorder(c4,y3,x2); 00138 c4 *= h; 00139 00140 dy = (c1+c2*2.0+c3*2.0+c4)/6.0; 00141 } 00142 00143 }; 00144 00145 #endif 00146 00147
1.5.8