Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! My professor asked me to create a simulation (for physics) of a spring in vP

ID: 3917509 • Letter: H

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

Explanation / Answer

Damping force is responsible for the attenuation or reduction of the amplitude of oscillation.

It is considered to be proportional to the velocity of the oscillating body or object.

There is a requirement of a damping coefficient or damping factor for calculating the damping force.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote