This code numerically solves the spring-mass system problem and determines the mass displacement, velocity, and acceleration for n time steps using the central difference method.
The central difference method is an explicit numerical method. This method is based on finite difference expressions in time for velocity and acceleration at a time t given by:
Numerical integration:
The procedure for a solution is then as follows:
Step1: determine displacement, velocity, and force at t=0
Step2: determine acceleration at t=0
Step3: determine displacement (i=-1)
Step4: determine displacement (i=1)
Step5: determine displacement (i=2)
Step6: determine acceleration (i=1)
Step7: determine velocity (i=1)
Use steps 5 through 7 repeatedly to obtain the displacement, acceleration, and velocity for all other time steps.
Enter the number of steps and the amplitute of force when t=0
Plot the displacement, velocity and acceleration: