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

Lead

1


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);


2


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])))


N_o = 10584 +/- 326
alpha = 60 +/- 2

3


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]:
<matplotlib.text.Text at 0x1f4c985ac88>

4


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]:
1.6694328164558021

In [44]:
dry*1e2 #cm


Out[44]:
0.053400174792917345

5


In [45]:
np.log(2)/alpha * 1e2 #cm


Out[45]:
1.1571626498605878

6


In [46]:
rho = 11.3*1e3 #kg/m^3

In [47]:
mu = alpha/rho
mu


Out[47]:
0.0053009366024752416

In [48]:
dmu = ealpha / rho
dmu


Out[48]:
0.00016956114576644637

In [66]:
#From chart 0.51

Aluminum


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])))


N_o = 10231 +/- 238
alpha = 15 +/- 0

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]:
<matplotlib.text.Text at 0x1f4c9d2e668>

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]:
6.8518298052926623

In [58]:
dry*1e2 #cm


Out[58]:
0.22353858326810663

In [59]:
np.log(2)/alpha * 1e2 #cm


Out[59]:
4.7493265112152088

In [60]:
rho = 2.7*1e3 #kg/m^3

In [64]:
mu = alpha/rho
mu*1e1


Out[64]:
0.054054227979258851

In [65]:
dmu = ealpha / rho
dmu*1e1


Out[65]:
0.001763500537155952

In [67]:
#from chart 0.53

In [ ]: