Simple harmonic motion: horizontal spring mass system with no friction
Author: Andrea Houck
Author: Andrea Houck
We create a horizontal spring-mass system on frictionless surface to understand simple harmonic motion. We begin by creating a figure to show the spring-mass system. We create a figure of a block attached to a spring that moves with time. We label the displacement of the block from the equilibrium position and the force on the block in order to understand their relationship and how they change throughout the oscillation. The oscillation is described by the position equation, so we use the position equation to determine the position of the block in the oscillation when we animate the system. The animation of the system moves with the velocity and acceleration described by simple harmonic motion. We then plot the position, velocity, and acceleration graphs of the spring-mass system to gain a better understanding of their patterns. As a single figure, we animate the spring-mass system, position, velocity, and acceleration graphs to see the relationship between what is visually happening in the figure, and how the position, velocity, and acceleration relate to each other in this system.
Introduction
Introduction
This computational essay will demonstrate the motion of a mass spring system on a horizontal frictionless surface. We build on the ideas presented by [1]. The format of a computational essay allows for a concept to be explained through text and shown through code and output graphics [3]. The graphics and the accompanying text in this computational essay can be useful in educational settings. Students can visualize the motion of a mass-spring system on a frictionless surface as the input for different variables is adjusted to better understand their relationship. We also use text to describe how we write the code to produce the graphic so the process can be replicated and adjusted for other applications.
In our system, the spring is fixed on one end, attached to a stationary wall. The other end of the spring is attached to a mass in the shape of a block. When the block is still with no net force, the block is in equilibrium. When the block is closer to the wall than the equilibrium position, the spring is compressed and puts force on the block. When the block is further from the wall than the equilibrium position, the spring is expanded and tries to pull the block back to equilibrium. Therefore, the mass oscillates around the equilibrium position. The equilibrium position of the mass is marked with a dashed line at the edge of the block closest to the stationary wall, to be referenced when the block begins moving.
This essay will begin with a stationary system at equilibrium, then present an animation of the oscillating block with the direction of the force displayed along with the displacement x. The system is then animated and shown with the corresponding position, velocity, and acceleration graphs as functions of time. The user can adjust the maximum displacement of the block from its equilibrium position, the spring constant, and the mass of the block to see how these parameters affect the spring mass system.
In our system, the spring is fixed on one end, attached to a stationary wall. The other end of the spring is attached to a mass in the shape of a block. When the block is still with no net force, the block is in equilibrium. When the block is closer to the wall than the equilibrium position, the spring is compressed and puts force on the block. When the block is further from the wall than the equilibrium position, the spring is expanded and tries to pull the block back to equilibrium. Therefore, the mass oscillates around the equilibrium position. The equilibrium position of the mass is marked with a dashed line at the edge of the block closest to the stationary wall, to be referenced when the block begins moving.
This essay will begin with a stationary system at equilibrium, then present an animation of the oscillating block with the direction of the force displayed along with the displacement x. The system is then animated and shown with the corresponding position, velocity, and acceleration graphs as functions of time. The user can adjust the maximum displacement of the block from its equilibrium position, the spring constant, and the mass of the block to see how these parameters affect the spring mass system.
Basic figure
Basic figure
The simplest version of the figure is when the whole system is stationary and the block is at equilibrium. We start with this simple version to understand the ideas of how to construct the system.
Creating the block
Creating the block
We create a function for creating the block to easily use in other parts of the code. Since the block will eventually move horizontally, we leave x as a variable by defining the block as a function of x.
The block' s position is defined by the location of the edge closest to the wall and attached to the spring, which we define as x. The units associated with x are meters. We create the system to be in equilibrium when the value of x is 0 meters and has the bottom of the block resting at . We use the options Dashed and Thick to draw a dashed line at the edge of the block. We then create the block by using the options EdgeForm (Thick) to create a thick outline, Purple to specify the color, Opacity[0.25] to make the block a lighter color, then specifying the shape is rectangle and giving the coordinates. We define the bottom edge of the block to be at y=0, giving the coordinate of the bottom left hand side of the block as (0, 0) when the system is in equilibrium. We must also define the top right corner of the block by adding the width of the block to x and choosing a height. We chose a square block that is 1m wide by adding 1 to x and 1m tall by plugging in 1 for the y-coordinate.
y=0m
In[]:=
block[x_]:=Graphics[{{Dashed,Thick,Line[{{x,1.25},{x,-1}}]},{EdgeForm[Thick],Purple,Opacity[0.25],Rectangle[{x,0},{x+1,1}]}}];
To see the block at equilibrium position, we plug in 0 for x as follows. We use Labeled to add a caption to the figure.
In[]:=
Labeled[block[0],"Figure 1: Block in equilibrium position."]
Out[]=
Figure 1: Block in equilibrium position. |
Creating the wall and surface
Creating the wall and surface
We now create the wall and a surface on which the block sits using the function Graphics.
To construct the surface, we need to draw a line centered at the equilibrium position of the block, , with the y-value equal to 0 to match that of the block. We choose that the surface extends from to and place the wall at . We use dashed lines to extend the both the wall and the position of the block that we will be measuring to below the surface for labeling purposes.
x=0m
x=-5m
x=5m
x=-5m
In[]:=
surface=Graphics[{{Thick,Line[{{-5,1.25},{-5,0},{5,0}}]},{Dashed,Thick,Line[{{-5,0},{-5,-1}}]}}];
Again, we use Labeled to caption the figure.
In[]:=
Labeled[surface,"Figure 2: Surface."]
Out[]=
Figure 2: Surface. |
Creating the Spring
Creating the Spring
We now create the spring by defining it as a function of x. On the ends of the spring, we draw short line segments to connect the spring to the wall and to the mass using Line. We then use the function Table to store the values of points to create the spring. The x-values and y-values in the table are helix formulas that include the index i in order to go through all values necessary to calculate the points through which the spring must pass without having to list all the points.
In[]:=
spring[x_]:=Graphics[Line[{{{x-0.6,0.5},{x,0.5}},{{-5,0.5},{-4.5,0.5}},Table[{((x+3.9)/500i+0.1(1-Cos[π/10(i-1)]))-4.5,0.5+0.1Sin[π/10(i-1)]},{i,1,501}]}]];
We can display the spring by plugging in a value for x and caption the figure using Labeled.
In[]:=
Labeled[spring[0],"Figure 3: Spring"]
Out[]=
Figure 3: Spring |
To be useful, we must combine the parts of the system into a single figure.
Combining the figures to create one system
Combining the figures to create one system
We use Show to display the output from the two parts of the system coded above in a single figure. Since each component of the system is defined as it’s own function, we only need to include the function definitions and provide values for each of the variables. As an option for Manipulate, which allows us to adjust the position of the block using the slider we use Style. This allows us to specify the initial position of the block, which we choose to be the equilibrium position, label the slider as Block Position, and still provide a range in which the position can be changed. Around Manipulate, we use Labeled to caption the figure.
,
In[]:=
DynamicModule[{},block[x_]:=Graphics[{{Dashed,Thick,Line[{{x,1.25},{x,-1}}]},{EdgeForm[Thick],Purple,Opacity[0.25],Rectangle[{x,0},{x+1,1}]}}];surface=Graphics[{{Thick,Line[{{-5,1.25},{-5,0},{5,0}}]},{Dashed,Thick,Line[{{-5,0},{-5,-1}}]}}];spring[x_]:=Graphics[Line[{{{x-0.6,0.5},{x,0.5}},{{-5,0.5},{-4.5,0.5}},Table[{((x+3.9)/500i+0.1(1-Cos[π/10(i-1)]))-4.5,0.5+0.1Sin[π/10(i-1)]},{i,1,501}]}]];Labeled[Manipulate[Show[spring[x],surface,block[x]],{{x,0,Style["Block Position",12]},-3.5,3.5}],"Figure 4: Spring-mass system. We combine the surface, block, and spring into a single figure. The position of the block can be manipulated by adjusting the value of x in the slider. A smaller value of x brings the block closer to the wall and compresses the spring while a larger value of x expands the spring. When x=0, the spring is neither compressed or expanded, as the system is in equilibriumm."],SaveDefinitionsTrue]
Out[]=
Figure 4: Spring-mass system. We combine the surface, block, and spring into a single figure. The position of the block can be manipulated by adjusting the value of x in the slider. A smaller value of x brings the block closer to the wall and compresses the spring while a larger value of x expands the spring. When x=0, the spring is neither compressed or expanded, as the system is in equilibriumm. |
We can add text and arrows to the figure by creating functions for the desired labels, then combining them into a single function using Show.
Using Dashed as an option for Line within the function Graphics, we create a dashed line to visualize the equilibrium position. This line aligns with the left edge of the block when the block is at equilibrium.
In[]:=
equilibriumLine=Graphics[{Dashed,Line[{{0,1.25},{0,-1.5}}]}];
Next, we create labels to show the displacement of the block from equilibrium. Since this changes as the position of the block changes, we define this function in terms of x. We use Arrowheads and Arrow to draw the arrows with arrowheads on both ends. is the distance between the wall and the left side of the block while the block is in the equilibrium position whereas x is the displacement of the block. We label these arrows using Text.
X
0
In[]:=
displacementLabels[x_]:=Graphics[{{Arrowheads[0.02],Arrow[{{0,-0.15},{-5,-0.15}}],Arrow[{{-5,-0.15},{0,-0.15}}]},{Text["",{-1.5,-0.35}]},{Arrowheads[{0.02}],Arrow[{{0,-0.5},{x,-0.5}}],Text["x",{0.5x,-0.6}]}}];
X
0
The force can also be included. We use an arrow to indicate the direction of the force. Both the magnitude and direction of the force will change with time. A larger arrow indicates a larger force. We change the size of the arrow by having the arrow start at x, the left side of the block, and go to the equilibrium position of the left side of the block. Since there is no force on the block while in the equilibrium position, we use the condition to display the force equation and arrow only when the block is not in equilibrium. We then use the empty set to have the label function defined but not display anything when the block is in equilibrium.
x≠0
In[]:=
forceLabel[x_]/;x≠0:=Graphics[{{Red,Arrowheads[0.03],Arrow[{{x,0.85},{0,0.85}}],Text[Style["F = - k x",FontSize20],{0,1.5}]}}];forceLabel[0]={};forceLabel[0.]={};
To make the labels easier to add to the diagram, we combine all labels into a single function using Show. This function is also a function of x because some of the functions it contains are functions of x.
In[]:=
labels[x_]:=Show[equilibriumLine,forceLabel[x],displacementLabels[x]];
Now, we can combine the mass-spring system from Figure 4 with the labels into a single figure to make it easier to use.
In[]:=
system[x_]:=Show[spring[x],surface,block[x],labels[x]];
Using Manipulate, we can adjust the block position and see the corresponding labels.
In[]:=
DynamicModule[{},Labeled[Manipulate[system[x],{{x,0,Style["Block Position",12]},-3.5,3.5}],"Figure 5: Labeling the mass-spring system. We can see that adjusting the block position closer to the wall gives a negative displacement, represented by the black arrow labeled x, and a force in the positive x direction, represented by a red arrow labeled F=-kx. The closer to the wall, the greater the force. This is shown by increasing the size of the red force arrow. Moving the block farther from the wall than the equilibrium position results in the force flipping to point towards the wall in the negative x direction. Again, as the block moves farther from the equilibrium position, the force arrow gets larger to show that the force is greater. From these observations, we can conclude that the force always points towards the equilibrium position and therefore, the force is a restoring force."],SaveDefinitionsTrue]
Out[]=
Figure 5: Labeling the mass-spring system. We can see that adjusting the block position closer to the wall gives a negative displacement, represented by the black arrow labeled x, and a force in the positive x direction, represented by a red arrow labeled F=-kx. The closer to the wall, the greater the force. This is shown by increasing the size of the red force arrow. Moving the block farther from the wall than the equilibrium position results in the force flipping to point towards the wall in the negative x direction. Again, as the block moves farther from the equilibrium position, the force arrow gets larger to show that the force is greater. From these observations, we can conclude that the force always points towards the equilibrium position and therefore, the force is a restoring force. |
Since the force always points toward the equilibrium position, it is a restoring force. This means that the force always acts to bring the system back into equilibrium by returning the block to the equilibrium position. This restoring force creates the oscillation we see in simple harmonic motion, as we will better see when we animate the system. However, we will need to make some changes when animating the system to ensure the position of the block is accurate.
Animating the mass spring system
Animating the mass spring system
To animate the mass spring system, we need to understand the way the mass moves. The maximum velocity of the mass is at the equilibrium position. Closer to the wall to the equilibrium, the spring exerts force opposite the movement due to compression of the spring, slowing the block down until the velocity is equal to zero. The compressed spring's force on the block causes acceleration in the direction of the equilibrium. As the block passes the equilibrium point moving away from the wall, the velocity again slows to zero.
Determining the position
Determining the position
We know that the position of the block changes over time t according to the following equation because of simple harmonic motion. We use seconds as the unit of time.
The required value of δ in units of radians is found by setting time equal to 0 in the position equation. At t = 0, we consider the block to be at the equilibrium position, so r[0] = 0. We can then re-write the position equation to be
which we can use to solve for δ.
The position equation can now be expressed in code as a function of amplitude, spring constant, mass, and time as follows:
Determining the velocity at which the block moves
Determining the velocity at which the block moves
The velocity of the block v[t] is determined by taking the derivative of the position formula r[t]. Therefore, we can use the position formula to define the location of the mass in our code so that when changing time, the block will move in a manner consistent with the velocity equation. We evaluate the derivative of the position equation with the variable tt since the program cannot compute the derivative with respect to t if t has a value assigned to it. We can then evaluate the expression for when tt is equal to the value assigned t. This is done in code as follows.
Determining the acceleration of the block
Determining the acceleration of the block
The acceleration of the block a[t] is determined by taking the second derivative of the position formula, or the derivative of the velocity formula. We will use the derivative of the velocity formula.
A more accurate version of the spring mass figure
A more accurate version of the spring mass figure
Now, we can draw the figure in terms of the position formula by plugging in r[A,k,m,t] for x in the function definitions. Using the position formula to determine the x-value of the block is more accurate for describing the motion of the mass than just plugging in numbers for x. Leaving the position in terms of A, k, m, and t allows us to adjust the amplitude, spring constant, and mass while manipulating time.
Running the animation
Running the animation
Finally, we can animate the system. From [2], we see that using Trigger releases the system to change over time, thus running the animation. We keep manipulating the amplitude, spring constant, and mass as above. We specify AnimationRate to be 1 to set the speed at which the animation runs and set SynchronousUpdating to True to ensure the animation updates as the sliders are adjusted for the manipulable variables. When using a trigger, only the play button must be pushed to run the animation.
Now that we have the figure of the system running, we can look at the movement in terms of its position versus time, velocity versus time, and acceleration versus time graphs in order to better understand the motion.
Plotting the position, velocity, and acceleration of the mass
Plotting the position, velocity, and acceleration of the mass
Position
Position
We can add a point to the position versus time graph. This way, the point can move along the position curve to show how the position of the block in the figure relates to the graph. The point will move with the animated figure. We use Graphics to create the point. The directive PointSize is used with the option Large to specify the size of the point. Blue specifies the color of the point. The point itself is created using Point and putting the x-coordinate as the time t and y-coordinate as the position formula r[A, k, m, t]. We set this portion of the graph equal to positionpoint, which is a function of amplitude, spring constant, mass, and time. The time is included in this list because it is not pre-determined .
With the point and plot both represented in code, we can combine them into a single image by using Show and listing the components we want displayed. We set this equal to positiongraph, which is a function of all variables included within the components inside the Show brackets (amplitude, spring constant, mass, time). We use AxesLabel to label the axes with the quantity being measured and the units and add a title to the graph using PlotLabel.
We use Manipulate with positiongraph to see the position over time with both the plot and point above, and list each of the variables that positiongraph is a function of with their respective ranges. We can now manipulate the values for the amplitude, spring constant, mass, and time to see how they affect the position of the block.
Velocity
Velocity
The velocity of the mass can also be plotted as a function of time using the same method as that used to create the position versus time graph above.
We set velocitypoint as a function of amplitude, the spring constant, mass, and time equal to the graphics that creates the point. As with the point for the position graph, we specify the PointSize is Large and use Point to create a point at the x-coordinate t and the y-coordinate of the velocity at time t. We specify the point is red to match the curve.
Again, we combine the plot and point using Show. This is set equal to velocitygraph, which is a function of amplitude, the spring constant, mass, and time because the components shown in this line of code are functions of these variables.
Acceleration
Acceleration
We can also plot the acceleration of the block as a function of time the same way as the position and velocity functions.
We then create the point to show the acceleration as related to the position, velocity, and the figure. This is done using Graphics and its directive PointSize, which is followed by the option Large and Green to create a large green point. The primitive Point is used to actually create the point at the x-coordinate t and the y-coordinate that lies on the acceleration curve at point t. We set this equal to accelerationpoint, which is a function of amplitude, the spring constant, mass, and time.
We combine the acceleration plot and acceleration point using Show and set it equal to accelerationgraph, which is a function of amplitude, the spring constant, mass, and time.
We can now manipulate the acceleration graph by adjusting the amplitude, spring constant, mass, and time within the ranges indicated in the code below.
Combining the position, velocity, and acceleration plots with the figure of the spring mass system
Combining the position, velocity, and acceleration plots with the figure of the spring mass system
We combine the diagram of the block moving and the position, velocity and acceleration graphs into a single output to see how they relate. This is best done using Grid. We use 2 sets of curly brackets to create 2 rows in our grid. Each set has 2 terms to create two columns. We put system[r[A,k,m,t]] from above as the first term in the first set of curly braces to display the figure of the spring-mass system in the first column of the first row. We put the position versus time graph in the second column of the first row. The first column of the second row will contain the velocity graph with both the plot and the point. The acceleration graph is shown in the second row, second column.
Our input information system, positiongraph, velocitygraph, and accelerationgraph are all functions of amplitude, the spring constant, mass, and time. In order to display the figure and graphs, these values must be defined. We do this by adding Manipulate around Grid to adjust the values for the amplitude, spring constant, mass, and time within the given range as we did with system above.
The points on the graphs above correspond to where the figure is in the oscillation. We see that the velocity is at its maximum when the block is at its equilibrium position. We know that the velocity must be zero at the point of maximum displacement because the block changes which direction it moves. The spring at this point is expanded. While expanding, the spring will be exerting a force pulling the block back towards the equilibrium position in attempt to return to the spring to its natural length. This will slow the spring down. As the spring compresses, the spring resists compression, thus exerting a force on the spring. These forces on the spring slow the motion of the block as it approaches the maximum displacement. Using this same type of thinking, we can conclude that the maximum velocity occurs at the equilibrium position because this is the point just before the spring starts exerting force to oppose the block’s motion. We can also see the acceleration of the block is zero at the equilibrium position where the block has maximum velocity. This must be the case because the slope of the velocity curve at the maximum velocity is 0 since it is at a peak on the graph, and acceleration is the derivative of velocity. This conclusion makes sense because the net force on the block at equilibrium is zero. According to Newton’s second law, the sum of the forces is equal to the mass times the acceleration. Since the sum of the forces is zero and the mass is non-zero, the acceleration must be zero at the equilibrium position.
Acknowledgements
Acknowledgements
The work of A.H. was supported by a Student Research Award funded by the Howard Hughes Medical Institute (HHMI) Inclusive Excellence 2017 Grant to Lawrence Technological University. A.H. thanks Dr. Bhubanjyoti Bhattacharya for his support and guidance and for his help with debugging and making the animation run more smoothly.
References
References
[1] B. Bhattacharya, “Demonstration for a spring and mass systems on a surface without friction,” Wolfram Groups, available on the web at https://community.wolfram.com/groups/-/m/t/1195418
[2] S. Wilkerson, “Dynamics of a Double Spring Mass,” Wolfram Demonstrations Project (2011), available on the web at https://demonstrations.wolfram.com/DynamicsOfADoubleSpringMass/
[3] S. Wolfram, “What is a Computational Essay,” Stephen Wolfram Writings (2017), available on the web at https://writings.stephenwolfram.com/2017/11/what-is-a-computational-essay/
[2] S. Wilkerson, “Dynamics of a Double Spring Mass,” Wolfram Demonstrations Project (2011), available on the web at https://demonstrations.wolfram.com/DynamicsOfADoubleSpringMass/
[3] S. Wolfram, “What is a Computational Essay,” Stephen Wolfram Writings (2017), available on the web at https://writings.stephenwolfram.com/2017/11/what-is-a-computational-essay/

