In [32]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit # import the curve fitting function
%matplotlib inline
In [33]:
N_net = np.array([10802,6943,5828,4180,3115,2062,1514,1114,805])
In [34]:
thickness = np.array([0,5.35,10.78,16.23,21.56,26.87,32.07,36.78,41.88])*1e-3
In [35]:
Ln = np.array([np.log(entry) for entry in N_net])
In [36]:
dy = np.array([1/np.sqrt(entry) for entry in N_net])
In [37]:
plt.figure(figsize=(12,6))
plt.scatter(thickness,Ln);
plt.xlabel('Thickness',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
plt.xticks(size = 13);
plt.yticks(size = 13);
In [38]:
def myfun(x,N_o,alpha):
ans = np.log(N_o) - alpha*x # this is y, "the function to be fit"
return ans
In [39]:
p0 = [20000,3/(0.04)]
In [40]:
xlots = np.linspace(0,.05,100) # need lots of data points for smooth curve
yfit = np.zeros((len(N_net),xlots.size))
plsq, pcov = curve_fit(myfun, thickness, Ln, p0,dy) # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
N_o = plsq[0]
eN_o = np.sqrt(pcov[0,0])
alpha = plsq[1]
ealpha = np.sqrt(pcov[1,1])
yfit = myfun(xlots,plsq[0],plsq[1]) # use fit results for a, b, c
print('N_o = %.0f +/- %.0f' % (plsq[0], np.sqrt(pcov[0,0])))
print('alpha = %.0f +/- %.0f' % (plsq[1], np.sqrt(pcov[1,1])))
In [41]:
plt.figure(figsize=(12,6));
plt.xticks(size = 13);
plt.yticks(size = 13);
plt.scatter(thickness,Ln);
plt.xlabel('x (mm)');
plt.ylabel('y (mm)');
plt.plot(xlots,yfit);
plt.legend(['data','Fit'],loc='best');
plt.text(0.03,8.5,'$N_o$ = %.0f +/- %.0f' % (plsq[0], np.sqrt(pcov[0,0])),size=17)
plt.text(0.03,8,'alpha = %.0f +/- %.0f' % (plsq[1], np.sqrt(pcov[1,1])),size=17)
plt.xlabel('Thickness',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
#plt.savefig('Linear')
Out[41]:
In [42]:
#range lambda = 1/alpha
ry = 1/alpha
#uncertainty dlambda = alpha^-2 dalpha
dry = 1/alpha**2 *ealpha
In [43]:
ry*1e2 #This is in cm
Out[43]:
In [44]:
dry*1e2 #cm
Out[44]:
In [45]:
np.log(2)/alpha * 1e2 #cm
Out[45]:
In [46]:
rho = 11.3*1e3 #kg/m^3
In [47]:
mu = alpha/rho
mu
Out[47]:
In [48]:
dmu = ealpha / rho
dmu
Out[48]:
In [66]:
#From chart 0.51
In [49]:
N_net = np.array([8313,7145,5867,4845,4060,3072,2799])
In [50]:
thickness = np.arange(1,8)*12.93*1e-3
In [51]:
Ln = np.array([np.log(entry) for entry in N_net])
In [52]:
dy = np.array([1/np.sqrt(entry) for entry in N_net])
In [53]:
plt.figure(figsize=(12,6))
plt.scatter(thickness,Ln);
plt.xlabel('Thickness',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
plt.xticks(size = 13);
plt.yticks(size = 13);
In [54]:
xlots = np.linspace(0,.1,100) # need lots of data points for smooth curve
yfit = np.zeros((len(N_net),xlots.size))
plsq, pcov = curve_fit(myfun, thickness, Ln, p0,dy) # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
N_o = plsq[0]
eN_o = np.sqrt(pcov[0,0])
alpha = plsq[1]
ealpha = np.sqrt(pcov[1,1])
yfit = myfun(xlots,plsq[0],plsq[1]) # use fit results for a, b, c
print('N_o = %.0f +/- %.0f' % (plsq[0], np.sqrt(pcov[0,0])))
print('alpha = %.0f +/- %.0f' % (plsq[1], np.sqrt(pcov[1,1])))
In [55]:
plt.figure(figsize=(12,6));
plt.xticks(size = 13);
plt.yticks(size = 13);
plt.scatter(thickness,Ln);
plt.xlabel('x (mm)');
plt.ylabel('y (mm)');
plt.plot(xlots,yfit);
plt.legend(['data','Fit'],loc='best');
plt.text(0.01,8.2,'$N_o$ = %.0f +/- %.0f' % (plsq[0], np.sqrt(pcov[0,0])),size=17)
plt.text(0.01,8,'alpha = %.0f +/- %.0f' % (plsq[1], np.sqrt(pcov[1,1])),size=17)
plt.xlabel('Thickness',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
#plt.savefig('Linear')
Out[55]:
In [56]:
#range lambda = 1/alpha
ry = 1/alpha
#uncertainty dlambda = alpha^-2 dalpha
dry = 1/alpha**2 *ealpha
In [57]:
ry*1e2 #This is in cm
Out[57]:
In [58]:
dry*1e2 #cm
Out[58]:
In [59]:
np.log(2)/alpha * 1e2 #cm
Out[59]:
In [60]:
rho = 2.7*1e3 #kg/m^3
In [64]:
mu = alpha/rho
mu*1e1
Out[64]:
In [65]:
dmu = ealpha / rho
dmu*1e1
Out[65]:
In [67]:
#from chart 0.53
In [ ]: