TExcelTAD
Home › Linear Algebra & Matrix Theory › The Matrix of a Linear Transformation

The Matrix of a Linear Transformation

Once you choose a basis for each space, every linear map between finite-dimensional spaces becomes a matrix, and applying the map becomes matrix-vector multiplication on coordinates. The derivative of polynomials becomes a small matrix with 1, 2, 3 above the diagonal. Changing the basis changes the matrix, and a well-chosen basis can turn differentiation into a rotation or even make integration a matrix inverse.

The recipe

Let T:V→WT: V \to W be linear, B=(v1,…,vn)B = (\mathbf{v}_1, \ldots, \mathbf{v}_n) a basis of VV and C=(w1,…,wm)C = (\mathbf{w}_1, \ldots, \mathbf{w}_m) a basis of WW. The matrix of TT with respect to BB and CC is the m×nm \times n matrix

[T]C←B=[[T(v1)]C[T(v2)]C⋯[T(vn)]C][T]_{C \leftarrow B} = \begin{bmatrix} [T(\mathbf{v}_1)]_C & [T(\mathbf{v}_2)]_C & \cdots & [T(\mathbf{v}_n)]_C \end{bmatrix}

Column jj holds the CC-coordinates of the image of the jj-th basis vector. By Linear Transformations Defined on a Basis those images determine TT, and indeed

[T(v)]C=[T]C←B⋅[v]Bfor every v∈V[T(\mathbf{v})]_C = [T]_{C \leftarrow B} \cdot [\mathbf{v}]_B \qquad \text{for every } \mathbf{v} \in V

To apply TT: take coordinates, multiply by the matrix, read the result as coordinates. For V=RnV = \mathbb{R}^n, W=RmW = \mathbb{R}^m with standard bases this is the familiar matrix of The Matrix of a Linear Transformation in Rn\mathbb{R}^n.

The derivative as a matrix

Take D(p)=p′D(p) = p' on P3P_3 with the basis 1,x,x2,x31, x, x^2, x^3 for both input and output. The images of the basis vectors are

D(1)=0→(0,0,0,0)D(x)=1→(1,0,0,0)D(x2)=2x→(0,2,0,0)D(x3)=3x2→(0,0,3,0)[D]=[0100002000030000]\begin{aligned} D(1) &= 0 && \to (0, 0, 0, 0) \\ D(x) &= 1 && \to (1, 0, 0, 0) \\ D(x^2) &= 2x && \to (0, 2, 0, 0) \\ D(x^3) &= 3x^2 && \to (0, 0, 3, 0) \end{aligned} \qquad [D] = \begin{bmatrix} 0 & 1 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 3 \\ 0 & 0 & 0 & 0 \end{bmatrix}

Differentiating p=5−2x+3x2+x3p = 5 - 2x + 3x^2 + x^3 is now [D]⋅(5,−2,3,1)=(−2,6,3,0)[D] \cdot (5, -2, 3, 1) = (-2, 6, 3, 0), i.e. p′=−2+6x+3x2p' = -2 + 6x + 3x^2. A helper that builds the matrix of any linear map on polynomials from a basis makes this mechanical:

python · try it yourself
from sympy import symbols, diff, Poly, Matrix

x = symbols("x")

def matrix_of(T, basis_in, n_out):
    """Matrix of T: columns are coefficients of T(b) in 1, x, ..., x^(n_out - 1)."""
    return Matrix([[Poly(T(b), x).coeff_monomial(x**k) for b in basis_in]
                   for k in range(n_out)])

basis = [1 + 0 * x, x, x**2, x**3]
Dm = matrix_of(lambda p: diff(p, x), basis, 4)
print("[D] =", Dm.tolist())
p = Matrix([5, -2, 3, 1])                    # 5 - 2x + 3x^2 + x^3
print("[D] p   =", list(Dm * p), " -> p' = -2 + 6x + 3x^2")
print("[D]^2 p =", list(Dm**2 * p), " -> p'' = 6 + 6x")
print("[D]^4 == 0:", Dm**4 == Matrix.zeros(4, 4))
print("eigenvalues:", Dm.eigenvals(), " eigenvectors:", [list(v) for v in Dm.nullspace()])
[D] = [[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3], [0, 0, 0, 0]]
[D] p   = [-2, 6, 3, 0]  -> p' = -2 + 6x + 3x^2
[D]^2 p = [6, 6, 0, 0]  -> p'' = 6 + 6x
[D]^4 == 0: True
eigenvalues: {0: 4}  eigenvectors: [[1, 0, 0, 0]]

Matrix facts now read as calculus facts. [D]4=0[D]^4 = 0 because the fourth derivative of a cubic is 0: DD is nilpotent. Its only eigenvalue is 0, with only the constants as eigenvectors (p′=λpp' = \lambda p has no nonzero polynomial solution for λ≠0\lambda \ne 0), so DD is not diagonalizable (Diagonalization). The rank is 3 and the nullity 1, as rank–nullity requires.

Composition is multiplication

If T:U→VT: U \to V and S:V→WS: V \to W, then [S∘T]=[S]⋅[T][S \circ T] = [S] \cdot [T] (with matching bases). For example, the integral J(p)=∫0xp:P2→P3J(p) = \int_0^x p: P_2 \to P_3 has a 4×34 \times 3 matrix, and D∘J=ID \circ J = I on P2P_2 while J∘D≠IJ \circ D \ne I on P3P_3, exactly as in The Algebra of Linear Transformations:

[J]=[00010001200013][D]P3→P2⋅[J]=I3[J]⋅[D]P3→P2=diag⁡(0,1,1,1)[J] = \begin{bmatrix} 0 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & \frac{1}{2} & 0 \\ 0 & 0 & \frac{1}{3} \end{bmatrix} \qquad [D]_{P_3 \to P_2} \cdot [J] = I_3 \qquad [J] \cdot [D]_{P_3 \to P_2} = \operatorname{diag}(0, 1, 1, 1)

The zero in the corner of J∘DJ \circ D is the lost constant term.

A different basis, a different matrix

The same map has different matrices in different bases. For T:V→VT: V \to V with basis BB, and another basis B′B' whose vectors have BB-coordinates in the columns of PP,

[T]B′=P−1[T]BP[T]_{B'} = P^{-1} [T]_B P

so the two matrices are similar and share eigenvalues, trace, determinant and rank. Picking the basis well can make the matrix very simple. Let DD act on V=span⁡{excos⁡x,exsin⁡x}V = \operatorname{span}\{e^x\cos x, e^x\sin x\}:

D(excos⁡x)=excos⁡x−exsin⁡x→column (1,−1)D(exsin⁡x)=exsin⁡x+excos⁡x→column (1,1)[D]=[11−11]\begin{aligned} D(e^x\cos x) &= e^x\cos x - e^x\sin x && \to \text{column } (1, -1) \\ D(e^x\sin x) &= e^x\sin x + e^x\cos x && \to \text{column } (1, 1) \qquad [D] = \begin{bmatrix} 1 & 1 \\ -1 & 1 \end{bmatrix} \end{aligned}

This is a rotation-scaling matrix with eigenvalues 1±i1 \pm i, matching e(1±i)xe^{(1 \pm i)x} (Complex Eigenvalues and Eigenvectors). And because it is invertible, integration is the inverse matrix: an antiderivative of excos⁡xe^x\cos x is [D]−1⋅(1,0)[D]^{-1} \cdot (1, 0).

python · try it yourself
from sympy import symbols, exp, cos, sin, Matrix, integrate, simplify

x = symbols("x")
b1, b2 = exp(x) * cos(x), exp(x) * sin(x)
M = Matrix([[1, 1], [-1, 1]])                       # [D] in the basis b1, b2
print("check columns:", simplify(b1.diff(x) - (b1 - b2)) == 0, simplify(b2.diff(x) - (b1 + b2)) == 0)
c = M.inv() * Matrix([1, 0])                        # coordinates of an antiderivative of b1
F = c[0] * b1 + c[1] * b2
print("M^-1 (1, 0) =", list(c))
print("antiderivative:", F)
print("SymPy integrate:", integrate(b1, x))
check columns: True True
M^-1 (1, 0) = [1/2, 1/2]
antiderivative: exp(x)*sin(x)/2 + exp(x)*cos(x)/2
SymPy integrate: exp(x)*sin(x)/2 + exp(x)*cos(x)/2

No integration by parts needed: a 2×22 \times 2 inverse did the work.

In software

  • Spectral methods: numerical PDE solvers store functions by coefficients in a basis (Fourier, Chebyshev) and apply differentiation as a matrix; in the Fourier basis it is diagonal, multiplying mode kk by ikik.
  • Finite differences: on a grid, the derivative becomes a banded matrix like [−110⋯0−11⋯⋮⋱]/h\begin{bmatrix} -1 & 1 & 0 & \cdots \\ 0 & -1 & 1 & \cdots \\ \vdots & & & \ddots \end{bmatrix} / h, the discrete cousin of [D][D].
  • Graphics: the same rotation has different matrices in world space and in an object's local space; converting between them is P−1APP^{-1}AP (3D Graphics: Transform Pipelines).
  • Symbolic algebra: computer algebra systems differentiate and integrate certain function families (polynomials times exponentials, for instance) by exactly this linear algebra.

Exercises

Exercise 1: The shift on P2P_2

Find the matrix of S(p)(x)=p(x+1)S(p)(x) = p(x + 1) on P2P_2 in the basis 1,x,x21, x, x^2, and use it to compute S(2−x+3x2)S(2 - x + 3x^2).

Answer

[S]=[111012001][S] = \begin{bmatrix} 1 & 1 & 1 \\ 0 & 1 & 2 \\ 0 & 0 & 1 \end{bmatrix}; S(2−x+3x2)=4+5x+3x2S(2 - x + 3x^2) = 4 + 5x + 3x^2.

Solution
S(1)=1→(1,0,0)S(x)=x+1→(1,1,0)S(x2)=x2+2x+1→(1,2,1)[S]⋅(2,−1,3)=(2−1+3,−1+6,3)=(4,5,3)check: 2−(x+1)+3(x+1)2=2−x−1+3x2+6x+3=4+5x+3x2✓\begin{aligned} S(1) &= 1 && \to (1, 0, 0) \\ S(x) &= x + 1 && \to (1, 1, 0) \\ S(x^2) &= x^2 + 2x + 1 && \to (1, 2, 1) \\ [S] \cdot (2, -1, 3) &= (2 - 1 + 3, -1 + 6, 3) = (4, 5, 3) \\ \text{check: } 2 - (x + 1) + 3(x + 1)^2 &= 2 - x - 1 + 3x^2 + 6x + 3 = 4 + 5x + 3x^2 \quad \checkmark \end{aligned}

The columns are rows of Pascal's triangle.

Exercise 2: The transpose map

Find the matrix of T(A)=ATT(A) = A^T on M2×2M_{2 \times 2} in the basis E11,E12,E21,E22E_{11}, E_{12}, E_{21}, E_{22}, and its eigenvalues.

Answer

[T]=[1000001001000001][T] = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}; eigenvalue 1 (symmetric matrices, multiplicity 3) and −1-1 (skew-symmetric matrices, multiplicity 1).

Solution

TT fixes E11E_{11} and E22E_{22} and swaps E12↔E21E_{12} \leftrightarrow E_{21}, so the matrix is a permutation matrix. AT=AA^T = A for the 3-dimensional space of symmetric matrices (λ=1\lambda = 1) and AT=−AA^T = -A for the 1-dimensional space spanned by E12−E21E_{12} - E_{21} (λ=−1\lambda = -1). Trace 1+0+0+1=2=1+1+1−11 + 0 + 0 + 1 = 2 = 1 + 1 + 1 - 1 ✓\checkmark.

Exercise 3: A Jordan block

Find the matrix of DD on span⁡{ex,xex}\operatorname{span}\{e^x, xe^x\} and use it to differentiate 3ex−2xex3e^x - 2xe^x.

Answer

[D]=[1101][D] = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}; D(3ex−2xex)=ex−2xexD(3e^x - 2xe^x) = e^x - 2xe^x.

Solution
D(ex)=ex→(1,0)D(xex)=ex+xex→(1,1)[1101]⋅(3,−2)=(3−2,−2)=(1,−2)→ex−2xex\begin{aligned} D(e^x) &= e^x && \to (1, 0) \\ D(xe^x) &= e^x + xe^x && \to (1, 1) \\ \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} \cdot (3, -2) &= (3 - 2, -2) = (1, -2) && \to \quad e^x - 2xe^x \end{aligned}

This is the shear matrix: eigenvalue 1 twice with a single eigenvector exe^x, so DD is not diagonalizable on this space, which is why xexxe^x appears in solutions of y′′−2y′+y=0y'' - 2y' + y = 0.

Exercise 4: Change of basis

Find the matrix of DD on P2P_2 in the basis 1,x,x2/21, x, x^2/2, directly and as P−1[D]PP^{-1}[D]P.

Answer

[010001000]\begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix}.

Solution

Directly: D(1)=0D(1) = 0, D(x)=1D(x) = 1, D(x2/2)=xD(x^2/2) = x, which is the second basis vector. So each basis vector goes to the previous one: a pure shift matrix. With P=diag⁡(1,1,12)P = \operatorname{diag}(1, 1, \frac{1}{2}) (the new basis in old coordinates):

python · try it yourself
from sympy import Matrix, diag, Rational

D = Matrix([[0, 1, 0], [0, 0, 2], [0, 0, 0]])     # basis 1, x, x^2
P = diag(1, 1, Rational(1, 2))                     # columns: 1, x, x^2/2 in that basis
print((P.inv() * D * P).tolist())
[[0, 1, 0], [0, 0, 1], [0, 0, 0]]

Test yourself

What is column jj of the matrix of TT with respect to bases BB and CC?

  1. The BB-coordinates of vj\mathbf{v}_j
  2. The CC-coordinates of T(vj)T(\mathbf{v}_j)
  3. The jj-th row of TT
  4. The eigenvector for λj\lambda_j

The matrix of DD on P3P_3 (basis 1,x,x2,x31, x, x^2, x^3) satisfies [D]4=0[D]^4 = 0. What does that mean in calculus terms?

  1. Every cubic has four roots
  2. The fourth derivative of every polynomial of degree ≤3\le 3 is zero
  3. DD is invertible
  4. Integration is impossible

In the basis excos⁡x,exsin⁡xe^x\cos x, e^x\sin x, the derivative has matrix [11−11]\begin{bmatrix} 1 & 1 \\ -1 & 1 \end{bmatrix}. What are its eigenvalues?

  1. 1 and 1
  2. 0 and 2
  3. 1+i1 + i and 1−i1 - i
  4. ii and −i-i