"""Carrier densities of n-type Si versus temperature, for the quiz figure of this page.

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

N_D = 1e15 cm^-3 (all donors ionized): n ~ N_D and p = n_i^2 / N_D, with
n_i = 5.2e15 * T^(3/2) * exp(-Eg / (2kT)), Eg = 1.12 eV, k = 8.62e-5 eV/K.
"""
import numpy as np

ND, k, Eg = 1e15, 8.62e-5, 1.12
T = np.linspace(250, 450, 81)
ni = 5.2e15 * T**1.5 * np.exp(-Eg / (2 * k * T))
p = ni**2 / ND
n = ND / 2 + np.sqrt((ND / 2)**2 + ni**2)   # exact for full ionization; ~N_D here
np.savetxt("np.dat", np.column_stack([T, n, p]), fmt="%.5g", header="T n p", comments="")
