anharmonic_spring_mwp

anharmonic_spring_mwp - L_vector = ball.pos s =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
from __future__ import division ## treat integers as real numbers in division from visual import * scene.width=600 scene.height = 760 s ## constants and data g = 9.8 mball = .1771 L0 = 0.3 ks = 12 epsilon = 0.5233 e ## objects ceiling = box(pos=(0,0,0), size = (0.2, 0.01, 0.2)) ball = sphere(pos=(.2727,-.0615,0), radius=0.025, color=color.orange) spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015) spring.axis = ball.pos - ceiling.pos trail = curve(color=ball.color) t ## initial values ball.p = mball*vector(0.362, 0.107, 0) b #time t = 0 deltat = 5e-5 d ## improve the display scene.autoscale = 0 ## don't let camera zoom in and out as ball moves scene.center = vector(0,-L0,0) ## move camera down to improve display visibility s ## calculation loop # while t < 4.83: w ## calculate force on ball by spring (note: requires calculation of L_vector)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: L_vector = ball.pos s = vector(0,L0,0)-L_vector smag = mag(s) Fs = (ks*smag + epsilon*(smag**3))*-(s/smag) ## calculate net force on ball (note: has two contributions) # Fgrav=mball*g*vector(0,-1,0) Fnet=Fgrav + Fs ## apply momentum principle (compute the magnitude of the components of the net force) pi = ball.p p_init = mag(ball.p) ball.p=ball.p+Fnet*deltat p_final = mag(ball.p) ftan = ((p_final - p_init)/deltat)*(ball.p/mag(ball.p)) fperp= Fnet - ftan ## update position # ball.pos=ball.pos + (ball.p/mball) * deltat ## update axis of spring # spring.axis=ball.pos-ceiling.pos trail.append(pos=ball.pos) ## update time t = t + deltat print 'position = ', ball.pos print 'velocity = ', ball.p/mball print 'parallel = ', ftan print 'perp = ', fperp...
View Full Document

Page1 / 2

anharmonic_spring_mwp - L_vector = ball.pos s =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online