#include #include // for time measuring #include #include #include #include #include #include "nr.h" using namespace std; #define PI 3.141592653589793 Vec_DP *xp_p; Mat_DP *yp_p; int jj = 0; // (global) counter for RHS computations const double a = 0.2; // global parameter const double b = 0.03; const double c = 0.1; const double d = 0.03; const double y10 = 6.0; // initial condition const double y11 = 15.0; const double TE = 70.0; // end point const DP TOL = 1.0e-6; void deriv(const DP t, Vec_I_DP &y, Vec_O_DP &f) // RHS of ODE { f[0] = -a*y[0] + b*y[0]*y[1]; f[1] = c*y[1] - d*y[0]*y[1]; jj++; // counter for RHS calls } void simpson( int k, Vec_I_DP &y, const DP t, const DP h, const DP TOL, Mat_IO_DP yp, Vec_IO_DP xp, Vec_O_DP &yout ) { int i, j, nmax = 4; double delta; int nvar=y.size(); Vec_DP u(nvar), v(nvar), w(nvar); Vec_DP ff(nvar); // constant part for the current step for (i=0; i TOL && j < nmax ) // iteration loop { deriv(t, v, ff); delta = 0.0; for(i=0;i end of starting procedure ..." << endl; // multistep method ( Simpson rule without predictor ) double cpuTotal = 0.0; clock_t startTime = clock(); for (j=2; j numerical solution:" << endl; cout << "# j | t | y1(t) y2(t) | "; cout << " f(t,y1(t) f(t,y2(t) " << endl; cout << "# "; for (i=0;i<72;i++) cout << "="; cout << endl; for (int j=0;j