Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Vectors and Linear Algebra

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:

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 v=2e1+3e2\mathbf{v} = 2e_1 + 3e_2, 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()
<Figure size 600x500 with 1 Axes>

Inner products, norms, and orthogonality

The inner product (dot product) ab\langle a \mid b \rangle measures how much two vectors share a direction:

where θ\theta 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:

eiej=δij={1i=j0ij.\langle e_i \mid e_j \rangle = \delta_{ij} = \begin{cases} 1 & i = j \\ 0 & i \neq j \end{cases}.

The norm is the square root of a vector’s inner product with itself, giving its length:

aa=a12+a22,a=a12+a22.\langle a \mid a \rangle = a_1^2 + a_2^2, \qquad |a| = \sqrt{a_1^2 + a_2^2}.

A vector with a=1|a| = 1 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

a11x1+a12x2=b1a21x1+a22x2=b2\begin{aligned} a_{11}x_1 + a_{12}x_2 &= b_1 \\ a_{21}x_1 + a_{22}x_2 &= b_2 \end{aligned}

packs into a single matrix-vector product:

Matrix times vector is the dot product of each row of AA with x\mathbf{x}:

Ax=(a11x1+a12x2a21x1+a22x2).A\mathbf{x} = \begin{pmatrix} a_{11}x_1 + a_{12}x_2 \\ a_{21}x_1 + a_{22}x_2 \end{pmatrix}.

If AA is invertible, the solution is x=A1b\mathbf{x} = A^{-1}\mathbf{b}.

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]

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λI)v=0(A - \lambda I)\mathbf{v} = 0, a nonzero solution exists only when the characteristic equation holds:

det(AλI)=0.\det(A - \lambda I) = 0.

The sign and size of λ\lambda say what happens to the eigenvector: λ>1\lambda > 1 stretches it, 0<λ<10 < \lambda < 1 compresses it, λ<0\lambda < 0 flips it, and λ=0\lambda = 0 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 H^ψ=Eψ\hat H\psi = E\psi is this same eigenvalue problem Av=λvA\mathbf{v}=\lambda\mathbf{v}.

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 typeExampleEffect
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()
<Figure size 800x800 with 4 Axes>

Problems

Problem 1: Dot product and angle

Find ab\langle a \mid b \rangle and the angle between a=(1,2)a = (1, 2) and b=(3,1)b = (3, -1).

Problem 2: Normalize a vector

Normalize v=(3,4)v = (3, 4).

Problem 3: Check orthogonality

Are (1,1)(1, 1) and (1,1)(1, -1) orthogonal? Are they orthonormal?

Problem 4: Eigenvalues by hand

Find the eigenvalues of A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}.

Problem 5: Solve a linear system

Solve (2312)x=(71)\begin{pmatrix} 2 & 3 \\ 1 & -2 \end{pmatrix}\mathbf{x} = \begin{pmatrix} 7 \\ 1 \end{pmatrix} by hand and check against the code.

Problem 6: Rotation preserves length

Show that the rotation matrix R=(cosθsinθsinθcosθ)R = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} leaves the norm of any vector unchanged.

Problem 7: Eigenvector direction

Verify that (1,1)(1, 1) is an eigenvector of A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} and identify its eigenvalue.

Problem 8: Complex inner product

For complex vectors the inner product conjugates the first entry: ab=iaibi\langle a \mid b \rangle = \sum_i a_i^* b_i. Compute aa\langle a \mid a \rangle for a=(1, i)a = (1,\ i) and confirm it is real and positive.