Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to model a spring damper system from a tutorial that I've found on this site.

If I use the exact same parameters as the ones in the tutorial the system is not stable. I've downloaded the code and verified that the parameters were the same as mine.

a = (k * u) - (d * v);
v = v + a;
s = s + v;

jsfiddle available here

I can make it stable by adding a factor 0.3, like so

s = 0.3 * s + v

However, I would like to know how to make it stable without hacking it. I'm aware that the integrator is not good, but it should still work for this case, because it does so in the demo.

share|improve this question

migrated from May 19 '13 at 20:21

This question came from our site for active researchers, academics and students of physics.

the equation is supposed to be $s=s_o+vt+\frac{1}{2}at^2$ – Greg May 19 '13 at 20:00
@Greg, no this formula is for constant acceleration. The OP is talking about a numerical solution where the acceleration changes with position and velocity. – ja72 May 19 '13 at 20:16
up vote 1 down vote accepted

Your spring model is fine. It is the numerical integration that needs attention. What you have above is Euler's method for numerical integration with $\Delta t=1$. This method is known to be unstable. You made it stable with artificial (numerical) damping. For a simple spring damper system try to use the mid-point method or better yet a four step Runge-Kutta method

More information here and here.

Your code would like something like this

// time step h=1 or less

a1 = (k*u) - (d*v)
u2 = u + (h/2)*v
v2 = v + (h/2)*a1
a2 = (k*u2) - (d*v2)

u = u + h*v2
v = v + h*a2
share|improve this answer
Thank you. I started searching for integrators and ended up here. The slide before the last one shows the problem. – wubbewubbewubbe May 19 '13 at 20:39
@stackoverflownewbie Great reference url. – ja72 May 19 '13 at 20:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.