import numpy as np
from scipy import integrate
import matplotlib as mpl # As of July 2017 Bucknell computers use v. 2.x
import matplotlib.pyplot as plt
mpl.style.use('classic')
plt.rc('figure', figsize = (6, 4.5)) # Reduces overall size of figures
plt.rc('axes', labelsize=16, titlesize=14)
plt.rc('figure', autolayout = True)
%matplotlib notebook
def yLin(t):
tau = m/bA
return -(vtA*t - vtA*tau*(1 - np.exp(-t/tau))) + y0
def vLin(t):
tau = m/bA
return vtA*(1 - np.exp(-t/tau))
def yQuad(t):
return -vtB**2*np.log(np.cosh(g*t/vtB))/g + y0
def vQuad(t):
return vtB*np.tanh(g*t/vtB)
data = np.loadtxt('sim.dat')
t, y = data.T
m = 0.0038
bA = 0.0175
bB = 0.01287
y0 = 1.153
vy0 = 0
g = 9.81
vtA = vt = m*g/bA
vtB = np.sqrt(m*g/bB)
print(vtA, vtB)
plt.figure()
plt.scatter(t,y)
t2 = np.linspace(0,0.6,601)
plt.plot(t, yLin(t))
plt.grid()
plt.xlabel('$t$')
plt.ylabel('$y$')
plt.title('linear drag; $B_A = %s$'%bA)
plt.ylim(0,1.2);
plt.figure()
plt.scatter(t, y - yLin(t))
t2 = np.linspace(0,0.6,601)
plt.grid()
plt.title('residuals with linear drag; $B_A = %s$'%bA);
#plt.ylim(0,1.2)
sum_sq = np.sum((y-yLin(t))**2)
print('sqrt of sum of squared deviations = ', np.sqrt(sum_sq))
plt.figure()
plt.scatter(t,y)
t2 = np.linspace(0,0.6,601)
plt.plot(t, yQuad(t))
plt.grid()
plt.xlabel('$t$')
plt.ylabel('$y$')
plt.title('quadratic drag; $B_B = %s$'%bB)
plt.ylim(0,1.2);
plt.figure()
plt.scatter(t, y - yQuad(t))
t2 = np.linspace(0,0.6,601)
plt.grid()
#plt.ylim(0,1.2)
plt.title('residuals with quadratic drag; $B_B = %s$'%bB);
sum_sq = np.sum((y-yQuad(t))**2)
print('square root of sum of squared deviations = ', np.sqrt(sum_sq))
y
np.roll(y,-1)
deltaY = y - np.roll(y,-1)
t
np.roll(t,-1)
deltaT = np.roll(t,-1) - t
v = deltaY[:len(deltaY)-1]/deltaT[:len(deltaY)-1]
plt.figure()
plt.scatter(t[:len(v)]+0.033/2,-v)
t2 = np.linspace(0,0.6,601)
plt.plot(t, -vLin(t))
plt.grid()
plt.xlabel('$t$')
plt.ylabel('$v$')
plt.title('linear drag; $B_A = %s$'%bA);
#plt.ylim(0,1.2)
plt.figure()
plt.xlabel('$t$')
plt.ylabel('$v$')
plt.title('quadratic drag; $B_B = %s$'%bB);
plt.scatter(t[:len(v)]+0.033/2,-v)
t2 = np.linspace(0,0.6,601)
plt.plot(t, -vQuad(t))
plt.grid()
#plt.ylim(0,1.2)