1 /* 2 To use the Runge-Kutta solver for systems of first order differential equations, 3 (the parametric object E must have public function such as E->f(i,x,y), 4 where i is the index of the function to evaluate, x is the time and 5 y is a point such as y(x), returns values of differential equation i) 6 7 1- construct the solver : solver = new RungeKutta<objet>(int); //the integer is the dimension of x 8 2- set the solver : solver->set(unit, y0, x0, xn); //unit is usually the pointer *this, y0 are the initial conditions, and x0 and xn is the time interval 9 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed???????????????????????????? 10 4- delete the solver : delete solver; 11 (ref :Fortin) 12 */ 13 #ifndef RUNGEKUTTA_H 14 #define RUNGEKUTTA_H 15 16 #include "defines.hpp" 17 using namespace std; 18 19 template <class E> 20 class RungeKutta 21 { 22 private: 23 double *k1, *k2, *k3, *k4, *y_tmp, *y; 24 // double k1[MAX_DIM], k2[MAX_DIM], k3[MAX_DIM], k4[MAX_DIM], y_tmp[MAX_DIM], y[MAX_DIM]; 25 double h, x0, xn, x; 26 int i, j, m; 27 bool success; 28 E *unit; 29 30 public: 31 RungeKutta(int); 32 ~RungeKutta(); 33 void set(E*, double*, double, double); dx()34 double dx(){return h;} 35 bool run(); 36 }; 37 #endif 38