Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Vectors and spaces

Basis, Dimension and Change of Basis

The same point can have different coordinates in different "rulers". Choosing the right basis is the idea behind PCA, Fourier analysis, robot coordinate frames and sparse coding.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Same place, different directions

Your friend’s house is “3 blocks east, 2 blocks north”. But in a city where the streets run diagonally, the same house might be “2 blocks along Main Street, 1 block along Park Avenue”. The house hasn’t moved. Only the way you describe it has changed.

A set of directions you use to describe every place is called a basis, and the numbers you give are the coordinates.

How many directions do you need?

  • On a line, like a railway track: 1 direction (forwards and backwards).
  • On a flat map: 2 directions.
  • In the air, for a drone: 3 directions.

That number is the dimension. You can’t describe a flat map with just one direction, and a third direction on a flat map would be wasted.

📝 Quick check (Level 0)
0/3 answered
  1. 1. How many numbers do you need to describe any spot on a flat football field?
  2. 2. A submarine moving underwater needs how many directions?
  3. 3. If you change the directions you use, does the house move?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

The standard basis

In R2\mathbb{R}^2, the standard basis is e1=(1,0)\mathbf e_1 = (1,0) and e2=(0,1)\mathbf e_2 = (0,1). The point (3,2)(3,2) is 3e1+2e23\mathbf e_1 + 2\mathbf e_2, so its coordinates are just its components.

A different basis

Take b1=(1,1)\mathbf b_1 = (1,1) and b2=(1,−1)\mathbf b_2 = (1,-1). To find the coordinates of x=(3,1)\mathbf x = (3,1), solve:

a(1,1)+b(1,−1)=(3,1) ⇒ a+b=3, a−b=1 ⇒ a=2, b=1a(1,1) + b(1,-1) = (3,1) \ \Rightarrow\ a + b = 3,\ a - b = 1 \ \Rightarrow\ a = 2,\ b = 1

So [x]B=(2,1)[\mathbf x]_B = (2, 1): “2 steps along b1\mathbf b_1, 1 step along b2\mathbf b_2”. It’s the same point with different numbers. Move the sliders and watch the tilted grid:

Change of basis: same point, new coordinates
b₁b₂p
Standard coordinates: p = (3, 1). In the basis (b₁, b₂): p = 2·b₁ + 1·b₂, so [p]_B = (2, 1). Same point, different coordinates.

What makes a basis

A basis must (1) span the space, so it can reach everything, and (2) be independent, so no direction is wasted. Two parallel vectors aren’t a basis of the plane. Three vectors in the plane are too many.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Coordinates of (4, 6) in the basis (2, 0), (0, 3)?
  2. 2. Is {(1, 2), (2, 4)} a basis of ℝ²?
  3. 3. How many vectors are in any basis of ℝ⁴?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Basis, coordinates and dimension

Definition

A basis of VV is a list b1,…,bn\mathbf b_1, \dots, \mathbf b_n that is linearly independent and spans VV. Every x∈V\mathbf x \in V can then be written in exactly one way as x=c1b1+⋯+cnbn\mathbf x = c_1\mathbf b_1 + \dots + c_n\mathbf b_n. The numbers [x]B=(c1,…,cn)[\mathbf x]_B = (c_1,\dots,c_n) are its coordinates. The dimension dim⁡V=n\dim V = n is the number of basis vectors.

The change-of-basis matrix

Put the basis vectors into the columns of a matrix P=[b1⋯bn]P = [\mathbf b_1 \cdots \mathbf b_n]. Then

x=P [x]Band[x]B=P−1x.\mathbf x = P\,[\mathbf x]_B \qquad\text{and}\qquad [\mathbf x]_B = P^{-1}\mathbf x.

If the basis is orthonormal (unit vectors at right angles to each other), then P−1=P⊤P^{-1} = P^\top. Each coordinate is then just a dot product, ci=bi⋅xc_i = \mathbf b_i\cdot\mathbf x. No equations to solve, and no loss of accuracy. That’s why orthonormal bases are loved in numerical work (A2.4).

🐍 Exercise 1: change of basis with NumPy
to_basis solves B c = x (basis vectors are the columns of B); from_basis multiplies back; to_orthonormal_basis uses the transpose.

Many useful bases

Basis Space Used for
Standard e1,…,en\mathbf e_1,\dots,\mathbf e_n Rn\mathbb{R}^n raw features, pixels
One-hot vectors categories class labels, token IDs
1,x,x2,…1, x, x^2, \dots or 1,(x−a),(x−a)2,…1, (x-a), (x-a)^2, \dots polynomials regression, Taylor series (A3)
Sines and cosines signals Fourier analysis, audio, vibration (A10)
Principal components data PCA: the directions of greatest variance (D9)
A rotation matrix’s columns 3D space a robot’s body frame (R2)
Robot coordinate frames are bases

A robot at position t\mathbf t facing angle θ\theta carries its own basis: “forward” (cos⁡θ,sin⁡θ)(\cos\theta, \sin\theta) and “left” (−sin⁡θ,cos⁡θ)(-\sin\theta, \cos\theta). These are the columns of the rotation matrix R(θ)R(\theta). A landmark the camera sees at pR\mathbf p_R in the robot frame is at pW=R pR+t\mathbf p_W = R\,\mathbf p_R + \mathbf t in the world, and pR=R⊤(pW−t)\mathbf p_R = R^\top(\mathbf p_W - \mathbf t). Practice Code 5 implements this.

📝 Quick check (Level 2)
0/3 answered
  1. 1. P = [[1, 1], [1, −1]] and [x]_B = (2, −1). Then x = ?
  2. 2. For an orthonormal basis Q, the coordinates of x are…
  3. 3. dim{x ∈ ℝ⁴ : x₁ + x₂ + x₃ + x₄ = 0} = ?

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Why dimension is well defined

Theorem

All bases of a finite-dimensional space have the same number of vectors.

Proof. Let BB and B′B' be bases with mm and nn vectors. BB is independent and lies in span⁡(B′)\operatorname{span}(B'), so m≤nm \le n by the exchange lemma (A2.1-3). Swapping roles gives n≤mn \le m. ∎

Theorem

Coordinates with respect to a basis are unique.

Proof. If ∑cibi=∑dibi\sum c_i\mathbf b_i = \sum d_i\mathbf b_i, then ∑(ci−di)bi=0\sum(c_i - d_i)\mathbf b_i = \mathbf 0. Independence forces ci=dic_i = d_i. ∎

Building bases

  • Every spanning list contains a basis. Remove vectors that are combinations of earlier ones. The span doesn’t change, and what’s left is independent.
  • Every independent list extends to a basis. Keep adding vectors not already in the span (Practice Code 4).
  • So in an nn-dimensional space: any nn independent vectors form a basis, and so do any nn vectors that span.

Dimension of a sum

Theorem

For subspaces U,WU, W of a finite-dimensional space: dim⁡(U+W)=dim⁡U+dim⁡W−dim⁡(U∩W)\dim(U + W) = \dim U + \dim W - \dim(U\cap W).

This is the subspace version of inclusion–exclusion (A1-1). Two planes through the origin in R3\mathbb{R}^3 have 2+2−dim⁡(U∩W)≤32 + 2 - \dim(U\cap W) \le 3, so they must share at least a line.

Changing the basis of a linear map

If a linear map has matrix AA in the standard basis, its matrix in the basis PP is A′=P−1APA' = P^{-1}AP. Matrices related this way are called similar: they describe the same map in different coordinates. The search for a basis where A′A' is as simple as possible, ideally diagonal, leads to eigenvectors (A2.3).

Exercise 3.1: What is the dimension of the space of symmetric 3 × 3 matrices?

A symmetric matrix is fixed by its diagonal (3 entries) and its upper triangle (3 entries), so the dimension is 6. A basis: E11,E22,E33,E12+E21,E13+E31,E23+E32E_{11}, E_{22}, E_{33}, E_{12}+E_{21}, E_{13}+E_{31}, E_{23}+E_{32}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Two distinct planes U, W through the origin in ℝ³. dim(U + W) = ?
  2. 2. dim of the solution space of y″ + y = 0?
  3. 3. A′ = P⁻¹AP means A and A′…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Learning the basis: sparse coding

Instead of fixing a basis, we can learn one in which data looks simple. Olshausen and Field (1996) learned a dictionary of image patches in which each natural image patch is a sparse combination of a few atoms. The atoms that emerged look like the edge detectors in the primary visual cortex, and like the first-layer filters of CNNs. Such dictionaries are often overcomplete, with more atoms than dimensions (for example, 256 atoms for 64-pixel patches). Representations are then no longer unique, and sparsity picks one. The same idea underlies sparse autoencoders used to interpret LLMs today (F15).

A bad basis amplifies errors

If two basis vectors are almost parallel, solving for coordinates becomes ill-conditioned. A tiny error in x\mathbf x can produce a huge change in [x]B[\mathbf x]_B. The worst-case amplification is ∥P−1∥\lVert P^{-1}\rVert, and the condition number κ(P)\kappa(P) measures it relative to ∥P∥\lVert P\rVert (A2.4). This matters for:

  • sensor fusion and calibration, where nearly collinear measurement directions make estimates unreliable;
  • regression with nearly collinear features, where coefficients swing wildly;
  • robot kinematics near singularities, where the Jacobian’s columns become nearly dependent and joint velocities explode (S5).
🐍 Exercise 2 (research): conditioning of a basis
With b₁ = (1,1) and b₂ = (1, 1+ε), measure the worst-case growth of coordinate errors and compare it with the condition number.

Frames in robotics: choosing a basis on purpose

The Denavit–Hartenberg convention (1955) attaches a coordinate frame to every link of a robot arm, chosen so each joint is described by just 4 numbers. Modern alternatives (product of exponentials, R3) avoid some of its pitfalls, but the principle is the same: a well-chosen basis makes the kinematics simple. In estimation, writing errors in the robot’s body frame rather than the world frame often makes filters behave much better, as in the “invariant” EKF (Barrau and Bonnabel, 2017; T5).

References

  1. J. Denavit and R. Hartenberg (1955). “A kinematic notation for lower-pair mechanisms based on matrices.” Journal of Applied Mechanics, 22.
  2. B. Olshausen and D. Field (1996). “Emergence of simple-cell receptive field properties by learning a sparse code for natural images.” Nature, 381.
  3. A. Barrau and S. Bonnabel (2017). “The invariant extended Kalman filter as a stable observer.” IEEE Transactions on Automatic Control, 62(4).
  4. S. Axler (2024). Linear Algebra Done Right, 4th ed. Chapter 2.
  5. G. Strang (2016). Introduction to Linear Algebra, 5th ed. Chapters 3.5 and 8.