When working with a situation like this (i.e. time-varying force), it's best to start with the differential equations \begin{align} \frac{{\rm d}x}{{\rm d}t}&=v \\ \frac{{\rm d}v}{{\rm d}t}&=F/m \end{align} rather than trying to use positions and velocities from kinematics. The above can be re-witten using a time-stepping technique called [leapfrog integration](http://en.wikipedia.org/wiki/Leapfrog_integration), in which you update positions and velocities at offset intervals: \begin{align} x^{n+1} &= x^n + v^{n+\frac12}\Delta t \\ a^{n+1} &= F(x^{n+1}) \tag{1}\\ v^{n+\frac32}&=v^{n+\frac12} + a^{n+1}\Delta t \end{align} Here, the fractional $n$ can be thought of the "cell wall" value (e.g., $x_{i+\frac12}=\frac12(x_i+x_{i+1})$) but in time instead of space. Or you can use a modification called [*verlocity verlet*](https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet). This turns (1) into a multi-step process: \begin{align} a_1 &= F\left(x^n_i\right)/m \\ x^{n+1} &= x_i^n + \left(v_i^n + \frac{1}{2}\cdot a_1\cdot\Delta t\right)\cdot\Delta t \\ a_2 & =F\left(x^{n+1}\right)/m \\ v^{n+1} &= v_i^n + \frac{1}{2}\left(a_1+a_2\right)\cdot\Delta t \end{align} Both integration methods are reasonably simple to implement, requiring definitions for forces and some vectors. The latter of the two is more often the algorithm-of-choice due to it's [symplectic nature](https://en.wikipedia.org/wiki/Symplectic_integrator). Your implementation for the latter of the two algorithms would essentially be while t < t_end a1 = Force(x) / m x += (v + 0.5 * a1 * dt) * dt a2 = Force (x) / m v += 0.5 * (a1 + a2) * dt output t, x, v t += dt