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

PYTHON (2.7) PROGRAM - SHOW CODE FOR FULL POINTS, WILL RATE A particle moves alo

ID: 657865 • Letter: P

Question

PYTHON (2.7) PROGRAM - SHOW CODE FOR FULL POINTS, WILL RATE

A particle moves along a trajectory in the xy plane such that at time t the object has position (x(t), y(t)). The velocity vector of the particle can be approximated by and its acceleration Write a function kinematics(x,y,t,dt = 1.0e-6) that approximates the velocity and acceleration of a particle with position vector (cos2pit, sin 2pit) for t = 0, 1/4, ½, ¾, and dt = 0.1,0.05, 0.01. Calculate the error in the approximations. Display your results in a table.

Explanation / Answer


from numpy import *

def a(r,t,dt=1E-5):
return (r(t+dt)-2*r(t)+r(t-dt))/(dt**2)

def v(r,t,dt=1E-5):
return (r(t+dt)-r(t-dt))/(2*dt)


def r(t,R=1,w=2*pi):
return array([R*cos(w*t),R*sin(w*t)])


def kinematics2(r,t,dt=1E-4):
print "Ort: <%g,%g>"
   %(r(t)[0],r(t)[1])
print "G: <%g,%g>"
   %(v(paramtr)[0],v(paramtr)[1])
print "B: <%g,%g>"
   %(a(paramtr)[0],a(paramtr)[1])


kinematics2(r,1,1E-5)