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 be linear, a basis of and a basis of . The matrix of with respect to and is the matrix
Column holds the -coordinates of the image of the -th basis vector. By Linear Transformations Defined on a Basis those images determine , and indeed
To apply : take coordinates, multiply by the matrix, read the result as coordinates. For , with standard bases this is the familiar matrix of The Matrix of a Linear Transformation in .
The derivative as a matrix
Take on with the basis for both input and output. The images of the basis vectors are
Differentiating is now , i.e. . A helper that builds the matrix of any linear map on polynomials from a basis makes this mechanical:
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. because the fourth derivative of a cubic is 0: is nilpotent. Its only eigenvalue is 0, with only the constants as eigenvectors ( has no nonzero polynomial solution for ), so is not diagonalizable (Diagonalization). The rank is 3 and the nullity 1, as rank–nullity requires.
Composition is multiplication
If and , then (with matching bases). For example, the integral has a matrix, and on while on , exactly as in The Algebra of Linear Transformations:
The zero in the corner of is the lost constant term.
A different basis, a different matrix
The same map has different matrices in different bases. For with basis , and another basis whose vectors have -coordinates in the columns of ,
so the two matrices are similar and share eigenvalues, trace, determinant and rank. Picking the basis well can make the matrix very simple. Let act on :
This is a rotation-scaling matrix with eigenvalues , matching (Complex Eigenvalues and Eigenvectors). And because it is invertible, integration is the inverse matrix: an antiderivative of is .
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 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 by .
- Finite differences: on a grid, the derivative becomes a banded matrix like , the discrete cousin of .
- Graphics: the same rotation has different matrices in world space and in an object's local space; converting between them is (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
Find the matrix of on in the basis , and use it to compute .
Answer
; .
Solution
The columns are rows of Pascal's triangle.
Exercise 2: The transpose map
Find the matrix of on in the basis , and its eigenvalues.
Answer
; eigenvalue 1 (symmetric matrices, multiplicity 3) and (skew-symmetric matrices, multiplicity 1).
Solution
fixes and and swaps , so the matrix is a permutation matrix. for the 3-dimensional space of symmetric matrices () and for the 1-dimensional space spanned by (). Trace .
Exercise 3: A Jordan block
Find the matrix of on and use it to differentiate .
Answer
; .
Solution
This is the shear matrix: eigenvalue 1 twice with a single eigenvector , so is not diagonalizable on this space, which is why appears in solutions of .
Exercise 4: Change of basis
Find the matrix of on in the basis , directly and as .
Answer
.
Solution
Directly: , , , which is the second basis vector. So each basis vector goes to the previous one: a pure shift matrix. With (the new basis in old coordinates):
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 of the matrix of with respect to bases and ?
- The -coordinates of
- The -coordinates of
- The -th row of
- The eigenvector for
The matrix of on (basis ) satisfies . What does that mean in calculus terms?
- Every cubic has four roots
- The fourth derivative of every polynomial of degree is zero
- is invertible
- Integration is impossible
In the basis , the derivative has matrix . What are its eigenvalues?
- 1 and 1
- 0 and 2
- and
- and