Errata

Chapter 03: Units and Measurements

p. 36 ... a car driving 2.0km in ... \( \rightarrow \) 2.0m

Chapter 04: Motion in one dimension

import numpy as np
import matplotlib.pyplot as plt

t,y = np.loadtxt('tennis002.d',usecols=[0,1],unpack=True);

plt.plot(t,y)
plt.xlabel('t [s]')
plt.ylabel('y [m]')

n = len(y)
dt = t[1] - t[0]
v = np.zeros(n-1,float)
for i in range(n-1):
   v[i] = (y[i+1] - y[i])/dt

a = np.zeros(n-1,float)
for i in range(1,n-1):
   a[i] = (v[i] - v[i-1])/dt

plt.subplot(3,1,1)
plt.plot(t,y)
plt.ylabel('y [m]')
plt.subplot(3,1,2)
plt.plot(t[0:n-1],v)
plt.ylabel('v [m/s]')
plt.subplot(3,1,3)
plt.plot(t[1:n-1],a[1:n-1])
plt.xlabel('t [s]')
plt.ylabel('a [m/s^2]')

imax = np.max(np.where(t<=0.5))
plt.plot(t[1:imax],a[1:imax])
plt.xlabel('t [s]')
plt.ylabel('a [m/s^2]')

g = 9.8 # m/s^2
y0 = 1.6 # m
vt = -g*t
yt = y0 - 0.5*g*t**2
plt.subplot(2,1,1)
plt.plot(t[0:imax],y[0:imax],'-r')
plt.plot(t[0:imax],yt[0:imax],'--b')
plt.xlabel('t [s]')
plt.ylabel('y [m]')
plt.subplot(2,1,2)
plt.plot(t[0:imax],v[0:imax],'-r')
plt.plot(t[0:imax],vt[0:imax],'--b')
plt.xlabel('t [s]')
plt.ylabel('v [m/s]')

import numpy as np
import matplotlib.pyplot as plt
t,a = np.loadtxt('therocket.d',usecols=[0,1],unpack=True)
dt = t[1] - t[0]
n = len(t)
x = np.zeros(n,float)
v = np.zeros(n,float)
x[0] = 0.0 # Initial value
v[0] = 0.0 # Initial value
for i in range(1,n):
  v[i] = v[i-1] + a[i-1]*dt
  x[i] = x[i-1] + v[i-1]*dt
plt.subplot(3,1,1)
plt.plot(t,x)
plt.xlabel('t [s]'); plt.ylabel('x [m]')
plt.subplot(3,1,2)
plt.plot(t,v)
plt.xlabel('t [s]'); plt.ylabel('v [m/s]')
plt.subplot(3,1,3)
plt.plot(t,a)
plt.xlabel('t [s]'); plt.ylabel('a [m/s^2]')

import numpy as np
import matplotlib.pyplot as plt
D = 0.0245 # m^-1
g = 9.8    # m/s^2
y0 = 2.0
v0 = 0.0
time = 0.5
dt = 0.00001
# Variables
n = int(np.ceil(time/dt))
y = np.zeros(n,float)
v = np.zeros(n,float)
a = np.zeros(n,float)
t = np.zeros(n,float)
# Initialize
y[0] = y0
v[0] = v0
# Integration loop
for i in range(n-1):
    a[i] = -g -D*v[i]*abs(v[i])
    v[i+1] = v[i] + a[i]*dt
    y[i+1] = y[i] + v[i+1]*dt
    t[i+1] = t[i] + dt
# Plot results
plt.subplot(3,1,1)
plt.plot(t,y)
plt.xlabel('t [s]'); plt.ylabel('y [m]')
plt.subplot(3,1,2)
plt.plot(t,v)
plt.xlabel('t [s]'); plt.ylabel('v [m/s]')
plt.subplot(3,1,3)
plt.plot(t[0:n-2],a[0:n-2])
plt.xlabel('t [s]'); plt.ylabel('a [m/s^2]')

Chapter 05: Forces in one dimension

Chapter 06: Motion in Two and Three Dimensions

Chapter 07: Forces in Two and Three Dimensions

Chapter 09: Forces and Constrained Motion

#start1
import numpy as np
import matplotlib.pyplot as plt
# Initialize
m = 2e-12 # kg
A = 1e-5  # m
k = 10.0  # N/m
N = 1e-4  # N
T = 0.01  # s
omega = 2*np.pi/T
time = 2*T
dt = time/100000
n = int(np.round(time/dt))
mud = 0.2
mus = 0.4
# Variables
t = np.zeros(n,float)
x = np.zeros(n,float)
v = np.zeros(n,float)
f = np.zeros(n,float)
# Initial conditions
x[0] = 0.0
v[0] = 0.0
for i in range(n-1):
    x0 = A*np.sin(omega*t[i])
    FD = -k*(x[i]-x0)
    if v[i]==0.0: # Static friction
        f[i] = -FD
        if abs(f[i])>mus*N: # Slips
            f[i] = -np.sign(FD)*mud*N
    else:          # Dynamic friction
        f[i] = -np.sign(v[i])*mud*N
    Fnet = FD + f[i]
    a = Fnet/m
    v[i+1] = v[i] + a*dt
    if (v[i]!=0.0) and (np.sign(v[i+1])!=np.sign(v[i])):
        v[i+1] = 0.0 # The block has stopped
    x[i+1] = x[i] + v[i+1]*dt
    t[i+1] = t[i] + dt
#end1
plt.subplot(2,1,1)
plt.plot(t,f,'-k')
plt.ylabel('f')
plt.xlabel('t')
plt.subplot(2,1,2)
x0 = A*np.sin(omega*t)
plt.plot(t,x,'-k',t,x0,'k:')
plt.ylabel('x')
plt.xlabel('t')

Chapter 10: Work

Chapter 11: Energy

Chapter 12: Momentum, Impulse and Collisions

Chapter 13: Multiparticle Systems

Chapter 15: Rotation of Rigid Bodies

Chapter 16: Dynamics of Rigid Bodies

Appendix B: Solutions