A semiconductor has a filled valence band and empty conduction band at zero temperature in the ideal pure crystal, separated by a modest band gap. Thermal energy, light, and deliberately introduced dopants can create mobile electrons and holes. This controllable carrier population makes diodes, transistors, light-emitting diodes, detectors, and solar cells possible.
A band gap alone does not determine device current. Temperature, carrier density, mobility, recombination, electrostatic potential, geometry, contacts, and applied bias all matter.
An electron promoted into the conduction band leaves an unoccupied state in the valence band. That missing occupation behaves usefully as a positively charged carrier called a hole. Let \(n\) be conduction-electron number density and \(p\) be hole number density.
In an intrinsic semiconductor at thermal equilibrium,
\[n=p=n_i\]where \(n_i\) is the intrinsic carrier density. In a nondegenerate approximation,
\[n_i=\sqrt{N_CN_V}\exp\left(-\frac{E_g}{2k_{\mathrm B}T}\right)\]Here \(N_C\) and \(N_V\) are effective densities of states, and \(E_g\) is band-gap energy. The exponential explains strong temperature sensitivity, but the material parameters also vary with temperature.
At equilibrium, occupation follows the Fermi–Dirac function
\[f(E)=\frac{1}{e^{(E-E_F)/(k_{\mathrm B}T)}+1}\]where \(E_F\) is the chemical potential at that temperature. In a nondegenerate semiconductor,
\[n\approx N_Ce^{-(E_C-E_F)/(k_{\mathrm B}T)},\qquad p\approx N_Ve^{-(E_F-E_V)/(k_{\mathrm B}T)}\]Multiplication gives the equilibrium mass-action law
\[np=n_i^2\]This relation applies at thermal equilibrium under the nondegenerate model. A strongly illuminated or biased device can have separate electron and hole quasi-Fermi levels, and \(np\) need not equal its equilibrium value locally.
Donor impurities can supply electrons, making electrons the majority carriers in n-type material. Acceptor impurities create holes, making holes the majority carriers in p-type material. Doping changes carrier occupation and Fermi level; it does not simply create a permanently charged bulk.
Charge neutrality in a uniform region is
\[p+N_D^+=n+N_A^-\]where \(N_D^+\) and \(N_A^-\) are ionized dopant densities. If donors are fully ionized, dominate acceptors, and greatly exceed intrinsic density, then approximately
\[n\approx N_D-N_A,\qquad p\approx\frac{n_i^2}{n}\]Swap electrons and holes for strongly p-type material. These approximations fail during dopant freeze-out, at very high degenerate doping, or under strong nonequilibrium injection.
import numpy as np
intrinsic, donors, acceptors = 1e16, 1e21, 0.0
net_donors = donors - acceptors
# Fully ionised, nondegenerate equilibrium; solve n-p=ND-NA and np=ni^2.
root = np.hypot(net_donors, 2 * intrinsic)
if net_donors >= 0:
electrons = (net_donors + root) / 2
holes = intrinsic**2 / electrons
else:
holes = (-net_donors + root) / 2
electrons = intrinsic**2 / holes
print("Electron and hole densities (1/m^3):", electrons, holes)
assert np.isclose(electrons * holes, intrinsic**2)
The full calculation should solve neutrality and occupation statistics rather than switch formulas at one arbitrary threshold.
Using \(e>0\), the conventional current densities are
\[\mathbf J_n=en\mu_n\mathbf E+eD_n\nabla n\] \[\mathbf J_p=ep\mu_p\mathbf E-eD_p\nabla p\]The total current is \(\mathbf J=\mathbf J_n+\mathbf J_p\). For uniform densities, conductivity is
\[\sigma=e(n\mu_n+p\mu_p)\]Zero electric field does not guarantee zero local current if a carrier gradient exists. At equilibrium in a junction, drift and diffusion contributions can be individually nonzero while their sums give zero terminal current.
When p-type and n-type regions are joined, electrons initially diffuse from the n side and holes from the p side. They recombine near the interface, leaving behind fixed ionized dopants. This depletion region contains little mobile charge but a nonzero space charge that creates an electric field opposing further majority-carrier diffusion.
At equilibrium, one Fermi level is constant across the device. In an abrupt, nondegenerate junction with fully ionized dopants, the built-in potential is
\[V_{\mathrm{bi}}=\frac{k_{\mathrm B}T}{e}\ln\left(\frac{N_AN_D}{n_i^2}\right)\]This is an internal electrostatic potential difference, not a terminal battery voltage available from an unbiased device. Contact potential changes elsewhere in a measurement loop prevent extracting continuous work from equilibrium.
Under the depletion approximation, total uncovered charge balances:
\[N_Ax_p=N_Dx_n\]where \(x_p\) and \(x_n\) are depletion widths on the p and n sides. The more lightly doped side therefore occupies more of the depletion width.
Forward bias lowers the junction barrier and narrows the depletion region, allowing substantially more carrier injection. Reverse bias raises the barrier and widens the region; a small minority-carrier current flows before breakdown.
An idealized diode equation is
\[I=I_S\left[\exp\left(\frac{eV}{n_{\mathrm{id}}k_{\mathrm B}T}\right)-1\right]\]Here \(I_S\) is strongly temperature- and device-dependent, and
\(n_{\mathrm{id}}\)summarizes the dominant idealized transport mechanism. The voltage sign must be defined so positive \(V\) is forward bias.
def ideal_diode_current(voltage, temperature=300, saturation=1e-12, ideality=1.0):
q, k_b = 1.602176634e-19, 1.380649e-23
if temperature <= 0 or saturation < 0 or ideality <= 0:
raise ValueError("Invalid diode model parameters.")
return saturation * np.expm1(q * voltage / (ideality * k_b * temperature))
print("Ideal diode current at 0.5 V (A):", ideal_diode_current(0.5))
At \(V=0\), the formula returns zero net current. At sufficiently large forward voltage, series resistance, high-level injection, and heating invalidate the simple exponential. In reverse bias, generation current and eventual Zener or avalanche breakdown require additional models.
Electron and hole populations evolve through transport, optical or thermal generation, and recombination:
\[\frac{\partial n}{\partial t}=\frac{1}{e}\nabla\cdot\mathbf J_n+G_n-R_n\] \[\frac{\partial p}{\partial t}=-\frac{1}{e}\nabla\cdot\mathbf J_p+G_p-R_p\]Recombination can be radiative, defect-assisted, or Auger-like. A single lifetime approximation may be useful near equilibrium but is not universal. Integrating both equations over the device provides a carrier-balance check against boundary currents and generation.
Poisson's equation closes the electrostatic part:
\[\nabla\cdot(\epsilon\nabla\varphi)=-e\left(p-n+N_D^+-N_A^-\right)\]with \(\mathbf E=-\nabla\varphi\). Potential, carrier densities, and current must usually be solved self-consistently.
Absorbing a photon with energy at least the relevant gap can create an electron–hole pair, subject to momentum and selection rules. Recombination can emit light. Direct-gap semiconductors allow efficient radiative transitions without a phonon; indirect-gap materials often require phonon participation.
An LED converts injected carrier recombination into photons. A solar cell uses absorption and a junction field to separate photogenerated carriers and deliver electrical power. Neither device is described by the dark ideal-diode equation alone; optical generation, recombination, contacts, and series losses matter.
A semiconductor calculation should verify:
Measured material parameters depend on crystal quality, temperature, strain, orientation, and fabrication. The formulas here omit quantum confinement, tunneling, high-field velocity saturation, contact resistance, interface traps, self-heating, and many-body corrections unless stated. They explain the core physics but are not a substitute for a calibrated device model.
Evaluate an illustrative ideal diode at room-temperature thermal voltage 0.02585 volts. The question for this calculation is precise: how does ideal diode current change when we change junction voltage, while keeping the other choices fixed? The earlier sections explain the physical relationship. Here we turn one part of that relationship into a calculation that you can run, inspect, and change in Google Colab.
Reverse breakdown, series resistance, and high-injection effects are omitted. Keep that sentence beside the results. A formula can return a number outside its useful range, and a plotting library will usually draw that number without asking whether the physical assumptions still hold. The selected interval is from -0.1 to 0.5 V. It gives us a specific domain to discuss instead of leaving the graph's range to a software default.
Use the notebook link above the lesson, run the setup cell, and then run the cells in order. The code below is also included there. NumPy handles the arrays of numerical values, SymPy keeps the equation symbolic, and Matplotlib draws the results. If these libraries or notebook cells are unfamiliar, start with Your first physics notebook.
In this small example, q stands for junction voltage, expressed in V. The output is
ideal diode current, expressed in A. The equation below uses the numerical values in those
units. Any fixed coefficients therefore carry the units needed to make the relation
consistent. A value supplied in another unit must be converted before it enters this
expression.
This is a function of one changing input. It is not a statement that the physical system has only one variable. We deliberately hold the other inputs fixed so that one cause of variation is visible. Changing several inputs at once would make it harder to tell which change produced the output difference. Write down the held-fixed choices before trying a different experiment.
At 0.3 V, the expression gives 1.09689e-07 A. This is our reference calculation. It is a prediction of the stated example, not a new measurement. Its displayed digits help us compare implementations. They should not be read as a claim that physical inputs are known to six significant figures.
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
q = sp.Symbol("q", real=True)
expression = sp.sympify("1e-12*(exp(q/0.02585)-1)", locals={"q": q})
reference_input = 0.3
reference_output = float(expression.subs(q, reference_input))
print("Input:", reference_input, "V")
print("Predicted ideal diode current:", reference_output, "A")
sp.Symbol declares a mathematical symbol. It does not assign a numerical measurement
to that symbol. subs then replaces the symbol with our chosen input, and float
converts the resulting symbolic number into a standard Python numerical value.
Keeping these steps separate lets us inspect the equation before numerical substitution.
It also prevents a later plot from becoming the only surviving record of the model.
Before drawing hundreds of points, calculate three. The lower endpoint gives -9.7911e-13 A. The midpoint, at 0.2 V, gives 2.29046e-09 A. The upper endpoint gives 0.000251351 A. Read these together with the assumptions: they describe different choices of junction voltage within the same example, with the other inputs held fixed.
These three values are a useful first check, but they do not establish the shape between them. Two endpoints can be equal even when the curve bends or oscillates in between. Likewise, a large change between endpoints does not tell us whether the relationship is linear. We need the equation and intermediate samples to answer those questions.
evaluate = sp.lambdify(q, expression, modules="numpy")
inputs = np.array([-0.1, 0.2, 0.5])
outputs = np.asarray(evaluate(inputs), dtype=float)
outputs = np.broadcast_to(outputs, inputs.shape)
for input_value, output_value in zip(inputs, outputs):
print(f"{input_value:.6g} V -> {output_value:.6g} A")
assert np.all(np.isfinite(outputs))
lambdify turns the symbolic expression into a numerical function. We explicitly select
NumPy as its numerical backend so it can accept an array. The same expression now has
two useful forms: one for algebra and one for calculating many cases. The assertion
checks that the chosen inputs produce finite outputs. It would catch an infinity or an
undefined numerical result, but a finite value can still be physically inappropriate.
The horizontal axis shows junction voltage; the vertical axis shows ideal diode current. Every plotted point is a prediction of the same expression. We mark the reference case separately so that a reader can connect the earlier printed value to its place on the curve. The axis labels include units because a shape without a scale cannot tell us the size of a physical effect.
input_grid = np.linspace(-0.1, 0.5, 301)
output_grid = np.asarray(evaluate(input_grid), dtype=float)
output_grid = np.broadcast_to(output_grid, input_grid.shape)
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(input_grid, output_grid, label="Stated model")
ax.scatter([reference_input], [reference_output], label="Reference case", zorder=3)
ax.set_xlabel("Junction voltage (V)")
ax.set_ylabel("Ideal diode current (A)")
ax.legend()
ax.grid(alpha=0.25)
fig.tight_layout()
plt.show()
Look for a sign change, a turning point, or a region where the curve becomes steep. Connect each feature to the expression rather than to the colour of the line. If the curve has a minimum or maximum, changing the input in opposite directions may have similar effects on the output near that point. If it is nearly straight over a short interval, a local linear approximation may be useful even when the complete expression is nonlinear.
Increasing the number of samples makes the line smoother and may reveal features that a coarse grid missed. It does not improve the physical inputs or enlarge the model's validity range. For quantities that can take only discrete values, use the line as a guide to the relationship and interpret only the allowed input values. A plotting function does not enforce such restrictions for you.
A derivative asks a more specific question than the whole graph: how quickly does ideal diode current change near the reference input? Its units are the output unit divided by the input unit. For this calculation, the derivative at 0.3 V is 4.24334e-06 in those ratio units. Locally, the output increases as the input increases. This statement is local; the sign or size of the slope can be different elsewhere on the curve.
\[f'(q) = 3.86847195357834 \cdot 10^{-11} e^{38.6847195357834 q}\]For a small input change, multiply the derivative by that change to estimate the output change. Then compare that estimate with a fresh evaluation of the full expression. The distinction between these two calculations matters: the derivative gives a tangent approximation, while substitution evaluates the chosen expression at the new point.
slope_expression = sp.diff(expression, q)
slope_at_reference = float(slope_expression.subs(q, reference_input))
changed_input = 0.303
linear_prediction = reference_output + slope_at_reference * (
changed_input - reference_input
)
full_prediction = float(evaluate(changed_input))
print("Symbolic derivative:", slope_expression)
print("Tangent prediction:", linear_prediction, "A")
print("Full expression:", full_prediction, "A")
print("Approximation difference:", full_prediction - linear_prediction, "A")
Here the changed input is 0.303 V. The tangent estimate is 1.22419e-07 A, while the full expression gives 1.23187e-07 A. If the two values are close, it means the chosen input change is small enough for this local approximation at this point. It does not mean the entire model is linear. If the slope is zero, a quadratic or higher-order term may supply the leading change instead.
This is also the beginning of uncertainty propagation. If the input has a small stated standard uncertainty, the magnitude of the slope times that uncertainty estimates one contribution to output uncertainty. Do not automatically use the same rule for a wide interval, a discontinuity, a turning point with zero first derivative, or several correlated uncertain inputs. Those situations need more of the model than one slope.
We can estimate the same slope from values on either side of the reference point. Subtract the lower output from the upper output and divide by twice the input step. Parentheses are essential: the entire output difference must be divided by the entire input interval. Without them, Python can execute a different mathematical expression while still producing a plausible number.
The calculation below uses three decreasing step sizes. Each estimate is compared with the symbolic derivative, so the reference is independent of the numerical difference formula. Near an endpoint, it is acceptable here to evaluate a small extension only because the displayed mathematical expression is smooth there; such a check does not assert that extrapolated values describe additional physical cases.
input_span = 0.6
for fraction in [1e-2, 1e-3, 1e-4]:
step = input_span * fraction
upper = float(evaluate(reference_input + step))
lower = float(evaluate(reference_input - step))
numerical_slope = (upper - lower) / (2 * step)
difference = numerical_slope - slope_at_reference
print(f"step={step:.6g}: slope={numerical_slope:.6g}, difference={difference:.6g}")
For a smooth function, reducing the step often reduces the approximation error at first. Very small steps can eventually make subtraction of nearly equal floating-point values less reliable. Therefore “smaller” is not an unlimited guarantee of “better.” Compare the observed behaviour over a useful range of steps instead of choosing the smallest number the computer can represent.
An absolute slope difference is useful when the expected slope is near zero. A relative difference would divide by a very small reference and could look enormous even when the absolute discrepancy is tiny. Away from zero, a relative difference can help compare quantities with very different scales. The tolerance should reflect the question and the numerical method, rather than a universal decimal threshold copied into every test.
Make one copy of the reference calculation before editing it. Choose a second value of junction voltage inside the stated interval, predict whether ideal diode current will rise or fall, and then evaluate the expression. Place the prediction and the result in a text cell. If they disagree, identify whether the mistake was in the sign, the unit conversion, the algebra, or the assumption about how the curve behaves.
Next choose a shorter plotting interval around the reference point. Compare the local curve with its tangent approximation. Then widen the interval again. The difference shows why a useful local estimate need not describe the whole range. Keep the axis labels and numerical scale visible when comparing the plots; automatic axis limits can make two different effects appear equally large.
Finally, return to the physical limit stated at the start: Reverse breakdown, series resistance, and high-injection effects are omitted. Describe one change to the setup that would violate that limit. State what new input, equation, or observation would be needed before trusting an answer in the changed situation. This last step connects the Python experiment to the physics instead of treating successful execution as the only criterion for a useful result.
Before saving, restart the runtime and run all cells in order. A result that depends on an earlier, now-deleted input cell is not reproducible from the saved notebook. Keep unrounded values for later calculations, round only the reported output, and label any new data as measured, assumed, or generated. The graph and printed values should remain traceable to the same expression and the same choices of inputs.
There is another way to check that the expression and its derivative describe the same relationship. Add up the small output changes predicted by the slope across the chosen input interval. In the continuous limit, this integral equals the output at the upper endpoint minus the output at the lower endpoint. The result has units of A: the input unit in the integration cancels the input unit in the denominator of the slope.
This statement is about the mathematics of this particular relationship. It does not assign a new physical meaning to an arbitrary area under a graph. For example, an area under force versus distance represents work, while an area under a different pair of quantities may represent something else or have no standard name. Always carry the axis units through the calculation before naming an integral.
slope_function = sp.lambdify(q, slope_expression, modules="numpy")
endpoint_change = float(evaluate(0.5) - evaluate(-0.1))
for points in [101, 201, 401]:
grid = np.linspace(-0.1, 0.5, points)
slopes = np.asarray(slope_function(grid), dtype=float)
slopes = np.broadcast_to(slopes, grid.shape)
integrated_change = np.trapezoid(slopes, grid)
print(
points,
"integrated change:",
integrated_change,
"endpoint change:",
endpoint_change,
)
The trapezoidal rule joins neighbouring slope samples with straight segments and adds their signed areas. A negative contribution remains negative; replacing every slope by its magnitude would calculate a different quantity. Increasing the sample count provides a practical refinement check. If the values do not settle toward the endpoint difference, first inspect the interval, singularities, and array ordering.
Do not conclude that two agreeing calculations prove the model is physically complete. Both use the same selected relationship, so an omitted effect would be omitted from both. Their agreement is evidence that the numerical tools implement that relationship consistently. Comparing with an independent experiment or a more appropriate physical model is a separate test.
Keep this comparison in the notebook when you change the expression. It is particularly useful after adding a coefficient, changing a sign convention, or converting an input unit. A code cell that produces a smooth graph can conceal these mistakes; a second calculation of the same output change gives you another place to notice them.