Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 62 · Linear Transformations

Change of Basis

Learn how coordinates change when you switch bases, how to write a matrix in a new basis with P^-1 A P, and why similar matrices share trace, determinant and eigenvalues.

A vector is an arrow, and the list of numbers you write for it is only a description of that arrow. The description depends on which basis you measure with. In Basis and Dimension you saw that the same arrow has different coordinates in different bases. Now we make that idea precise and ask the matching question for transformations: if a matrix A describes a transformation in the standard basis, what matrix describes the same transformation in another basis?

The answer is a short formula, B = P⁻¹ A P, and it is one of the most useful ideas in the whole subject. Diagonalization, the spectral theorem and the SVD are all "choose a basis in which the matrix looks simple". This lesson builds the formula from scratch and checks it in NumPy.

One arrow, many descriptions

The arrow It exists without any numbers.
The basis Chooses the rulers we measure with.
The coordinates The result of measuring.
1 / 2

Coordinates in a new basis

Take two vectors that form a basis of the plane:

  • b1 = (1, 1)
  • b2 = (-1, 1)

Put them in the columns of a matrix P. This is called the change-of-basis matrix. A vector whose coordinates in the new basis are c = (c1, c2) is the combination c1·b1 + c2·b2, and in matrix form that is simply

TEXT
v = P c

So P turns new coordinates into standard coordinates. To go the other way you solve for c:

TEXT
c = P⁻¹ v

Because the columns of P are a basis, P is invertible, so this always works. In code we use np.linalg.solve(P, v) instead of forming the inverse (see Solving Systems with NumPy).

Python Coordinates of a vector in a new basis

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The vector (3, 1) is two steps along b1 and one step backwards along b2, so its coordinates are (2, -1). The arrow did not move. Only the way we count along it changed.

Many books write the coordinates of v in basis B as [v]_B. With that notation v = P [v]_B and [v]_B = P⁻¹ v. It is easy to mix up which way P goes, so say it aloud: P takes new coordinates to standard ones.

Going between two non-standard bases

You can chain the two directions. If P has the columns of basis B and Q has the columns of basis C, then a vector with B-coordinates c has standard coordinates P c, and its C-coordinates are Q⁻¹ P c. So Q⁻¹ P is the matrix that converts B-coordinates into C-coordinates. The standard basis is just the special case where the matrix is the identity.

A transformation in a new basis

Now the interesting part. A matrix A takes standard coordinates in and gives standard coordinates out. Suppose you want a matrix B that takes B-coordinates in and gives B-coordinates out. Follow a vector through three steps:

  1. Convert the new coordinates c to standard coordinates: P c.
  2. Apply the transformation: A P c.
  3. Convert the answer back to new coordinates: P⁻¹ A P c.

So the matrix of the same transformation in the new basis is

TEXT
B = P⁻¹ A P

Read it right to left, the order in which things happen to the vector.

flowchart LR
    C["c<br/>(new coordinates)"] -- "P" --> V["v<br/>(standard)"]
    V -- "A" --> W["A v<br/>(standard)"]
    W -- "P⁻¹" --> D["B c<br/>(new coordinates)"]

Going around the three-step path is the same as multiplying by B directly.

Let's try it with a symmetric matrix and the basis above.

Python P^-1 A P turns A into a diagonal matrix

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

B is diagonal with entries 3 and 1. That is not an accident: A stretches b1 by a factor of 3 and leaves b2 alone. In the basis (b1, b2) the transformation is just "scale the first coordinate by 3". This is the whole idea behind eigenvalues: a basis made of special directions makes a matrix easy to understand.

The columns of B have a simple meaning too. Column j of B holds the new coordinates of A bⱼ, which is exactly what the formula computes.

A rotation seen through a skewed basis

The new matrix does not have to be diagonal. Take the 90-degree rotation and look at it through the basis b1 = (1, 0), b2 = (1, 1).

Python The same rotation, described in a skewed basis

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The matrix B = [[-1, -2], [1, 1]] looks nothing like a rotation matrix, yet it does exactly what the rotation does, expressed in a different language. Both ways of computing the result agree.

Similar matrices and what they share

Two square matrices A and B are similar if B = P⁻¹ A P for some invertible P. Similar matrices are the same transformation seen in different bases, so anything that belongs to the transformation itself, and not to the basis, must be equal:

  • the determinant (the area scaling does not depend on your rulers),
  • the trace (the sum of the diagonal),
  • the rank,
  • the eigenvalues.
Python What similar matrices share

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The invariants match, but the entries of A and B differ. Remember that this goes one way: equal trace and determinant do not prove two matrices are similar, but different values prove they are not.

Why you should care

Changing basis is how mathematicians turn hard problems into easy ones. Powers of a matrix are painful, but in a basis where it is diagonal they are just powers of numbers: Aᵏ = P Bᵏ P⁻¹. Graphics engines switch between object, world and camera coordinates. Principal component analysis rotates your data into a basis aligned with its spread. Each time the recipe is the same: convert in, do the easy thing, convert out.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. The columns of P are the new basis vectors written in standard coordinates. What does P do to a coordinate vector c?

    v = P c: new coordinates go in, standard coordinates come out. P inverse does the opposite.
  2. 2. A transformation has matrix A in the standard basis. Which expression gives its matrix in the basis whose columns form P?

    Read right to left: convert new coordinates to standard with P, apply A, convert back with P^-1.
  3. 3. Which quantity can differ between two similar matrices?

    Similar matrices describe the same transformation in different bases, so determinant, trace, rank and eigenvalues agree. The entries depend on the basis.
  4. 4. Why does P have to be invertible?

    An invertible square matrix has independent columns that span the space, which is exactly what a basis is.

Summary

  • Coordinates depend on the basis; the arrow does not.
  • If the columns of P are a basis, v = P c and c = P⁻¹ v.
  • The matrix of a transformation A in the new basis is B = P⁻¹ A P.
  • Similar matrices share determinant, trace, rank and eigenvalues.
  • A good basis can make a matrix diagonal, which is the idea behind eigenvalues and the SVD.

Next up: Determinants, the single number that tells you how a transformation scales area and volume.