Linear algebra is the backbone of quantum mechanics. States are vectors, observables are matrices, and measurement outcomes are eigenvalues. Everything that follows in the course is, at bottom, an eigenvalue problem in a vector space. This page builds that vocabulary from the 2D picture up.
Vectors¶
What is a vector?¶
A vector is an ordered collection of numbers describing the state or configuration of a system:
, a 2D vector,
and , unit vectors along the axes,
, a 3D vector,
, a 4D vector with complex components,
, an infinite-dimensional vector (a sequence).
Vectors may live in real or complex vector spaces depending on their components. In quantum mechanics the components are generally complex.
The plot shows a vector built as , decomposed along the two basis directions.
Source
import numpy as np
import matplotlib.pyplot as plt
e1 = np.array([1, 0])
e2 = np.array([0, 1])
v = 2 * e1 + 3 * e2
fig, ax = plt.subplots(figsize=(6, 5))
ax.set_xlim(-0.5, 3.5)
ax.set_ylim(-0.5, 3.5)
ax.set_aspect('equal')
ax.arrow(0, 0, *e1, head_width=0.1, color='gray', length_includes_head=True)
ax.arrow(0, 0, *e2, head_width=0.1, color='gray', length_includes_head=True)
ax.text(1.05, -0.25, r'$e_1$', fontsize=13)
ax.text(-0.28, 1.05, r'$e_2$', fontsize=13)
ax.arrow(0, 0, *v, head_width=0.15, color='#2e4057', length_includes_head=True)
ax.plot([0, v[0]], [v[1], v[1]], '--', color='gray')
ax.plot([v[0], v[0]], [0, v[1]], '--', color='gray')
ax.text(v[0] + 0.1, v[1] + 0.1, r'$\mathbf{v} = 2e_1 + 3e_2$', color='#2e4057', fontsize=13)
ax.axhline(0, color='black', lw=0.8)
ax.axvline(0, color='black', lw=0.8)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Fig.1 A vector as a linear combination of basis vectors')
plt.tight_layout()
plt.show()
Inner products, norms, and orthogonality¶
The inner product (dot product) measures how much two vectors share a direction:
where is the angle between them. When two vectors are perpendicular the dot product is zero and we call them orthogonal. Vectors that are both orthogonal and normalized are orthonormal, compactly written with the Kronecker delta:
The norm is the square root of a vector’s inner product with itself, giving its length:
A vector with is normalized. Orthonormal bases and this norm are the finite-dimensional shadow of wavefunction normalization and orthogonality.
Matrices¶
Linear systems as matrix equations¶
A system of linear equations is a matrix acting on a vector. The system
packs into a single matrix-vector product:
Matrix times vector is the dot product of each row of with :
If is invertible, the solution is .
import numpy as np
A = np.array([[2, 3],
[1, -2]])
b = np.array([7, 1])
# Solve by inversion, and with the recommended solver
x_inv = np.linalg.inv(A) @ b
x_solve = np.linalg.solve(A, b)
print("solution via inverse:", x_inv)
print("solution via solve :", x_solve)solution via inverse: [2.42857143 0.71428571]
solution via solve : [2.42857143 0.71428571]
Prefer solve over inv
solve over invnp.linalg.solve(A, b) is both faster and more numerically accurate than forming np.linalg.inv(A) @ b. Inverting a matrix explicitly is almost never necessary and should be avoided in real calculations; we show the inverse here only because it makes the algebra transparent.
Eigenvalues and eigenvectors¶
When a matrix acts on a vector it usually changes both its length and direction. Certain special vectors keep their direction and are only rescaled. These are eigenvectors, and the scaling factors are eigenvalues.
Rearranging to , a nonzero solution exists only when the characteristic equation holds:
The sign and size of say what happens to the eigenvector: stretches it, compresses it, flips it, and collapses it. In quantum mechanics this exact structure reappears for operators acting on wavefunctions: eigenvalues are the measurable observables (energies, momenta) and eigenvectors are the states with definite outcomes. The next page makes that leap explicit, showing that a function is just a vector with infinitely many components and the Schrodinger equation is this same eigenvalue problem .
import numpy as np
A = np.array([[2, 1],
[1, 2]])
vals, vecs = np.linalg.eig(A)
print("eigenvalues :", vals)
print("eigenvectors (columns):\n", vecs)
# Verify A v = lambda v for the first eigenpair
print("\nA @ v0 :", A @ vecs[:, 0])
print("lambda0 * v0 :", vals[0] * vecs[:, 0])eigenvalues : [3.+0.j 1.+0.j]
eigenvectors (columns):
[[ 0.70710678+0.j -0.70710678+0.j]
[ 0.70710678+0.j 0.70710678+0.j]]
A @ v0 : [2.12132034+0.j 2.12132034+0.j]
lambda0 * v0 : [2.12132034+0.j 2.12132034+0.j]
The geometric action of a matrix¶
Different kinds of matrices deform a shape in characteristic ways:
| Matrix type | Example | Effect |
|---|---|---|
| Diagonal, unequal entries | [[1.8, 0], [0, 0.8]] | Stretch, different scaling per axis |
| Diagonal, equal entries | [[0.7, 0], [0, 0.7]] | Uniform scaling |
| Rotation (orthogonal) | [[cosθ, -sinθ], [sinθ, cosθ]] | Rotation, preserves lengths and angles |
| Off-diagonal term | [[1, k], [0, 1]] | Shear, slants without changing area |
We apply each matrix to the same small polygon to see how it transforms.
Source
import numpy as np
import matplotlib.pyplot as plt
coords = np.array([[0, 0], [0.5, 0.5], [0.5, 1.5], [0, 1], [0, 0]]).T
stretch = np.array([[1.8, 0], [0, 0.8]])
rotation = np.array([[np.cos(np.pi / 6), -np.sin(np.pi / 6)],
[np.sin(np.pi / 6), np.cos(np.pi / 6)]])
shear = np.array([[1, 0.8], [0, 1]])
scaling = np.array([[0.7, 0], [0, 0.7]])
transforms = {
"Stretch (non-uniform)": stretch,
"Rotation (30 deg)": rotation,
"Shear": shear,
"Scaling (uniform)": scaling,
}
fig, axes = plt.subplots(2, 2, figsize=(8, 8))
for ax, (name, M) in zip(axes.flat, transforms.items()):
ax.plot(coords[0], coords[1], 'r--', label='original')
new_coords = M @ coords
ax.plot(new_coords[0], new_coords[1], 'b-', label='transformed')
ax.set_title(name, fontsize=11)
ax.set_aspect('equal', 'box')
ax.set_xlim(-2, 2)
ax.set_ylim(-1, 2)
ax.grid(True, ls=':')
ax.legend(fontsize=8, loc='upper left')
plt.suptitle('Fig.2 How different matrices deform the same shape', fontsize=13)
plt.tight_layout()
plt.show()
Problems¶
Problem 1: Dot product and angle¶
Find and the angle between and .
Problem 2: Normalize a vector¶
Normalize .
Solution
, so the normalized vector is , which has length 1.
Problem 3: Check orthogonality¶
Are and orthogonal? Are they orthonormal?
Solution
Their dot product is , so they are orthogonal. Each has length , not 1, so they are orthogonal but not orthonormal. Dividing each by makes them orthonormal.
Problem 4: Eigenvalues by hand¶
Find the eigenvalues of .
Solution
so and , matching the numerical output above.
Problem 5: Solve a linear system¶
Solve by hand and check against the code.
Problem 6: Rotation preserves length¶
Show that the rotation matrix leaves the norm of any vector unchanged.
Problem 7: Eigenvector direction¶
Verify that is an eigenvector of and identify its eigenvalue.
Problem 8: Complex inner product¶
For complex vectors the inner product conjugates the first entry: . Compute for and confirm it is real and positive.