# Program for the motion of a particle subject to an external # force f(x) = -x. We have divided the total time 2*pi into # 10000 intervals with an equal time step. The position and # velocity of the particle are written out at every 500 steps. import numpy as np N = 10001 # number of time points IN = 500 # interval between outputs PI=3.14159265358979 DT = 2.0*PI/(N-1) X = np.arange(N, dtype=float) # position T = np.arange(N, dtype=float) # time V = np.arange(N, dtype=float) # velocity # Assign constants, initial position, and initial velocity X[0] = 0.0 T[0] = 0.0 V[0] = 1.0 # Recursion for position and velocity at later time I = 0 while I < N-1: T[I+1] = DT*(I+1) X[I+1] = X[I]+V[I]*DT V[I+1] = V[I]-X[I]*DT I += 1 # Write the position and velocity every 500 steps I = 0 while I < N: print(str(T[I]) + " " + str(X[I]) + " " + str(V[I])) I += 500