// Dynamics6.cc // Simulates five particles moving // under the influence of no forces. // Timestep deliberately chosen // to lead to inaccurate arithmetic. #include using namespace std; int main() { float T = 4000 , t=0 ; // time (t) and max time (T) float dt = 0.001 ; // timestep float v = 10 ; // velocity float x0 = 0.0 ; // position float x1 = 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 with v=" << v << " and timestep dt=" << dt << endl ; for( ; t<=T ; ) { x0+= dt * v ; x1+= dt * v ; x2+= dt * v ; x3+= dt * v ; x4+= dt * v ; t += dt ; if ( (i < 50) || !(i%1000) ) cout << i << " " << t << " " << x0<< " " << x1<< " " << x2<< " " << x3<< " " << x4<< endl ; i++; } }