If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

# 1D spring-mass system

## Video transcript

great work now it's time to throw a spring into the mix let's imagine we connect one end of a spring to our particle and the other end to an anchor point like this the particle is being pulled down by gravity causing the spring to stretch out when Springs are displays they try to pull back together and this is known as a spring force in Lesson one we saw the strength of this spring force depends on the displacement and the stiffness of the spring and we can express the stiffness of a spring with a variable K call it the spring constant this is known as Hookes law spring force equals negative K times displacement now let's modify our program to include this new spring first I'll add new variables for the anchor position of the spring to the initial settings one for the x coordinate and one for the y coordinate I'll call these anchor X and anchor Y I'll set these so the anchor is in the middle of the screen there is another initial setting to consider which is the spring constant it expresses how stiff the spring is let's call this K I'll give it a value say 7 now we can go into a draw function and add the spring force I'm going to define a new variable called spring force Y to represent the vertical spring forces from Hookes law we know this will be spring force y equals negative K times displacement or position Y - anchor Y which is the distance from the anchor to the mass now we just need to add the spring force to our existing force Y calculation which gives us force y equals spring force y plus mass times gravity and that's it for updating our forces finally we just need to do some new drawing to account for the spring we've added a draw and an anchor with a little box centered at the anchor position we've defined in our initial settings and I'll draw the spring with a line which extends for the anchor to the particle position like this now let's run our simulation and see what happens it's alive let's pause here so you can get comfortable with this mass spring system