Announcements & Reminders
Congratulations with completing the first half of the course!
π
Feedback on midterm exam will be available some time next week
Quiz 3 is due next Monday, April 22 β donβt forget
Will focus on linear algebra including the last lecture before the teaching break
π Determinants, eigenpairs and diagonalization#
β± | words
Determinants#
Determinant is a fundamental characteristic of any matrix \(A\) and a linear operator given by a matrix \(A\)
Note
Determinants are only defined for square matrices, so in this section we only consider square matrices.
we use some sort of recursive definition
Definition
For a square \(2 \times 2\) matrix the determinant is given by
Notation for the determinant is either \(\det(A)\) or sometimes \(|A|\)
Example
We build the definition of the determinants of larger matrices from \(2 \times 2\) case. Think of the next definitions as a βinduction stepβ
Definition
Consider an \(n \times n\) matrix \(A\). Denote \(A_{ij}\) a \((n-1) \times (n-1)\) submatrix of \(A\), obtained by deleting the \(i\)-th row and \(j\)-th column of \(A\). Then
the \((i,j)\)-th minor of \(A\) denoted \(M_{ij}\) is
the \((i,j)\)-th cofactor of \(A\) denoted \(C_{ij}\)
cofactors are signed minors
signs alternate in checkerboard pattern
for even \(i+j\) minors and cofactors are equal
Definition
The determinant of an \(n \times n\) matrix \(A\) with elements \(\{a_{ij}\}\) is given by
for any choice of \(i\) or \(j\).
given that the cofactors are lower dimension determinants, we can use the same formula to compute determinants of matrices of all sizes
Example
Expanding along the first column:
Expanding along the top row:
We got exactly same result!
Fact
Determinant of \(3 \times 3\) matrix can be computed by the triangles rule:
Examples for quick computation
Properties of determinants#
Important facts concerning the determinants
Fact
If \(I\) is the \(N \times N\) identity, \(A\) and \(B\) are \(N \times N\) matrices and \(\alpha \in \mathbb{R}\), then
\(\det(I) = 1\)
\(\det(A) = \det(A^T)\)
\(\det(AB) = \det(A) \det(B)\)
\(\det(\alpha A) = \alpha^N \det(A)\)
\(\det(A) = 0\) if and only if columns of \(A\) are linearly dependent
\(A\) is nonsingular if and only if \(\det(A) \ne 0\)
\(\det(A^{-1}) = \frac{1}{\det(A)}\)
Example
Compute the determinant of the \((n \times n)\) matrix
Fact
If some row or column of \(A\) is added to another one after being multiplied by a scalar \(\alpha \ne 0\), then the determinant of the resulting matrix is the same as the determinant of \(A\).
Fact
Determinant operator is linear in each row or column separately:
a common factor of the elements of any row or column of \(A\) can be taken outside of the determinant operator, and
determinant of the matrix which row or column is given by a sum of conformable vectors is given by a sum of determinants of matrices with this row or column replaced by the corresponding vector
very useful in practical computation of determinant exercises!
see Problem Set \(\eta\)
Where determinants are used#
Fundamental properties of the linear operators given by the corresponding matrix
Inversion of matrices
Solving systems of linear equations (Cramerβs rule)
Finding Eigenvalues and eigenvectors (soon)
Determining positive definiteness of matrices
etc, etc.
Eigenvalues and Eigenvectors#
Let \(A\) be a square matrix
Think of \(A\) as representing a mapping \(x \mapsto A x\), this is a linear function (see prev lecture)
But sometimes \(x\) will only be scaled:
Definition
If \(A x = \lambda x\) holds and \(x\) is nonzero, then
\(x\) is called an eigenvector of \(A\) and \(\lambda\) is called an eigenvalue
\((x, \lambda)\) is called an eigenpair
Clearly \((x, \lambda)\) is an eigenpair of \(A\) \(\implies\) \((\alpha x, \lambda)\) is an eigenpair of \(A\) for any nonzero \(\alpha\)
Example
Let
Then
form an eigenpair because \(x \ne 0\) and
import numpy as np
A = [[1, 2],
[2, 1]]
eigvals, eigvecs = np.linalg.eig(A)
for i in range(eigvals.size):
x = eigvecs[:,i]
lm = eigvals[i]
print(f'Eigenpair {i}:\n{lm:.5f} --> {x}')
print(f'Check Ax=lm*x: {np.dot(A, x)} = {lm * x}')
Eigenpair 0:
3.00000 --> [0.70710678 0.70710678]
Check Ax=lm*x: [2.12132034 2.12132034] = [2.12132034 2.12132034]
Eigenpair 1:
-1.00000 --> [-0.70710678 0.70710678]
Check Ax=lm*x: [ 0.70710678 -0.70710678] = [ 0.70710678 -0.70710678]
Consider the matrix
Induces counter-clockwise rotation on any point by \(90^{\circ}\)
Hint
The rows of the matrix show where the classic basis vectors are translated to.
Hence no point \(x\) is scaled
Hence there exists no pair \(\lambda \in \mathbb{R}\) and \(x \ne 0\) such that
In other words, no real-valued eigenpairs exist. However, if we allow for complex values, then we can find eigenpairs even for this case
Eigenvalues and determinants#
Fact
For any square matrix \(A\)
Proof
Let \(A\) by \(N \times N\) and let \(I\) be the \(N \times N\) identity
We have
Example
In the \(2 \times 2\) case,
Hence the eigenvalues of \(A\) are given by the two roots of
Equivalently,
Existence of Eigenvalues#
For an \((N \times N)\) matrix \(A\) expression \(\det(A - \lambda I) = 0\) is a polynomial equation of degree \(N\) in \(\lambda\)
to see this, imagine how \(\lambda\) enters into the computation of the determinant using the definition along the first row, then first row of the first minor submatrix, and so on
the highest degree of \(\lambda\) is then the same as the dimension of \(A\)
Definition
The polynomial \(\det(A - \lambda I)\) is called a characteristic polynomial of \(A\).
The roots of the characteristic equation \(\det(A - \lambda I) = 0\) determine all eigenvalues of \(A\).
By the Fundamental theorem of algebra there are \(N\) of such (complex) roots \(\lambda_1, \ldots, \lambda_N\), and we can write
Each such \(\lambda_i\) is an eigenvalue of \(A\) because
Note: not all roots are necessarily distinct β there can be repeats
Diagonalization#
Consider a square \(N \times N\) matrix \(A\)
Definition
The \(N\) elements of the form \(a_{nn}\) are called the principal diagonal
Definition
A square matrix \(D\) is called diagonal if all entries off the principal diagonal are zero
Often written as
Diagonal matrixes are very nice to work with!
Example
Fact
If \(D = \mathrm{diag}(d_1, \ldots,d_N)\) then
\(D^k = \mathrm{diag}(d^k_1, \ldots, d^k_N)\) for any \(k \in \mathbb{N}\)
\(d_n \geq 0\) for all \(n\) \(\implies\) \(D^{1/2}\) exists and equals
\(d_n \ne 0\) for all \(n\) \(\implies\) \(D\) is nonsingular and
Example
Letβs find eigenvalues and eigenvectors of \(D = \mathrm{diag}(d_1, \ldots,d_N)\).
The characteristic polynomial is given by
Therefore the diagonal elements are the eigenvalues of \(D\)!
Change of basis#
Consider a vector \(x\in \mathbb{R}^N\) which has coordinates \((x_1,x_2,\dots,x_N)\) in classis basis \((e_1,e_2,\dots,e_N)\), where \(e_i = (0,\dots,0,1,0\dots,0)^T\)
Coordinates of a vector is what we call the coefficients of the linear combination of the basis vectors that gives the vector
We have
Consider a different basis in \(\mathbb{R}^N\) (recall the definition) denoted \((e'_1,e'_2,\dots,e'_N)\) Here we assume that each \(e'_i\) is written in the coordinates corresponding to the original basis \((e_1,e_2,\dots,e_N)\).
The coordinates of vector \(x\) in basis \((e'_1,e'_2,\dots,e'_N)\) denoted \(x' = (x'_1,x'_2,\dots,x'_N)\) are by definition
Definition
The transformation matrix from the basis \((e_1,e_2,\dots,e_N)\) to \((e'_1,e'_2,\dots,e'_N)\) is given by
In other words, the same vector has coordinates \(x = (x_1,x_2,\dots, x_N)\) in the original basis \((e_1,e_2,\dots,e_N)\) and \(x' = (x'_1,x'_2,\dots, x'_N)\) in the new basis \((e'_1,e'_2,\dots,e'_N)\), and it holds
We now have a way to represent the same vector in different bases, i.e. change basis!
Example
Fact
The transformation matrix \(P\) is nonsingular (invertible).
Proof
Because the transformation matrix maps a set of basis vectors to another set of basis vectors, they are linearly independent. By the properties of linear functions, \(P\) is then non-singular, and \(P^{-1}\) exists. \(\blacksquare\)
Linear functions in different bases#
Consider a linear map \(A: x \mapsto Ax\) where \(x \in \mathbb{R}^N\)
Can we express the same linear map in a different basis?
Let \(B\) be the matrix representing the same linear map in a new basis, where the transformation matrix is given by \(P\).
If the linear map is the same, we must have
Definition
Square matrix \(A\) is said to be similar to square matrix \(B\) if there exist an invertible matrix \(P\) such that \(A = P B P^{-1}\).
Similar matrixes also happen to be very useful!
Example
Consider \(A\) that is similar to a diagonal matrix \(D = \mathrm{diag}(d_1,\dots,d_N)\).
To find the \(A^n\) we can use the fact that
and therefore itβs easy to show by mathematical induction that
Given the properties of the diagonal matrixes, we have an easily computed expression
Diagonalization using eigenvectors#
Definition
If \(A\) is similar to a diagonal matrix, then \(A\) is called diagonalizable
Fact (Diagonalizable \(\longrightarrow\) Eigenpairs)
Let \(A\) be diagonalizable with \(A = P D P^{-1}\) and let
\(D = \mathrm{diag}(\lambda_1, \ldots, \lambda_N)\)
\(p_n\) for \(n=1,\dots,N\) be the columns of \(P\)
Then \((p_n, \lambda_n)\) is an eigenpair of \(A\) for each \(n\)
Proof
From \(A = P D P^{-1}\) we get \(A P = P D\)
Equating \(n\)-th column on each side gives
Moreover \(p_n \ne 0\) because \(P\) is invertible (which facts?)
Fact (Distinct eigenvalues \(\longrightarrow\) diagonalizable)
If \(N \times N\) matrix \(A\) has \(N\) distinct eigenvalues \(\lambda_1, \ldots, \lambda_N\), then \(A\) is diagonalizable as \(A = P D P^{-1}\) where
\(D = \mathrm{diag}(\lambda_1, \ldots, \lambda_N)\)
each \(n\)-th column of \(P\) is equal to the eigenvector for \(\lambda_n\)
Example
Let
The eigenvalues of \(A\) are 2 and 4, while the eigenvectors are
Hence
import numpy as np
from numpy.linalg import inv
A = np.array([[1, -1],
[3, 5]])
eigvals, eigvecs = np.linalg.eig(A)
D = np.diag(eigvals)
P = eigvecs
print('A =',A,sep='\n')
print('D =',D,sep='\n')
print('P =',P,sep='\n')
print('P^-1 =',inv(P),sep='\n')
print('P*D*P^-1 =',P@D@inv(P),sep='\n')
A =
[[ 1 -1]
[ 3 5]]
D =
[[2. 0.]
[0. 4.]]
P =
[[-0.70710678 0.31622777]
[ 0.70710678 -0.9486833 ]]
P^-1 =
[[-2.12132034 -0.70710678]
[-1.58113883 -1.58113883]]
P*D*P^-1 =
[[ 1. -1.]
[ 3. 5.]]
Profit!#
Fact
Given \(N \times N\) matrix \(A\) with distinct eigenvalues \(\lambda_1, \ldots, \lambda_N\) we have
If \(A = \mathrm{diag}(d_1, \ldots, d_N)\), then \(\lambda_n = d_n\) for all \(n\)
\(\det(A) = \prod_{n=1}^N \lambda_n\)
If \(A\) is symmetric, then \(\lambda_n \in \mathbb{R}\) for all \(n\) (not complex!)
Proof
The first statement can be checked directly by verifying that the classic basis vectors are eigenvectors of \(A\).
The second statement follows from the properties of the determinant of a product:
The third statement requires complex analysis, we take for granted.
Fact
\(A\) is nonsingular \(\iff\) all eigenvalues are nonzero
Proof
\(A\) is nonsingular \(\iff\) \(\det(A) \ne 0\) \(\iff\) \(\prod_{n=1}^N \lambda_n \ne 0\) \(\iff\) all \(\lambda_n \ne 0\)
Fact
If \(A\) is nonsingular, then eigenvalues of \(A^{-1}\) are \(1/\lambda_1, \ldots, 1/\lambda_N\)
Proof
Notes from the lecture#
References and reading#
References
[Simon and Blume, 1994]: chapters~9, 23 (excluding complex number)
[Sundaram, 1996]: 1.3.4-1.3.6
Further reading and self-learning
Excellent visualizations of concepts covered in this lecture, strongly recommended for further study 3Blue1Brown: Essence of linear algebra