In [263]:
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 [264]:
N_net = np.array([10802,6943,5828,4180,3115,2062,1514,1114,805])
In [265]:
thickness = np.array([0,5.35,10.78,16.23,21.56,26.87,32.07,36.78,41.88])*1e-3
In [266]:
Ln = np.array([np.log(entry) for entry in N_net])
In [267]:
dy = np.array([1/np.sqrt(entry) for entry in N_net])
In [268]:
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 [269]:
def myfun(x,N_o,alpha):
ans = np.log(N_o) - alpha*x # this is y, "the function to be fit"
return ans
In [270]:
p0 = [20000,3/(0.04)]
In [271]:
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 [272]:
plt.figure(figsize=(12,6));
plt.xticks(size = 13);
plt.yticks(size = 13);
plt.scatter(thickness*1e2,Ln);
plt.xlabel('x (mm)');
plt.ylabel('y (mm)');
plt.plot(xlots*1e2,yfit);
plt.xlim(0,.05*1e2)
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('Plate Thickness (cm)',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
plt.savefig('Lead')
In [273]:
#range lambda = 1/alpha
ry = 1/alpha
#uncertainty dlambda = alpha^-2 dalpha
dry = 1/alpha**2 *ealpha
In [274]:
ry*1e2 #This is in cm
Out[274]:
In [275]:
dry*1e2 #cm
Out[275]:
In [276]:
np.log(2)/alpha * 1e2 #cm
Out[276]:
In [277]:
dry*1e2*np.log(2) #cm
Out[277]:
In [278]:
rho = 11.3*1e3 #kg/m^3
In [279]:
mu = alpha/rho
mu
Out[279]:
In [280]:
dmu = ealpha / rho
dmu
Out[280]:
In [281]:
#From chart 0.51
In [282]:
N_net = np.array([8313,7145,5867,4845,4060,3072,2799])
In [283]:
thickness = np.arange(1,8)*12.93*1e-3
In [284]:
Ln = np.array([np.log(entry) for entry in N_net])
In [285]:
dy = np.array([1/np.sqrt(entry) for entry in N_net])
In [286]:
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 [287]:
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 [288]:
plt.figure(figsize=(12,6));
plt.xticks(size = 15);
plt.yticks(size = 15);
plt.scatter(thickness*1e2,Ln);
plt.plot(xlots*1e2,yfit);
plt.xlim(0,.1*1e2)
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 = %.1f +/- %.1f' % (plsq[1], np.sqrt(pcov[1,1])),size=17)
plt.xlabel('Plate Thickness (cm)',size=20);
plt.ylabel('Ln($N_{net}$)',size=20);
plt.savefig('Aluminum')
In [289]:
#range lambda = 1/alpha
ry = 1/alpha
#uncertainty dlambda = alpha^-2 dalpha
dry = 1/alpha**2 *ealpha
In [290]:
ry*1e2 #This is in cm
Out[290]:
In [291]:
dry*1e2 #cm
Out[291]:
In [292]:
np.log(2)/alpha * 1e2 #cm
Out[292]:
In [293]:
dry*1e2*np.log(2) #cm
Out[293]:
In [294]:
rho = 2.7*1e3 #kg/m^3
In [295]:
mu = alpha/rho
mu*1e1
Out[295]:
In [296]:
dmu = ealpha / rho
dmu*1e1
Out[296]:
In [297]:
#from chart 0.53
In [ ]: