## Solar System Springs

### Activity Information

#### Learning Goals

• Understand how a spring constant ($k$) affects simple harmonic motion
• Understand effects of mass and gravity on simple harmonic motion

#### Prior Knowledge Required

• Free-body diagrams
• Hooke's Law
• $F=-kx$

#### Code Manipulation

• Creating/modifying existing code
• Translating physical concepts and equations into code

—-

### Activity

#### Handout

Solar System Springs You and your team have the opportunity to board the Sol Spacecraft to explore the solar system. Should you choose to accept the mission, NASA requires you to study the action of springs on each of the planets. Some planets do not have a solid surface, so your experiment will be conducted as you hover deep within the planet's atmosphere. Your experiments will examine the effect of each planet's gravitational field on the oscillation of a spring. You also have another container filled with many different masses.

Your gravimeter gives you the following values for $g$ on each planet:

(Dwarf*) Planet $g$ (m/s²)
Mercury -3.6
Venus -8.9
Earth -9.8
Mars -3.8
Jupiter -26.0
Saturn -11.1
Uranus -10.7
Neptune -14.1
Pluto* -0.42
##### Pre-coding Questions
1. Complete a free body diagram for each of the 5 following cases:
1. Case 1: The mass is at the equilibrium point
2. Case 2: The mass is above the equilibrium point
3. Case 3: The mass is below the equilibrium point
4. Case 4: The mass is between equilibrium and the top
5. Case 5: The mass is between the equilibrium and bottom
2. Create a diagram showing the acceleration and velocity vectors for each of the aforementioned cases.
3. Run the minimally working code (below). The code allows the user to input the value for the spring constant ($k$) and change the mass of the crate ($m$) using a slider. What problem(s) do you see with the simulation?

Fortunately, the code is not entirely complete; you have a fantastic opportunity to fix it! Modify the code to make the spring oscillate appropriately. Also, add some lines of code so that you can change the acceleration due to gravity and perform a check to make sure the value is in the “down” direction (the “up” direction is set as positive). Make sure that the acceleration due to gravity is reported in the window that prints the mass and spring constant. Once you have verified that your code is running properly, complete the following questions.

##### Post-coding Questions
1. Sketch a graph of the position, velocity, and acceleration of the mass as functions of time. Use the graph produced by the program as a guide.
2. When the mass is at the top of its oscillations, what is the velocity and acceleration? Are they a minimum, maximum, or intermediate value?
3. When the mass is at the equilibrium point, what is the velocity and acceleration? Are they a minimum, maximum, or intermediate value?
4. When the mass is at the bottom, what is the velocity and acceleration? Are they a minimum, maximum, or intermediate value?
5. Run the program multiple times keeping the mass and acceleration due to gravity the same, but change the spring constant. Record your observations. What effect does changing the spring constant have on the amplitude for position, velocity, and acceleration? How does this affect the frequency and period of the oscillation?
6. Now run the program multiple times keeping the spring constant and acceleration due to gravity the same, but change the mass. Record your observations. What effect does changing the mass have on the amplitude for position, velocity, and acceleration? How does this affect the frequency and period of the oscillation?
7. Finally, run the program multiple times keeping the spring constant and mass the same, but change the acceleration due to gravity. Record your observations. What effect does changing the acceleration due to gravity have on the amplitude for position, velocity, and acceleration? How does this affect the frequency and period of the oscillation?

#### Code

GlowScript 2.7 VPython running=True     #Sets up condition for pause/run button totalTime=20 #in seconds #Variables/Objectsk=int(prompt("Spring constant?: ")) #prompt allows user to set spring constant#Graphs below measure position, velocity, and acceleration as a function of timef4 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f5 = gcurve(color=color.green, label='position',fast=True)f6 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)f7 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)f1 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f1 = gcurve(color=color.green, label='position',fast=True)f2 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f2 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)f3 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f3 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True) #The mass and spring hang from the ceilingceiling = box(pos=vec(0,11.5,0),size=vec(8,1,1), color=color.red) Mass = box(pos=vector(0,-10,0),size=vec(2,2,2),velocity=vector(0,0,0),color=color.green,mass=1) def setmass(s):  return#Using a slider for the mass allows the user to change the mass, ranging from 1 to 5 kgmass = slider( min=1, max=5, value=1, align='right',step=0.5, length=220, bind=setmass) pivot = vector(0,10,0) spring = helix(pos=pivot,axis=Mass.pos-pivot,radius=0.8,coils=20,constant=k,thicnkess=0.1,color=color.green)#When you hang a mass from a spring, the spring stretches and the equilibrium point gets moved downeq = vector(0,Mass.mass*-9.81/k,0) #We are starting with time t=0, and changing every .05 secondst = 0dt = .05 #if time step is smaller than this, then completion time will not be the total time duration.print('mass = 1', 'spring constant = ', k) #The code below allows the user to pause/run the program by pushing a button at the topdef Run(b):      global running      running = not running      if running:        b.text = "Pause"        running=True      else:         b.text = "Run"        running=Falsebutton(text="Pause", pos=scene.title_anchor, bind=Run)   #In the while loop below, the forces (gravity, spring, and net) are being updated#Also, the acceleration, velocity, and position of the box are being updated while True:      if running==True:      frameRate = 1/dt      rate(frameRate)      Fg = vec(0,Mass.mass*-9.81,0)      if eq.y < Mass.pos.y:        Fs = vec(0, -k*mag(Mass.pos-eq),0)      else:        Fs = vec(0, k*mag(Mass.pos-eq),0)      #something needs to happen here      Fnet = Fg      acc = Fnet/(Mass.mass)         Mass.velocity = Mass.velocity+acc*dt      Mass.pos = Mass.pos+Mass.velocity*dt      spring.axis = Mass.pos-spring.pos        if mass.value != Mass.mass:        print('mass = ', mass.value, 'spring constant = ', k)       Mass.mass=mass.value        f1.plot(t,Mass.pos.y)      f2.plot(t,Mass.velocity.y)      f3.plot(t,acc.y)      f5.plot(t,Mass.pos.y)      f6.plot(t,Mass.velocity.y)      f7.plot(t,acc.y)        t = t + dt    if running==False:       frameRate =1/dt      rate(frameRate)      acc = (eq-Mass.pos)*(spring.constant/Mass.mass)*0      Mass.velocity = Mass.velocity      Mass.pos = Mass.pos      spring.axis = spring.axis

#### Handout

##### Pre-coding Questions
1. There are 2 major problems with the code:
1. The program does not stop, despite there being code alluding to a 20 second run-time (line 5)
2. The spring does not oscillate, but rather extends infinitely. This is due to the “Fnet” in line 69 only including the force of gravity but not the force of the spring
##### Post-coding Questions
1. 2. When the mass is at the top of its oscillation, the velocity is at a minimum and its acceleration is at a maximum (the force of gravity and the force of the compressed spring are pulling and pushing the mass down)
3. When the mass is at the equilibrium point, its velocity is at a maximum, and its acceleration is at a minimum (the spring and the force of gravity counteract each other and the net force is 0)
4. When the mass is at the bottom of its acceleration, the velocity is at a minimum and the acceleration is at a maximum value (although the force of gravity is still pulling the mass downwards, the force of the stretched spring pulling the mass upwards will result in a net force that causes the same magnitude acceleration as when the spring is at the top of its oscillation)
5. Increasing the spring constant affects the stiffness of the spring. The higher the constant, the stiffer the spring is. A higher spring constant results in smaller amplitude for position, but higher amplitudes for velocity and acceleration. Additionally, the frequency of the oscillation increases, and therefore the period decreases

#### Code

GlowScript 2.7 VPython running=True     #Sets up condition for pause/run button totalTime=20 #in seconds #Variables/Objectsg=float(prompt("Acceleration due to Gravity?: "))while g>0:  g=0  g=float(prompt("ERROR: Acceleration due to Gravity is down: "))k=int(prompt("Spring constant?: "))#prompt allows user to set spring constant #Graphs below measure position, velocity, and acceleration as a function of timef4 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f5 = gcurve(color=color.green, label='position',fast=True)f6 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)f7 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)f1 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f1 = gcurve(color=color.green, label='position',fast=True)f2 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f2 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)f3 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')f3 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True) #The mass and spring hang from the ceilingceiling = box(pos=vec(0,11.5,0),size=vec(8,1,1), color=color.red) Mass = box(pos=vector(0,-10,0),size=vec(2,2,2),velocity=vector(0,0,0),color=color.green,mass=1) def setmass(s):  return#Using a slider for the mass allows the user to change the mass, ranging from 1 to 5 kgmass = slider( min=1, max=5, value=1,label='Mass' ,align='right',step=0.5, length=220, bind=setmass) pivot = vector(0,10,0) spring = helix(pos=pivot,axis=Mass.pos-pivot,radius=0.8,coils=20,constant=k,thicnkess=0.1,color=color.green)#When you hang a mass from a spring, the spring stretches and the equilibrium point gets moved downeq = vector(0,Mass.mass*g/k,0) #We are starting with time t=0, and changing every .05 secondst = 0dt = .05 #if time step is smaller than this, then completion time will not be the total time duration.print('mass = 1 kg | ', 'spring constant = ', k,'N/m', ' | gravity is:',g, 'm/s/s') #The code below allows the user to pause/run the program by pushing a button at the topdef Run(b):      global running      running = not running      if running:        b.text = "Pause"        running=True      else:         b.text = "Run"        running=Falsebutton(text="Pause", pos=scene.title_anchor, bind=Run)   #In the while loop below, the forces (gravity, spring, and net) are being updated#Also, the acceleration, velocity, and position of the box are being updated while True:    if t > totalTime:      running=False     if running==True:      frameRate = 1/dt      rate(frameRate)      Fg = vec(0,Mass.mass*g,0)      if eq.y < Mass.pos.y:        Fs = vec(0, -k*mag(Mass.pos-eq),0)      else:        Fs = vec(0, k*mag(Mass.pos-eq),0)      Fnet = Fg + Fs      acc = Fnet/(Mass.mass)        Mass.velocity = Mass.velocity+acc*dt      Mass.pos = Mass.pos+Mass.velocity*dt      spring.axis = Mass.pos-spring.pos        if mass.value != Mass.mass:        print('mass =  ', mass.value,'kg' ,'| spring constant = ', k,'N/m', '| gravity is:', g, 'm/s/s')       Mass.mass=mass.value        f1.plot(t,Mass.pos.y)      f2.plot(t,Mass.velocity.y)      f3.plot(t,acc.y)      f5.plot(t,Mass.pos.y)      f6.plot(t,Mass.velocity.y)      f7.plot(t,acc.y)        t = t + dt    if running==False:       frameRate =1/dt      rate(frameRate)      acc = (eq-Mass.pos)*(spring.constant/Mass.mass)*0      Mass.velocity = Mass.velocity      Mass.pos = Mass.pos      spring.axis = spring.axis