Modeling a Spring Using Hooke’s Law

The notation used in our text to describe the force exerted by a stretched or compressed spring can be a bit confusing at first. But it is written in a way that can be useful for modeling a mass-spring system using VPython, even when the mass can move in more than one direction as we will eventually see. It is worthwhile to review this notation and make sure that we are consistent in how we use it to describe the force the spring exerts.

Mass Spring System

In this model we are assuming that we have a single spring where one end is attached to a fixed  location and the other end is free to move and usually has a mass attached.

  • First, we will use the scalar value \(L_0\) to describe the un-stretched (or natural) length of the spring.  This is the length the spring would have if you just laid it out on a flat horizontal surface.  We will denote this natural length in VPython using the variable L0 and need to remember that this value is a scalar.
  • Next, we introduce a vector, \(\vec{L}\) whose tail is at the point of attachment of the spring and whose tip is at the free end of the spring where the mass is attached.  We will denote this value in VPython using the variable L and need to remember that this value is a vector.
  • The length of the spring at any moment will be given by the magnitude of \(\vec{L}\), which we denote here by \(|\vec{L}|\).  In VPython we will write this value using the scalar variable Lmag.
  • A unit vector pointing in the along the spring, in the direction from the attachment point toward the free end, is $$\hat{L} = \frac{\vec{L}}{|\vec{L}|}$$ In VPython we calculate this unit vector using the command Lhat = norm(L). The force will either be in the same direction or opposite direction of \(\hat{L}\) depending upon whether the spring is compressed or stretched as discussed below.
  • The stretch of the spring is a scalar quantity that represents how much the spring is stretched beyond its natural length.  We compute the stretch using $$s = |\vec{L}| – L_0$$ which in VPython we would write as s = Lmag - L0.
    • If the spring is stretched then s will be positive.
    • If the spring is compressed then s will be negative.
  • Finally, we define the force on the spring, also called Hooke’s Law, using the expression $$\vec{F}_s = – k_s s \hat{L}$$ where \(k_s\) is the force constant for the spring.
    • \(\vec{F}_s\) will be in the opposite direction of \(\hat{L}\) when the spring is stretched (\(s\) is positive).
    • \(\vec{F}_s\) will be in the same direction as \(\hat{L}\) when the spring is compressed (\(s\) is negative).
  • In VPython, we will write the spring force, which is of course a vector, using Fs = - ks * s * Lhat. The spring constant ks and the stretch s, which are both scalars, are multiplied by the unit vector Lhat to create the vector spring force Fs.

So in summary, if the natural length and spring constant of the spring (L0 and ks) have been defined previously, the process of calculating the force exerted by a spring on a mass when it has a vector length L can be carried out using the following code:

Lmag = mag(L)
Lhat = norm(L)

# Compute the stretch of the spring
s = Lmag - L0

# Compute the Spring Force
Fs = - ks * s * Lhat

Or, you could do this all in one line using:

# Compute the Spring Force
Fs = - ks * (mag(L) - L0) * norm(L)