// Dynamics1.cc // Simulates five particles moving // under the influence of no forces #include using namespace std; int main(int argc, char* argv[]) { float T = 40 , t=0 ; // time (t) and max time (T) float dt= 0.00001 ; // timestep float v = 1000 ; // velocity float x0 = 0.0 ; // position float x = 25000.0 ; // position float x2 = 50000.0 ; // position2 float x3 = 75000.0 ; float x4 =100000.0 ; int i = 1 ; // line number cout << "# Dynamics will run from x=" << x << " with v=" << v << " and timestep dt=" << dt << endl ; for( ; t<=T ; ) { x0+= dt * v ; x += dt * v ; x2+= dt * v ; x3+= dt * v ; x4+= dt * v ; t += dt ; if ( (i < 50) || !(i%1000) ) cout << i << " " << t << " " << x0<< " " << x << " " << x2 <<" " << x3 <<" " << x4 << endl ; i++; } }