Bound quantum systems permit particular stationary states rather than every energy a classical particle could have. In code, an energy-level calculation is an eigenvalue problem: turn a Hamiltonian into a matrix, solve for eigenpairs, normalize the returned state vectors, and check the residual before you label a level as physical.
For a one-dimensional stationary problem,
\[\hat H\psi(x)=\left[-\frac{\hbar^2}{2m}\frac{d^2}{dx^2}+V(x)\right]\psi(x)=E\psi(x)\]On an evenly spaced grid with spacing dx, replace the second derivative with a finite difference. That produces a tridiagonal matrix whose diagonal includes the potential and whose neighboring entries represent kinetic coupling. The approximation improves only when the interval, grid, and boundary condition are appropriate for the state being studied.
const norm = Math.sqrt(psi.reduce((sum, value) => sum + value * value * dx, 0));
const normalized = psi.map((value) => value / norm);
const residual = maxAbs(matVec(H, normalized).map((value, i) => value - energy * normalized[i]));
The normalization condition is
\[\int |\psi(x)|^2\,dx=1\]It gives the displayed wavefunction a stable scale and makes |ψ|² interpretable as a probability density after the model's assumptions are stated. A low residual catches a different class of error: the vector may be normalized but still fail to be an eigenvector of the matrix you actually constructed.
For an ideal infinite square well of width L, the analytic levels are
Use that case as a regression fixture before interpreting a custom potential. Refine dx and verify that low-lying numerical energies approach the analytic values. Sorting eigenvalues, fixing an eigenvector sign convention for plots, and reporting the grid make repeated runs comparable.
Prediction: Halving the ideal well width raises every fixed-n energy by a factor of four.
Evaluate the analytic expression for a chosen n at widthL and L/2. Predict the ratio before calculating it, then explain which input in your discretized model needs to change with the physical width.Energy levels are checked eigenpairs, not decorative horizontal lines. Normalize the state, inspect the residual, compare a known potential with an analytic answer, and record the numerical choices that control error.
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Energy Levels, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Atoms and Solids, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Energy Levels as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Compute bound-state eigenpairs with normalization, sorting, and residual checks.