Mathematical Models of a Spring-Mass System

1. Introduction and Background
1.1 State Variables
1.2 Variables and Parameters
1.3 Notation
1.4 Governing Physical Principles

2. Mathematical Models
2.1 A Discrete in Time Mathematical Model
2.1 A Continuous in Time Mathematical Model

3. Algorithm for the Discrete in Time Model
3.1 Pseudocode
3.2 C Code Algorithms

4. Computational Experiments and Model Refinements
4.1 Computational Experiments
4.2 Model Refinements

1. Introduction

Mathematical models of many interesting dynamics problems are based on Newton's Laws of motion. This document has two main goals: (1) present mathematical models of a simple spring-mass system and (2) show how Newton's 2nd Law of motion can be applied in the construction of mathematical models.

As a concrete example of a dynamical system, consider a solid mass attached to a coil spring. The spring is rigidly fixed at one end and the spring and the attached mass are free to move in a line along a horizontal surface. See Figure 1. We define the equilibrium position of the spring-mass system to be that in which the spring is neither compressed nor stretched and the mass is at rest. So that we can formulate a very simple mathematical model describing this physical system, we make the simplifying assumptions that (1) friction between the mass and the supporting horizontal is negligible; (2) if the spring is compressed by a length of L, then it exerts on the mass a force of k*L in the direction of the positive x-axis; and (3) if the spring is stretched by a length of L, then it exerts on the mass a force of k*L in the direction of the negative x-axis.

A spring that behaves as described in assumptions (2) and (3) above is called a linear spring and k (k > 0) is called the spring constant. The strength, or stiffness, of the spring is directly correlated with the spring constant.

1.1 State Variables

In a mathematical model, the state variables or field variables are quantities that characterize the behavior of the physical system. In the case of a spring-mass system, the state of the physical system is completely characterized by the velocity of the mass and the horizontal distance the mass is displaced from its equilibrium position, x = 0.

For a spring-mass system, we know from experience that if the spring is compressed (or stretched) with the mass located at x = X0 and then the mass is released with a velocity of V0, the mass will oscillate with time. This leads us to develop a mathematical model in which the state variables are time dependent.

1.2 Variables and Parameters

Mathematical models typically contain three distinct types of quantities: input variables, output variables and parameters. In the case of our spring-mass problem, an associated mathematical model will have:
Input Variables
Output Variables:
Parameters:

1.3 Notation

It is common practice to use shorthand notation for the variables and parameters. A convenient way of introducing the notation to be used in a mathematical model is the following tabular format.
 

Quantity

Symbol

Units

time t seconds
mass of object m kilograms
spring constant k  (k > 0)  meters/second/second
velocity of the object V or V(t) meters/second
displacement of the object  X or X(t) meters
initial velocity of the object V0 or V(0) meters/second
initial displacement of the object X0 or X(0) meters

1.4 Governing Physical Principles

A mathematical model for a spring-mass system can be developed from Newton's 2nd Law of motion and the definitions of velocity and momentum.

Definition of Velocity: Velocity equals the rate of change of position.

Definition of Momentum: Momentum equals mass times velocity.

Newton's 2nd Law:  Rate of change of momentum equals the applied force.

The definitions of velocity and momentum and Newton's 2nd Law are the physical principles from which we will develop two mathematical models for a spring-mass system.

2. Mathematical Models

2.1 A Discrete in Time Model

The Grid

To develop a discrete in time mathematical model, we mark off a time line as indicated in Fig. 2.

                   
      <----  h  ---->
------x------|------x------|------x------|------x------|-- (t-axis)
      t0     t1/2    t1     t3/2    t2    . . .
Figure 2. A time line with grid points marked by "x".
 
The points on the t-axis marked with the symbol " x " are called grid points or mesh points. They represent the discrete times at which the mathematical model will approximate the position of the mass. The points marked with the symbol " | " are the midpoints of the line segments joining adjacent time grid points. These midpoints will prove to be convenient time values for approximating velocities of the mass.

The grid we have defined is called a uniform grid since each pair of adjacent grid points are separated by a constant time interval. This time interval between grid points, h, is called the time step, the grid spacing or the mesh spacing.

Following the notation introduced in Figure 2, we can represent an arbitrary grid point on the t-axis as follows.

Note that ti+1 - ti = h, which is just a restatement of the fact that successive grid points are separated by a time interval of h.

In the notation table of Section 2.3, we have chosen to denote the physical displacement and velocity of the object by X(t) and V(t), respectively. A common notational convention in mathematical modeling is to use variables of an opposite case to denote the mathematical model approximations of physical quantities. Following this convention, we define xi to be a numerical approximation to X(ti) and vi to be a numerical approximation to V(ti).

Momentum Equation

To continue our development of a mathematical model of the spring-mass system, consider an object of mass m that is moving in a straight line. Suppose the object has initial velocity VI along the x-axis. The initial momentum of this object is

MO_I = m*VI.

Let VN denote the new velocity of the object after T seconds have elapsed. The new momentum of the object is

MO_N = m*VN

According to Newton's 2nd law, if a constant force F aligned with the x-axis is applied to this object for an interval of time T, then the change of momentum (new momentum minus old momentum) is equal to F times T.

MO_N = MO_I + F*T (1)

Displacement Equation

If an object moves along a line at a constant rate R for a time T, then the object moves a distance D. In words, "distance traveled (D) equals rate (R) multiplied by time (T)", or

D = R*T (2)

Put another way, if the initial position of the object is PI and the new position of the object T seconds later is PN, then

PN = PI + R*T

Equations (1) and (2) are special cases of the governing physical principles stated in Section 2.4.

Model Development

Recall that XO is the initial displacement and V0 is the initial velocity of the mass attached to the spring. Let v1/2 denote the numerical model velocity of the mass at t1/2 = h/2, the first point marked " | " .

The first step in development of a mathematical model for the spring-mass system is to obtain an estimate of v1/2. First, observe that the value of X0 determines the force applied to the object by the spring at time t0 = 0. If X0 > 0, then the spring is initially stretched and a force F = -k*X0 is applied to the object. The negative sign in the last equation accounts for the fact that the spring is pulling the object in the direction of the negative x-axis. If X0 < 0, then the spring is initially compressed and a force F = -k*X0 is applied to the object. The negative sign in the last expression for F accounts for the fact that X0 is negative, but in the case of compression of the spring the force F is directed along the positive x-axis.

As time proceeds from t0 = 0 to t1/2 = h/2, the elongation or compression of the spring varies and thus the force applied to the object varies with time. In our development of a discrete in time mathematical model, we do not attempt to reconcile variations in the physical system within a time step. Instead, we will make the modeling assumption that during the time period from t0 = 0 to t1/2 = h/2, the force applied to the object by the spring is given by the constant value of F = -k*X0.

Setting VI = m*V0, VN = m*v1/2, T = (h/2) and F = -k*X0 in Equation (1) yields

m*v1/2 = m*V0 + (-k*X0)*(h/2)

from which we can conclude that

v1/2 = V0 - k*X0*(h/2)     (3a)

Similar reasoning for successive points marked " | " yields,

v3/2 = v1/2 - k*x1*h/m,    v5/2 = v3/2 - k*x2*h/m, ...   (3b)

provided the locations x1, x2, ... of the object can be computed.

Now we turn to the part of the mathematical model that deals with estimating the position of the object as time varies. Recall that X0 is the initial position of the mass. During the time interval t0 = 0 to t1 = h, the velocity of the mass is known to be V0 at t = 0 and estimated at t1/2 = h/2 by Equation (3a). Thus, we have two values of velocity available to represent the motion of the object during the time t = 0 to t = h. As a modeling assumption, we choose the constant v1/2 to represent the velocity of the mass over the period t = 0 to t = h.

Now that we have assumed a constant velocity during t = 0 to t = h, we can apply Equation (2) to estimate the position of the mass at time t1 = h. In Equation (2) let

PI = X0 (the initial position),
R = v1/2,
T = h and
PN = x1
to conclude

x1 = X0 + v1/2*h    (4a)

Similar reasoning for successive grid points marked " x " in Figure 1 yields

x2 = x1+ v3/2*h,  x3 = x2 + v5/2*h, ...    (4b)

Equations (3a,b) and (4a,b) are the core of our discrete in time mathematical model for a spring-mass system . We will defer the discussion of how to implement this mathematical model until Section 3.

2.2 A Continuous in Time Mathematical Model

For our spring-mass example, a continuous in time mathematical model can be formulated very simply in terms of derivatives as follows.

V'(t) = -kX(t),    V(0) = V0

X'(t) = V(t),      X(0) = X0

where the prime ' denotes differentiation with respect to time.

Those who have studied calculus can verify that the exact solution to the above mathematical model is given by

X(t) = (X0)*cos(r*t) + (V0/r)*sin(r*t)        and     V(t) = -(X0 *r)*sin(r*t)+ (V0)*cos(r*t)

where r = sqrt(k/m)

Later we will compare the mathematical model predictions from the discrete in time method with the continuous in time method.

3. Algorithm for the Discrete Mathematical Model

In this section we will proceed with a computer implementation of the discrete mathematical model of a spring-mass system. Recall that the discrete mathematical model is based on Equations (3a,b) and (4a,b).

3.1 Pseudocode

Before setting out to write C or Fortran code to implement a mathematical model, it is usually a good idea to make sure the coding notation and coding logic are clear. A good first step is the creation of language-independent pseudocode which we later can implement in a particular programming language. There are many formatting styles for pseudocode, one of which is illustrated below.


Algorithm 1. Discrete in Time Mathematical Model of a Spring-Mass System

Step 1. Document the Code

This algorithm uses the discrete in time mathematical model defined by Equations (3a,b) and (4a,b) to approximate the velocity and position of a mass attached to a spring. The initial velocity of the mass is V0 and the initial position is X0. The model is based on the assumptions that
(1) motion is in a horizontal straight line;
(2) friction is negligible and
(3) the spring is linear.

INPUT

V0 -- initial velocity (double precision)
X0 -- initial position (double precision)
k, -- spring constant (positive) (double precision)
m -- mass of object (double precision)
h -- time step (double precision)
imax -- number of time steps to perform (integer)

OUTPUT

for i = 0 to imax
ti -- t-value a time step i (double precision)
xi -- approximate mass position at time ti (double precision)
vi -- approximate mass velocity at time ti (double precision)

AUXILIARY VARIABLES

vi_left -- approximate velocity at time ti - .5*h (double precision)
vi_right -- approximate velocity at time ti + .5*h (double precision)
i -- loop counter (integer)

Step 2. Initialize numerical solution at t = 0

Set ti = 0
      vi = V0
      xi = X0
Print ti, vi, xi

Step 3. Calculate velocity at t = .5*h

Set vi_left = V0 -.5*k*xi*h/m

Step 4. Begin time stepping

For i = 1,2,...,imax
    Do steps 5-7

Step 5. Advance solution one time step

Set ti = ti + h
      xi = xi + vi_left*h
      vi_right = vi_left - k*xi*h/m
      vi = .5*(vi_left + vi_right)

Step 6. Output numerical solution

Output ti, xi, vi

Step 7. Prepare for next time step

Set vi_left = vi_right


3.2 C Code Algorithms

Two C versions of the psuedocode are given. The first version accepts input from the keyboard and displays the results to the screen. The second version reads input values and parameters from a file (spring.dat) and writes the output to another file (spring.out).

3.3 Fortran Code

Here is Fortran source code implementation of the pseudocode of Section 3.1.

4. Computational Experiments and Model Refinements

4.1 Computational Experiments

To become familiar with the behavior of the discrete in time mathematical model for a spring mass system, perform the following experiments.

Experiment 1. Compile the C or Fortran code. Then make several runs with X0 = 1.0 meters, V0 = 0 meters/second and in different runs choose different values for the time step h. Choose imax sufficiently large so that the mass passes through the origin x = 0 several times. Compare the time values when the mass is over the origin for the different time steps. How does the model behave if the user should accidently enter a negative value of spring constant k? What is the model behavior is a negative value of time step h is used?

Experiment 2. Modify the C or Fortran code so that the modified code prints out the difference between the continuous in time model and the discrete in time model at each grid point. Run the modified code for various choices of Z0, V0 and h. What do you conclude about the accuracy of the discrete in time model?

4.2 Model Refinements

Model Refinement 1. When we observe a physical spring-mass system we see that the mass eventually comes to rest. The physical mechanism which prevents the mass from oscillating forever is friction between the mass and the supporting surface. In a refined version of our mathematical model of a spring-mass system, we must account for both the spring force and the frictional force. If we make the modeling assumption that the friction force is proportional to the speed of the mass and acts in the direction opposite to the velocity, then the friction force applied to the mass is

Friction Force = -s V(t)

where the constant s is proportional to the amount of sliding friction experienced by the mass. The negative sign makes the frictional force act in the direction opposite to the direction of travel and thus retard the motion of the mass. Reformulate the continuous in time mathematical model to incorporate the above expression for friction force. Can you find the exact solution to this modified continuous in time model?

Model Refinement 2. In the original discrete in time mathematical model the velocity variable is advanced in time in accordance with Newton's 2nd Law using the equation

Consider the following modification designed to incorporate friction into the mathematical model. Can you explain each term in this equation in terms of Newton's 2nd Law? Modify one of the spring-mass codes to incorporate the last equation and test your modified code to see if it behaves as you would expect.