# How to apply damping to a spring?

I'm using Hooke's law to simulate my spring, but no matter what I do nothing works! How can I dampen the spring so it stops, cos it never stops right now. I've been told that acceleration = force / mass and that I need to add acceleration * delta * delta (Similar to acceleration ^ .5 but slightly different results when I tested) to velocity, and add that velocity to the position of the part (How else are we gonna see Hooke's law in action if nothing moves) but the flaw with this is that the velocity gets so big eventually that it wont even out until it goes past the rest point to the opposite direction, so I'm a bit stuck on how to make it stop.

• @Countto10 did you not see in the tags that it says "simulation"? I'm doing this by code not in real world. Mar 12, 2017 at 23:09
• My sincere apologies KapKing, I simply did not see the word simulation.
– user146020
Mar 12, 2017 at 23:16

The spring is damped with time. In solving F=ma, we use the spring force

$$-kx = ma$$

And then write acceleration in terms of the double time derivative

$$a= \frac{dx}{dt^{2}}$$

and we see the units work out. If we were in meters and second, acceleration would be meters/second/second.

The equation is now

$$m\frac{dx}{dt^{2}}=-kx$$

Which is a differential equation with an oscillatory solution? The easiest way to solve a differential equation to just guess the answer, and let's guess

$$x(t) = \cos(\omega t)$$

Where $\omega = \sqrt{\frac{k}{m}}$

Note that you could use sine also. I'm assuming the oscillator starts away from the origin. If the oscillator starts at the origin and gets pushed by an external force, then sine describes the motion.

Now, we need to damp the oscillation. The damping will depend on velocity. If the oscillator is moving very quickly, the damping will be stronger than if the oscillator is moving very slowly. Going back to

$$m\frac{dx}{dt^{2}}=-kx$$

We add a velocity term $v=\frac{dx}{dt}$

$$m\frac{dx}{dt^{2}}+kx=-c\frac{dx}{dt}$$

And the value $c$ is a constant describing the damping. Now, let's simplify the constants a bit and let $\omega = \sqrt{k}{m}$ and $\xi = \frac{c}{2\sqrt{mk}}$.

$$\frac{dx}{dt^{2}}+2\xi\omega\frac{dx}{dt}+\omega^{2}x=0$$

This is a second order differential equation. The solution is

$$x(t)= Ae^{-\xi\omega t}\cos(\sqrt{1-\xi^2}\omega t)$$

If you plug in our $x(t)$ into the differential equation, you'll see it works. We see $A$ is a constant. Again, the cosine is from the initial conditions: I'm assuming the oscillator begins far from the origin. If it begins at the origin at $t=0$, then the motion is described by sine. At time increases, the exponential term gets smaller and smaller, and $x(t)\rightarrow 0$.