"""Intrinsic carrier density for the ni figure of this page.

    python ni.py     writes ni.dat, read by ni.tex (needs numpy)

n_i = 5.2e15 * T^(3/2) * exp(-Eg / (2kT)) electrons/cm^3, with k = 8.62e-5 eV/K,
Eg = 1.12 eV (Si) and 0.67 eV (Ge), the formula and bandgaps in my notes.
"""
import numpy as np

k = 8.62e-5
T = np.linspace(150, 500, 141)
ni = lambda Eg: 5.2e15 * T**1.5 * np.exp(-Eg / (2 * k * T))
np.savetxt("ni.dat", np.column_stack([T, ni(1.12), ni(0.67)]), fmt="%.5g", header="T si ge", comments="")
print("n_i(Si, 300 K) = %.3g /cm^3" % (5.2e15 * 300**1.5 * np.exp(-1.12 / (2 * k * 300))))
