// // harmonic4b.C Copyright Jun Makino 1998 // // demonstration program for numerical integration of // harmonic oscillator // use C type array #include #include #include #include #define NDIM 2 double k; void calc_df(double x[NDIM], double f[NDIM]) { f[0] = x[1]; f[1] = -k*x[0]; } void rk4(double x[NDIM], double h) { double kx1[NDIM],kx2[NDIM],kx3[NDIM],kx4[NDIM], xtmp[NDIM],ftmp[NDIM]; int i; calc_df(x,ftmp); for(i=0;i> nsteps >> norbits >> print_interval; h = 2*M_PI/nsteps; cout.precision(16); cerr << " x= " << x[0] << " v= " << x[1] << " h = " << h <<"\n"; cerr << " norbits= " << norbits <<"\n"; for(i=0; i