
Quantum core · institution-dependent · Interactive lesson
Observables as matrices in the energy basis
The box hands you an orthonormal basis for nothing, so use it. Every observable becomes a matrix NumPy can hold: H diagonal, x and p checkerboards whose only surviving off-diagonal entries have m − n odd. The craft is knowing which entries vanish before you integrate, and what breaks when you cut the array off at N.
UPV-05.05 · Lesson 5 of 9 in this unit. Position is not a completion score.Quantum core · institution-dependent. Your university determines the required depth of these quantum topics, including the use of operators, differential equations and computation. Institution-dependent does not automatically mean optional.
Build the model
Pick the basis that diagonalises H, and every other observable becomes an array.
The key idea
A matrix representation of an observable is the array of numbers Aₘₙ = ⟨m|A|n⟩ taken in some orthonormal basis; in the box that basis is the energy eigenstates, and the array carries every prediction the operator can make.
Example. For a box of width L = 0.800 nm, ⟨2|x|2⟩ = L/2 = 0.400 nm, ⟨1|x|2⟩ = −16L/(9π²) = −0.144 nm, and ⟨1|x|3⟩ = 0 exactly, because 3 − 1 is even.
The complete physical model and assumptions
Once the Dirichlet problem is solved, the kets |n⟩ with ⟨x|n⟩ = √(2/L) sin(nπx/L) are an orthonormal basis of L²([0, L]) and Σₙ |n⟩⟨n| = 1. Slide that identity in on either side of any operator and the operator becomes an array: A = Σₘₙ |m⟩ Aₘₙ ⟨n| with Aₘₙ = ⟨m|A|n⟩. Nothing has been approximated; this is the same operator written in a different alphabet. The alphabet was chosen so that H comes out diagonal, Hₘₙ = Eₙδₘₙ, and that is the whole point of it, because exp(−iHt/ℏ) is then diagonal too and evolution is a phase on each coefficient. But an operator is diagonal in the energy basis only if it commutes with H, and neither x nor p does. Their matrices are checkerboards fixed by the parity of ψₙ about the midpoint: ⟨m|x|n⟩ = −8Lmn/(π²(m² − n²)²) when m − n is odd, and exactly zero when m − n is even and m ≠ n. The cost arrives the moment you truncate to an N by N array. Truncation is a projector, that projector commutes with neither x nor p, and so the product of two truncated matrices is not the truncation of the product: p² is exactly diagonal here, yet squaring the 3 by 3 truncation of p returns 72% of its (1,1) entry and invents a (1,3) entry where the true value is zero. Sum rules are how you catch that before it ruins an answer.
1Insert the identity and the operator becomes an array
Completeness licenses the whole move. The sine states satisfy Σₙ |n⟩⟨n| = 1, so A = 1 A 1 = Σₘₙ |m⟩ ⟨m|A|n⟩ ⟨n|, and a Hermitian operator is completely specified by the numbers Aₘₙ = ⟨m|A|n⟩, subject to Aₘₙ = Aₙₘ*. The basis was chosen to diagonalise H, so Hₘₙ = Eₙδₘₙ with Eₙ = n²π²ℏ²/(2ML²). That is the free lunch and the reason for the basis: exp(−iHt/ℏ) is diagonal too, so evolution is cₙ(t) = cₙ(0) exp(−iEₙt/ℏ), one phase per coefficient. Everything else costs an integral. The criterion for a second free lunch is exact, and worth stating as a rule: because no two levels of the box share an energy, A is diagonal in the energy basis if and only if [A, H] = 0. Since [x, H] = iℏp/M is not zero, x cannot be diagonal here. The off-diagonal entries you are about to compute are not clutter, they are the statement that position and energy are incompatible.
2Parity does the integral before you do
Move the origin to the centre and set u = x − L/2. Then ψₙ has parity (−1)ⁿ⁺¹ in u: odd n gives an even function, even n an odd one. The operator u is odd, so ⟨m|u|n⟩ vanishes unless ψₘψₙ is odd, which happens only when m − n is odd. That single argument kills half the matrix with no integration at all. ⟨1|x|3⟩, ⟨2|x|4⟩ and ⟨1|x|5⟩ are exactly zero, while the diagonal is ⟨n|x|n⟩ = L/2 by symmetry alone. For the surviving entries the integral gives xₘₙ = −8Lmn/(π²(m² − n²)²). In units of L that is x₁₂ = −0.18013, x₂₃ = −0.19454 and x₃₄ = −0.19851 next to the diagonal, but only x₁₄ = −0.014410 three steps out: the squared denominator makes distant entries fall like 1/m³, so the position matrix is strongly band-dominated. The shared sign is a phase convention rather than physics, since replacing |2⟩ by −|2⟩ flips x₁₂ with it. No single off-diagonal sign is measurable; |xₘₙ|² is, and so is any product around a closed loop of indices, such as x₁₂x₂₃x₃₄x₄₁, which no rephasing can change.
3Take p from the commutator, not from a second integral
For any H = p²/2M + V(x) the identity p = (iM/ℏ)[H, x] is exact. Sandwich it between energy eigenstates and the commutator collapses to a number, because H acts on its own eigenvectors: pₘₙ = iM(Eₘ − Eₙ)xₘₙ/ℏ. The momentum matrix therefore falls out of the position matrix and the spectrum, with no new integration. Putting in Eₘ − Eₙ = π²ℏ²(m² − n²)/(2ML²) gives pₘₙ = −4iℏmn/(L(m² − n²)) for m − n odd and zero otherwise. Three checks pay for themselves. The entries are purely imaginary and antisymmetric in their indices, so pₘₙ = pₙₘ* and the matrix is Hermitian. Every diagonal entry vanishes, so ⟨p⟩ = 0 in each stationary state, as it must be for a real bound eigenfunction. And the fall-off is only 1/m, because the factor Eₘ − Eₙ grows like m² and cancels one power of the denominator. In units of ℏ/L the near-diagonal entries are p₁₂ = 2.667i, p₂₃ = 4.800i, p₃₄ = 6.857i: they grow, they do not decay.
4Truncation is a projector, and projectors do not commute
To compute, you keep N rows and columns, so A becomes ΠN A ΠN. That is harmless for one operator and wrong for a product, because ΠN A B ΠN equals ΠN A ΠN B ΠN when ΠN commutes with A or with B, and in general not otherwise. The resolution of the identity you inserted between the two factors was truncated along with everything else. The box supplies a clean test case. Inside the walls V = 0, so p² = 2MH is exactly diagonal, (p²)ₘₙ = (nπℏ/L)²δₘₙ. Now truncate p to 3 by 3. In units of ℏ/L only p₁₂ = 2.667i and p₂₃ = 4.800i survive, so ((P₃)²)₁₁ = |p₁₂|² = 64/9 = 7.111 against the exact π² = 9.870, just 72% of it. Worse, ((P₃)²)₁₃ = p₁₂p₂₃ = −12.8, where the true p² has a clean zero: the columns m = 4, 6, 8, … whose contributions cancel that term were thrown away. Widening to N = 9 lifts the (1,1) entry only to 8.977 and drags the spurious (1,3) entry to −2.771.
5Sum rules tell you whether N was large enough
Completeness also hands you a test you can run without knowing the answer: Σₘ |Aₘₙ|² = ⟨n|A†A|n⟩. For position that reads Σₘ |xₘₙ|² = ⟨n|x²|n⟩ = L²(1/3 − 1/(2n²π²)), which is 0.282673 L² in the ground row. Add the terms up. The diagonal alone gives 0.250000 L², or 88.4%; m = 2 lifts it to 0.282446, or 99.92%; m = 3 adds nothing at all because 3 − 1 is even; and m = 4 reaches 0.282653, or 99.993%. Four columns are already better than a part in ten thousand. Run the same test on momentum and the verdict reverses. Σₘ |pₘₙ|² = 2MEₙ = (nπℏ/L)², and in the ground row the partial sums reach 72.1% at N = 2, 92.6% at N = 10, 99.20% at N = 100 and still only 99.92% at N = 1000, because |p₁ₘ|² falls like 16ℏ²/(L²m²) while |x₁ₘ|² falls like 1/m⁶. A truncated basis is a fine place to compute ⟨x⟩ and a poor place to compute ⟨p²⟩. Take that one from H.
6What no finite matrix can ever do
[x, p] = iℏ has no finite-dimensional solution, and the box shows why in one line: the trace of a commutator of finite matrices is tr(XP) − tr(PX) = 0, while tr(iℏ IN) = iNℏ. A truncated pair must therefore fail the canonical commutation relation, and it is worth seeing where. At N = 3 the diagonal of [X₃, P₃] in units of iℏ is 0.9607, 0.9069, −1.8676: the first entry is already within 4% of the exact 1 and the second within 10%, while the whole deficit is dumped into the last kept row so that the trace comes out exactly zero. At N = 9 the (1,1) entry has climbed to 0.9985 and the last entry has fallen to −7.08. The working rule is to trust the top-left corner of a truncated array, never the last few rows, and to quote no number that leans on them. Diagonalising the truncated x is the same story with a happier ending: the eigenvalues of X₃ are 0.235L, 0.500L and 0.765L, a coarse quadrature grid inside the well, and X₈ gives eight nearly evenly spaced nodes from 0.101L to 0.899L.
Key equations
Read the units, assumptions and limits before substituting.
Matrix element in the energy basis
Aₘₙ = ⟨m|A|n⟩ = (2/L) ∫₀ᴸ sin(mπx/L) A sin(nπx/L) dx
Two indices and one integral turn an operator into an array you can hand to numpy.linalg.
H is diagonal by construction
Hₘₙ = Eₙδₘₙ, Eₙ = n²π²ℏ²/(2ML²)
A is diagonal in this basis if and only if [A, H] = 0, which is exactly why x and p are not.
M is the particle mass and L the wall separation; Eₙ in joulesPosition matrix and its parity rule
xₙₙ = L/2xₘₙ = −8Lmn/(π²(m² − n²)²) for m − n odd
Parity settles half the matrix before any integral, and it is why the box absorbs only when m − n is odd.
zero for every m ≠ n with m − n even; xₘₙ in metresMomentum from the commutator with H
pₘₙ = iM(Eₘ − Eₙ)xₘₙ/ℏ = −4iℏmn/(L(m² − n²))
p = (iM/ℏ)[H, x] builds the whole momentum matrix from the position matrix and the spectrum: no second integral.
m − n odd, else zero; pₙₙ = 0 always; units kg m s⁻¹p² is diagonal, but the square of truncated p is not
(p²)ₘₙ = 2MEₙδₘₙ = (nπℏ/L)²δₘₙ
((P₃)²)₁₁ = 64/9 ℏ²/L² is 72% of π²ℏ²/L², and ((P₃)²)₁₃ = −12.8 ℏ²/L² where p² has a clean zero.
V = 0 inside, so p² = 2MH exactly; PN is p cut to N by NSum rule: the truncation test
Σₘ |xₘₙ|² = ⟨n|x²|n⟩ = L²(1/3 − 1/(2n²π²))
Row 1 of x is 99.99% complete by N = 4, while the same test on p is still 0.8% short at N = 100.
n = 1 gives 0.28267 L²; both sides in square metresInteractive lab
Predict first. Explore the model. Compare the result.
Explore the model
Try this. Hold the cut at 5 and sweep n: the zero bars change parity, the L/2 diagonal spike walks along the row, and the p bars grow with n while the neighbouring x bars hold near 0.2 L. Now pull the cut back to 2 at n = 4 and you have deleted the largest momentum element in the row.
Live results
- Eₙ/E₁
- 4
- |x| at m = n + 1
- 0.1945 L
- |p| at m = n + 1
- 4.800 ℏ/L
- row sum rule for x²
- 0.3207 L²
Results follow this lesson’s model and assumptions. Displayed values are rounded.
Predict → change one variable → check
Plan a change before running it. Every other input stays at the saved baseline.
Saved baseline. Row index n: 2; Keep columns m up to: 3
This experiment is kept only while this page is open. It does not change saved course progress.
Catch the common trap
The commonest slip here is to argue that because the energy eigenvectors are orthogonal, ⟨m|x|n⟩ must vanish for m ≠ n. Orthogonality says ⟨m|n⟩ = δₘₙ, which is a statement about the identity operator, not about x. Putting an operator between the bra and the ket changes the integrand: the integral of x sin(mπx/L) sin(nπx/L) is not the integral of sin(mπx/L) sin(nπx/L), and for m − n odd it is emphatically not zero, since ⟨1|x|2⟩ = −0.180 L. The rule worth memorising is the general one, valid whenever the spectrum of H is non-degenerate as the box's is: A is diagonal in the eigenbasis of H if and only if [A, H] = 0. Since [x, H] = iℏp/M is not zero, the position matrix cannot be diagonal, and its off-diagonal entries are precisely what makes ⟨x⟩ move in a superposition and what gives the box its m − n odd absorption lines.
Practice & worked examples
3 authored examples. Make an attempt, then reveal the reasoning one step at a time.
EasyExample 1
A particle sits in an infinite square well of width L = 0.800 nm. Without integrating, say which of ⟨1|x|3⟩, ⟨2|x|4⟩, ⟨1|x|2⟩ and ⟨2|x|5⟩ are zero, then evaluate the two that are not.
Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.
0 of 5 steps revealed.
- Shift the origin to the midpoint. There ψₙ has parity (−1)ⁿ⁺¹, so ψₘψₙ is even whenever m − n is even, while x − L/2 is odd. Every element with m − n even therefore collapses to (L/2)δₘₙ.
- ⟨1|x|3⟩ and ⟨2|x|4⟩ both have m − n = −2, an even number, so both are exactly zero and no integral is needed to say so.
- ⟨1|x|2⟩ and ⟨2|x|5⟩ have m − n odd, so use xₘₙ = −8Lmn/(π²(m² − n²)²).
- ⟨1|x|2⟩ = −8(0.800 nm)(1)(2)/(π²(1 − 4)²) = −12.8/(9π²) nm = −12.8/88.83 nm = −0.1441 nm.
- ⟨2|x|5⟩ = −8(0.800 nm)(2)(5)/(π²(4 − 25)²) = −64/(441π²) nm = −64/4352.5 nm = −0.01470 nm.
Answer. ⟨1|x|3⟩ = ⟨2|x|4⟩ = 0 by parity; ⟨1|x|2⟩ = −0.1441 nm and ⟨2|x|5⟩ = −0.01470 nm. An element one step off the diagonal is about ten times one three steps off, which is the 1/m³ fall-off at work.
MediumExample 2
Test the truncation of the position matrix. For the ground row n = 1, sum |x₁ₘ|² over the first four columns and compare it with the exact ⟨1|x²|1⟩ = L²(1/3 − 1/(2π²)). Then say how the same test goes for momentum.
Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.
0 of 6 steps revealed.
- Row 1 of x in units of L: x₁₁ = 0.500000, x₁₂ = −16/(9π²) = −0.180127, x₁₃ = 0 because 3 − 1 is even, and x₁₄ = −32/(225π²) = −0.014410.
- Square them, in units of L²: 0.250000, 0.032446, 0, 0.000208.
- Partial sum over four columns, carrying full precision through the addition: 0.282653 L².
- Exact value: L²(1/3 − 1/(2π²)) = L²(0.333333 − 0.050661) = 0.282673 L², so the four-column sum captures 99.993% of it.
- The momentum sum rule is Σₘ |p₁ₘ|² = (πℏ/L)² = 9.8696 ℏ²/L², but the m = 2 term alone is (8/3)² = 7.1111, only 72.1% of it, and |p₁ₘ|² falls like 1/m² rather than like 1/m⁶.
- Partial sums for p reach 92.6% at N = 10, 99.20% at N = 100 and 99.92% at N = 1000.
Answer. 0.282653 L² against the exact 0.282673 L²: four columns capture 99.993% of the x sum rule. Momentum would need N of order 10⁴ for the same accuracy, which is why ⟨p²⟩ should be read off H rather than off a truncated p.
HardExample 3
Show that no truncated pair of matrices can satisfy [x, p] = iℏ. Compute the diagonal of [X₃, P₃] in units of iℏ and take its trace.
Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.
0 of 6 steps revealed.
- x is real and symmetric, xₖₙ = xₙₖ, while p is purely imaginary and antisymmetric, pₙₖ = −pₖₙ. So ([X, P])ₙₙ = Σₖ (xₙₖpₖₙ − pₙₖxₖₙ) = 2 Σₖ xₙₖpₖₙ.
- Inside a 3 by 3 block the m − n odd rule leaves one term for n = 1 (k = 2), two for n = 2 (k = 1 and k = 3) and one for n = 3 (k = 2).
- n = 1: 2x₁₂p₂₁ = 2(−16L/(9π²))(−8iℏ/(3L)) = 256iℏ/(27π²) = 0.9607 iℏ.
- n = 2: 2x₂₁p₁₂ + 2x₂₃p₃₂ = −256iℏ/(27π²) + 2304iℏ/(125π²) = (−0.9607 + 1.8676) iℏ = 0.9069 iℏ.
- n = 3: 2x₃₂p₂₃ = −2304iℏ/(125π²) = −1.8676 iℏ.
- Trace: 0.9607 + 0.9069 − 1.8676 = 0 exactly, whereas tr(iℏ I₃) = 3iℏ. Any finite commutator is traceless, so the canonical relation cannot hold.
Answer. The diagonal is (0.9607, 0.9069, −1.8676) iℏ and the trace is exactly 0, against 3iℏ for iℏ I₃. At N = 9 the (1,1) entry has reached 0.9985 iℏ while the last row has sunk to −7.08 iℏ.
Quick check
Select an answer and explain it before checking.
Review & continue
A matrix representation of an observable is the array of numbers Aₘₙ = ⟨m|A|n⟩ taken in some orthonormal basis; in the box that basis is the energy eigenstates, and the array carries every prediction the operator can make.
- Explain the relationship without looking at the equation.
- Check a sign, a unit and a model assumption in your working.
- Return to the lab or worked example if a step is still unclear.