In this lab we will investigate simple harmonic motion, a particular kind of oscillation. To get an oscillation, we need a restoring force, that is, a force that is always directed toward an equilibrium point. Any discplacement from equilibrium will then result in a force pushing the system back to equilibrium. However, when it gets there the system has kinetic energy, so it goes past the equilibrium point. The restoring force now slows it down and pushes it back toward the equilibrium point. This goes on forever if there is nothing removing energy from the system.
Any restoring force will result in an oscillating system, but a restoring force that is proportional to the displacement gives a sinusoidal oscillation which we call simple harmonic motion.
To examine simple harmonic motion, we will simulate a simple mass and spring system like you used to measure spring constant in an earlier lab. You will use the simulation to examine the relationships between period, amplitude, spring constant, and mass. You will also examine the relationship of position, velocity, and acceleration during the oscillation.
We'll expand the usefulness of this by adding a damping force to the system. A damping force is one that takes energy out of the system and causes the oscillations to diminish. Then we'll add a driving force to see how the frequency of the driving force affects the resulting motion.
Complete Question 1 in the Word document before doing anything with the simulation.
from pylab import * # Downloads libraries
#Variables
M = 0.25 #mass connected to the spring (kg)
k = 12.3 #spring constant (N/m or kg/s^2)
t = 0
dt = 0.001 #time step
tmax = 1 #max time that simulation will run
x = 0.1 #initial position of the mass relative to the equilibrium point
vx = 0 #intial velocity
#Creation of graph
figure(figsize=(18,6), dpi=160)
#Calculation loop
while t < tmax:
#Forces acting on the system
Fsp = -k*x
Fnet=Fsp
#Acceleration
ax=Fnet/M
#Graphs being plotted
subplot(311)
plot(t, x, 'bo', markersize=0.2)
ylabel('Postion [m]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
subplot(312)
plot(t, vx, 'bo', markersize=0.2)
ylabel('Velocity [m/s]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
subplot(313)
plot(t, ax, 'bo', markersize=0.2)
ylabel('Acceleration [m/s^2]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
#Velocity using euler approximation
vx=vx+ax*dt
#Distance traveled using euler approximation
x=x+vx*dt
#time step
t=t+dt
from pylab import * # Downloads libraries
#Variables
M = 0.25 #mass connected to the spring (kg)
k = 20 #spring constant (N/m or kg/s^2)
t = 0
dt = 0.001 #time step
tmax = 1 #max time that simulation will run
x = 0.5 #initial position of the mass relative to the equilibrium point
vx = 0 #intial velocity
#Creation of graph
figure(figsize=(18,6), dpi=160)
#Calculation loop
while t < tmax:
#Forces acting on the system
Fsp = -k*x
Fnet=Fsp
#Acceleration
ax=Fnet/M
#Graphs being plotted
plot(t, x, 'bo', markersize=0.2)
ylabel('Postion [m]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
#Velocity using euler approximation
vx=vx+ax*dt
#Distance traveled using euler approximation
x=x+vx*dt
#time step
t=t+dt
from pylab import * # Downloads libraries
#Variables
M = 0.25 #mass connected to the spring (kg)
k = 20 #spring constant (N/m or kg/s^2)
b = 0.2 #drag constant (kg/s)
t = 0
dt = 0.001 #time step
tmax = 10 #max time that simulation will run
x = 0.5 #initial position of the mass relative to the equilibrium point
vx = 0 #intial velocity
#Creation of graph
figure(figsize=(18,6), dpi=160)
#Calculation loop
while t < tmax:
#Forces acting on the system
Fsp = -k*x
Fdrag = -b*vx
Fnet=Fsp+Fdrag
#Acceleration
ax=Fnet/M
#Graphs being plotted
plot(t, x, 'bo', markersize=0.2)
ylabel('Postion [m]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
#Velocity using euler approximation
vx=vx+ax*dt
#Distance traveled using euler approximation
x=x+vx*dt
#time step
t=t+dt
from pylab import * # Downloads libraries
#Variables
M = 0.25 #mass connected to the spring (kg)
k = 20 #spring constant (N/m or kg/s^2)
b = 0.2 #drag constant (kg/s)
f = 1.75
Fmax = 0.123
t = 0
dt = 0.005 #time step
tmax = 20 #max time that simulation will run
x = 0 #initial position of the mass relative to the equilibrium point
vx = 0 #intial velocity
#Creation of graph
figure(figsize=(18,6), dpi=160)
#Calculation loop
while t < tmax:
#Forces acting on the system
Fsp = -k*x
Fapp = Fmax*sin(2*pi*f*t)
Fdrag = -b*vx
Fnet=Fsp+Fdrag+Fapp
#Acceleration
ax=Fnet/M
#Graphs being plotted
plot(t, x, 'bo', markersize=0.2)
ylabel('Postion [m]')
xlabel("time [s]")
grid(color = 'green', linestyle = '--', linewidth = 0.5)
#Velocity using euler approximation
vx=vx+ax*dt
#Distance traveled using euler approximation
x=x+vx*dt
#time step
t=t+dt
After having complete Questions 2-3, we won't need the plots of velocity and acceleration. Copy your code to a new code box below and modify to get just one plot of the position vs. time so you can see it better. Then complete questions 4-6.
Copy your code to a new code box below and add damping to the simulation to complete Questions 7 and 8.
For Questions 9-11, copy your code for the damped oscillator to a new code box below and add the driving force to the simulation.
If time permits, copy the code for the damped oscillator below and change it to plot kinetic, potential, and mechanical energy vs. time. You can set the damping constant to zero to use the same code to look at energy in undamped oscillations.
Submit your word document with any Excel graphs pasted into it. Also submit your python notebook.