Question: Hi! My professor asked me to create a simulation (for physics) of a spring in vPython. I was able to do that! (What I have

Hi!

My professor asked me to create a simulation (for physics) of a spring in vPython. I was able to do that! (What I have matches everything he wants and is correct).

GlowScript 2.7 VPython

from visual import *

scene.autoscale = False

scene.range = 20

display(width=600, height = 600, center = vec(6,0,0), background = color.black)

kinematicsgraph = gdisplay(xtitle = 'time', ytitle = 'Kinematic Quantity')

velocityy = gcurve(gdisplay = kinematicsgraph, color=color.green, label = 'Velocity')

positiony = gcurve(gdisplay = kinematicsgraph, color=color.blue, label = 'Position')

accelerationy = gcurve(gdisplay = kinematicsgraph,color=color.red,label = 'Acceleration')

energygraph = gdisplay(xtitle = 'time' , ytitle = 'energy')

totalenergy = gcurve(gdisplay = energygraph, color=color.black, label = 'Total energy')

kineticenergy = gcurve(gdisplay = energygraph,color = color.green, label = 'Kinetic energy')

potentialenergy = gcurve(gdisplay = energygraph, color = color.blue, label = 'Potential energy')

equilibriumlength = vec(0,0.25,0)

mass = 4500

k = 45000

v = vec(0,0,0)

cart = sphere(pos=vec(0,0.1,0), radius = 0.5, color=color.red)

pivot = vec(0,0,0)

spring = helix(pos = pivot,axis = (cart.pos), radius = 0.5, thickness = 0.1)

t=0

dt=0.0001

while t<15:

rate(25000)

disp = cart.pos-equilibriumlength

a = (-k*disp)/mass

v = v+a*dt

cart.pos = cart.pos+v*dt

pe = 0.5*k*((disp.y)**2)

ke = 0.5*mass*((v.y)**2)

spring.axis = cart.pos-spring.pos

te = pe+ke

positiony.plot(pos=(t,cart.pos.y))

velocityy.plot(pos=(t,v.y))

accelerationy.plot(pos=(t,a.y))

kineticenergy.plot(pos=(t,ke))

potentialenergy.plot(pos = (t,pe))

totalenergy.plot(pos=(t,te))

t = t+dt

He then asked me to add a damping force, which is where I'm currently stuck. Any help would be SERIOUSLY appreciated.

Thanks so much!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!