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. 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

Link

  1. GlowScript 2.7 VPython
  2.  
  3. running=True #Sets up condition for pause/run button
  4.  
  5. totalTime=20 #in seconds
  6.  
  7. #Variables/Objects
  8. k=int(prompt("Spring constant?: ")) #prompt allows user to set spring constant
  9. #Graphs below measure position, velocity, and acceleration as a function of time
  10. f4 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  11. f5 = gcurve(color=color.green, label='position',fast=True)
  12. f6 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)
  13. f7 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)
  14. f1 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  15. f1 = gcurve(color=color.green, label='position',fast=True)
  16. f2 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  17. f2 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)
  18. f3 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  19. f3 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)
  20.  
  21. #The mass and spring hang from the ceiling
  22. ceiling = box(pos=vec(0,11.5,0),size=vec(8,1,1), color=color.red)
  23.  
  24. Mass = box(pos=vector(0,-10,0),size=vec(2,2,2),velocity=vector(0,0,0),color=color.green,mass=1)
  25.  
  26. def setmass(s):
  27. return
  28. #Using a slider for the mass allows the user to change the mass, ranging from 1 to 5 kg
  29. mass = slider( min=1, max=5, value=1, align='right',step=0.5, length=220, bind=setmass)
  30.  
  31. pivot = vector(0,10,0)
  32.  
  33. spring = helix(pos=pivot,axis=Mass.pos-pivot,radius=0.8,coils=20,constant=k,thicnkess=0.1,color=color.green)
  34. #When you hang a mass from a spring, the spring stretches and the equilibrium point gets moved down
  35. eq = vector(0,Mass.mass*-9.81/k,0)
  36.  
  37. #We are starting with time t=0, and changing every .05 seconds
  38. t = 0
  39. dt = .05 #if time step is smaller than this, then completion time will not be the total time duration.
  40. print('mass = 1', 'spring constant = ', k)
  41.  
  42. #The code below allows the user to pause/run the program by pushing a button at the top
  43. def Run(b):
  44. global running
  45. running = not running
  46. if running:
  47. b.text = "Pause"
  48. running=True
  49. else:
  50. b.text = "Run"
  51. running=False
  52. button(text="Pause", pos=scene.title_anchor, bind=Run)
  53.  
  54. #In the while loop below, the forces (gravity, spring, and net) are being updated
  55. #Also, the acceleration, velocity, and position of the box are being updated
  56.  
  57. while True:
  58.  
  59.  
  60. if running==True:
  61. frameRate = 1/dt
  62. rate(frameRate)
  63. Fg = vec(0,Mass.mass*-9.81,0)
  64. if eq.y < Mass.pos.y:
  65. Fs = vec(0, -k*mag(Mass.pos-eq),0)
  66. else:
  67. Fs = vec(0, k*mag(Mass.pos-eq),0)
  68. #something needs to happen here
  69. Fnet = Fg
  70. acc = Fnet/(Mass.mass)
  71.  
  72.  
  73. Mass.velocity = Mass.velocity+acc*dt
  74. Mass.pos = Mass.pos+Mass.velocity*dt
  75. spring.axis = Mass.pos-spring.pos
  76.  
  77.  
  78. if mass.value != Mass.mass:
  79. print('mass = ', mass.value, 'spring constant = ', k)
  80.  
  81. Mass.mass=mass.value
  82.  
  83.  
  84. f1.plot(t,Mass.pos.y)
  85. f2.plot(t,Mass.velocity.y)
  86. f3.plot(t,acc.y)
  87. f5.plot(t,Mass.pos.y)
  88. f6.plot(t,Mass.velocity.y)
  89. f7.plot(t,acc.y)
  90.  
  91.  
  92. t = t + dt
  93. if running==False:
  94.  
  95. frameRate =1/dt
  96. rate(frameRate)
  97. acc = (eq-Mass.pos)*(spring.constant/Mass.mass)*0
  98. Mass.velocity = Mass.velocity
  99. Mass.pos = Mass.pos
  100. spring.axis = spring.axis

Answer Key

Handout

Pre-coding Questions
  1. INSERT PHOTO
  2. INSERT PHOTO
  3. 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

Code

  1. GlowScript 2.7 VPython
  2.  
  3. running=True #Sets up condition for pause/run button
  4.  
  5. totalTime=20 #in seconds
  6.  
  7. #Variables/Objects
  8. g=float(prompt("Acceleration due to Gravity?: "))
  9. while g>0:
  10. g=0
  11. g=float(prompt("ERROR: Acceleration due to Gravity is down: "))
  12. k=int(prompt("Spring constant?: "))#prompt allows user to set spring constant
  13.  
  14. #Graphs below measure position, velocity, and acceleration as a function of time
  15. f4 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  16. f5 = gcurve(color=color.green, label='position',fast=True)
  17. f6 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)
  18. f7 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)
  19. f1 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  20. f1 = gcurve(color=color.green, label='position',fast=True)
  21. f2 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  22. f2 = gcurve(type='scatter', color=color.blue, label='velocity',fast=True)
  23. f3 = graph(xmin=0,xmax=totalTime,xtitle='<i>t</i> in seconds')
  24. f3 = gcurve(type='scatter', color=color.red, label='acceleration',fast=True)
  25.  
  26. #The mass and spring hang from the ceiling
  27. ceiling = box(pos=vec(0,11.5,0),size=vec(8,1,1), color=color.red)
  28.  
  29. Mass = box(pos=vector(0,-10,0),size=vec(2,2,2),velocity=vector(0,0,0),color=color.green,mass=1)
  30.  
  31. def setmass(s):
  32. return
  33. #Using a slider for the mass allows the user to change the mass, ranging from 1 to 5 kg
  34. mass = slider( min=1, max=5, value=1,label='Mass' ,align='right',step=0.5, length=220, bind=setmass)
  35.  
  36. pivot = vector(0,10,0)
  37.  
  38. spring = helix(pos=pivot,axis=Mass.pos-pivot,radius=0.8,coils=20,constant=k,thicnkess=0.1,color=color.green)
  39. #When you hang a mass from a spring, the spring stretches and the equilibrium point gets moved down
  40. eq = vector(0,Mass.mass*g/k,0)
  41.  
  42. #We are starting with time t=0, and changing every .05 seconds
  43. t = 0
  44. dt = .05 #if time step is smaller than this, then completion time will not be the total time duration.
  45. print('mass = 1 kg | ', 'spring constant = ', k,'N/m', ' | gravity is:',g, 'm/s/s')
  46.  
  47. #The code below allows the user to pause/run the program by pushing a button at the top
  48. def Run(b):
  49. global running
  50. running = not running
  51. if running:
  52. b.text = "Pause"
  53. running=True
  54. else:
  55. b.text = "Run"
  56. running=False
  57. button(text="Pause", pos=scene.title_anchor, bind=Run)
  58.  
  59. #In the while loop below, the forces (gravity, spring, and net) are being updated
  60. #Also, the acceleration, velocity, and position of the box are being updated
  61.  
  62. while True:
  63. if t > totalTime:
  64. running=False
  65.  
  66. if running==True:
  67. frameRate = 1/dt
  68. rate(frameRate)
  69. Fg = vec(0,Mass.mass*g,0)
  70. if eq.y < Mass.pos.y:
  71. Fs = vec(0, -k*mag(Mass.pos-eq),0)
  72. else:
  73. Fs = vec(0, k*mag(Mass.pos-eq),0)
  74. Fnet = Fg + Fs
  75. acc = Fnet/(Mass.mass)
  76.  
  77.  
  78. Mass.velocity = Mass.velocity+acc*dt
  79. Mass.pos = Mass.pos+Mass.velocity*dt
  80. spring.axis = Mass.pos-spring.pos
  81.  
  82.  
  83. if mass.value != Mass.mass:
  84. print('mass = ', mass.value,'kg' ,'| spring constant = ', k,'N/m', '| gravity is:', g, 'm/s/s')
  85.  
  86. Mass.mass=mass.value
  87.  
  88.  
  89. f1.plot(t,Mass.pos.y)
  90. f2.plot(t,Mass.velocity.y)
  91. f3.plot(t,acc.y)
  92. f5.plot(t,Mass.pos.y)
  93. f6.plot(t,Mass.velocity.y)
  94. f7.plot(t,acc.y)
  95.  
  96.  
  97. t = t + dt
  98. if running==False:
  99.  
  100. frameRate =1/dt
  101. rate(frameRate)
  102. acc = (eq-Mass.pos)*(spring.constant/Mass.mass)*0
  103. Mass.velocity = Mass.velocity
  104. Mass.pos = Mass.pos
  105. spring.axis = spring.axis

See Also

  • repository/solar_system_springs.txt
  • Last modified: 2020/09/03 15:40
  • by porcaro1