Suppose we have a measurement of carrier concentration versus temperature. Your job is to estimate the gap of the semiconductor in eV. Your data is given in this file. Your tasks will be:
The correct answer is on this page, but convince yourself of your work before you look at it.
These are examples; they will not work if you copy/paste them!
Import all libraries you’ll need and grab physical constants (Boltzmann constant in eV)
import seaborn as sns
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy
import scipy.constants
k_eV = scipy.constants.k/scipy.constants.e
Rename a column
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df = df.rename(columns={"A": "a", "B": "c"})
a c
0 1 4
1 2 5
2 3 6
Read in data from a URL
df = pd.read_csv("http://courses.engr.illinois.edu/phys460/cooldata.csv")
Do math on columns of data
df['inversex'] = 1.0/df['x']
df['z'] = df['x'] + df['y']
df['logx'] = np.log(df['x'])
Plot the data
plt.scatter('x','y',data=df, label='data')
plt.legend()
plt.xlabel("x (units)")
plt.ylabel("y (units)")
Fit a function and provide a report on the fit. This will perform linear regression and print out the coefficients and their error bars, listed under ‘std err’
fit = sm.ols("y ~ x", data = df).fit()
fit.summary()
Plot the fit versus the data, and save to a PDF.
plt.scatter('x','y',data=df, label='Data')
plt.plot(df['x'], fit.predict(df), label='Fit')
plt.legend()
plt.xlabel("x (units)")
plt.ylabel("y (units)")
plt.savefig("fit_plot.pdf", bbox_inches='tight')
1.2 eV
We know that for insulators, the heat capacity is proportional to T3 at low temperature. But how do we know what low temperature is? For this case, I’ve made up a silly function that you will play with. You’ll also use some of the tools from above. The data is in this file.
What you should do:
Try to fit to a T3 with different cutoffs.
for cutoff in [100, 50, 30, 20, 10, 5]:
fit = sm.ols('C ~ np.power(T,3)', data=df[df['T']<cutoff]).fit()
print(cutoff, fit.params['np.power(T, 3)'])
0.2 T3 + 0.00000001T5 + 0.000000001T9