Two by Two Matrix Jacobians
This notebook emphasizes the multiple views of Jacobians with examples of 2x2 matrix functions.
In particular we will see the
Symbolic "vec" format producing 4x4 matrices (generally n² by n² or mn by mn)
Numerical formats
The important Linear Transformation view
Kronecker notation
An example using ForwardDiff automatic differentiation
We also emphasize that matrix factorizations are also matrix functions, just as much as the square and the cube.
Symbolic Matrices
vec
The vec
command in Julia and in standard mathematics flattens a matrix column by column.
1) The matrix square function
Symbolic Jacobian
The Jacobian of the (flattened) matrix function X² symbolically
jac (generic function with 1 method)
Numerical Jacobian
2×2 Matrix{Float64}:
0.00140007 0.0020001
0.00300015 0.00440022
Linear Transformation Jacobian
Notice: there is no flattening; this is just matrix to matrix.
linear_transformation (generic function with 1 method)
2×2 Matrix{Float64}:
0.0014 0.002
0.003 0.0044
Kronecker product or ⊗ notation
Notation that kind of lets you think "flattened" or "not flattened" at the same time
Notice all possible products with the first matrix and the second
It is very reasonable to express the Jacobian of the matrix square function as
Key Kronecker identity
(A ⊗ B) * vec(C) = vec(BCAᵀ)
true
25×25 Matrix{Float64}:
0.0012953 0.166326 0.0562614 0.0499152 … 0.184296 0.163508 0.589165
0.143089 0.0619388 0.0722452 0.192885 0.236655 0.631837 0.727104
0.0310261 0.214501 0.0969148 0.0296121 0.317465 0.0970006 0.520203
0.0162279 0.136538 0.138209 0.0550643 0.452734 0.180375 0.0318315
0.0896786 0.0640814 0.0263767 0.0670469 0.0864026 0.219626 0.577041
0.000992756 0.127477 0.0431203 0.0382564 … 0.0449995 0.0399237 0.143856
0.109667 0.0474716 0.0553708 0.147833 0.0577839 0.154276 0.177537
⋮ ⋱
0.134359 0.0960087 0.0395185 0.100452 0.104482 0.265582 0.697785
0.00143673 0.184485 0.0624041 0.0553651 … 0.200821 0.178169 0.641993
0.158711 0.0687014 0.0801332 0.213945 0.257875 0.688491 0.792301
0.0344136 0.237921 0.107496 0.0328452 0.345931 0.105698 0.566848
0.0179997 0.151445 0.1533 0.0610763 0.493329 0.196548 0.0346857
0.09947 0.0710779 0.0292566 0.0743673 0.09415 0.239319 0.628782
Useful Krockecker identities
,
is orthogonal if
and are orthogonalIf
, and , then if , then , and also . Therefore and have the same eigenvalues, and transposed eigenvectors.
(See Wikipedia for more properties. )
The Jacobian in Kronecker notation
You see (I⊗X + X'⊗I) vec(dX) = vec(XdX + dX X) = vec( d(X²))
showing that d(X²) = (I⊗X + X'⊗I) dX.
(I feel it's okay to drop the "vec" and think of the kronecker notation as defining the linear operator from matrices to matrices)
Do look this over.
Automatic Differentiation (is not finite differences nor symbolic)
It comes in forward and reverse modes. Let's try forward.
4×4 Matrix{Int64}:
2 2 3 0
3 5 0 3
2 0 5 2
0 2 3 8
2) The matrix cube Function
Symbolic Jacobian
The Jacobian of the (flattened) matrix function X² symbolically
LinearTransformation Jacobian
dX X² + X dX X + dX X²
with numerical data:
#7 (generic function with 1 method)
2×2 Matrix{Float64}:
0.0111011 0.0162016
0.0243024 0.0354035
2×2 Matrix{Float64}:
0.0111 0.0162
0.0243 0.0354
check against the symbolic answer
The Jacobian in Kronecker Notation
3) The LU Decomposition
Recall the LU Decomposition factors a matrix into unit lower-trianguar and upper triangular:
The four entries of X: p,q,r,s are transformed into these four entries in LU:
Exercise: Relate this to d(LU) = dL U + L dU
4) Traceless symmetric eigenproblem: an example with two parameters not four
We know that the eigenvalues add to 0 (from the trace) and the eigenvectors are orthogonal (from being symmetric), so we can represent the eigenvectors and eigenvalues:
The relationship between θ,r to p,s:
Interesting mathematical observation: these are the formulas you may remember from other classes that relate cartesian coordinates to polar coordinates in the plane.
Mathematical aside det J=r , this is the change of variables from x,y to r,θ that you may have seen in 18.02. This eigenvalue problem is the same as the cartesian coordinates to polar representations of the plane. Often written dx dy = r dr dθ
5) The full 2x2 symmetric eigenproblem
We think of
as the function from
S = QΛQ':
The determinant of this transformation simplifies to