—-
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 |
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.
GlowScript 2.7 VPython running=True #Sets up condition for pause/run button totalTime=20 #in seconds #Variables/Objects k=int(prompt("Spring constant?: ")) #prompt allows user to set spring constant #Graphs below measure position, velocity, and acceleration as a function of time f4 = 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 ceiling ceiling = 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 kg mass = 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 down eq = vector(0,Mass.mass*-9.81/k,0) #We are starting with time t=0, and changing every .05 seconds t = 0 dt = .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 top def Run(b): global running running = not running if running: b.text = "Pause" running=True else: b.text = "Run" running=False button(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
GlowScript 2.7 VPython running=True #Sets up condition for pause/run button totalTime=20 #in seconds #Variables/Objects g=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 time f4 = 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 ceiling ceiling = 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 kg mass = 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 down eq = vector(0,Mass.mass*g/k,0) #We are starting with time t=0, and changing every .05 seconds t = 0 dt = .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 top def Run(b): global running running = not running if running: b.text = "Pause" running=True else: b.text = "Run" running=False button(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