// Dynamics1.cc #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 x = 50000.0 ; // position float x2 = 75000.0 ; float x3 =100000.0 ; int i = 1 ; // line number if(argc>1) { sscanf( argv[1], "%f", &dt ) ; // put the 1st command-line argument in dt } if(argc>2) { sscanf( argv[2], "%f", &x ) ; // put the 2nd command-line argument in x } cout << "# Dynamics will run from x=" << x << " x2=" << x2 << " with v=" << v << " and timestep dt=" << dt << endl ; for( ; t<=T ; ) { x += dt * v ; x2+= dt * v ; x3+= dt * v ; t += dt ; if ( (i < 50) || !(i%1000) ) cout << i << " " << t << " " << x << " " << x2 <<" " << x3 << endl ; i++; } }