Two by Two Matrix Jacobians
md"""
# 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.
md"""
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.
"""
using Symbolics , LinearAlgebra , PlutoUI
TableOfContents(title="Two by Two Matrix Jacobians", indent=true,aside=true)
Symbolic Matrices
md"""
# Symbolic Matrices
"""
@variables p,q,r,s,θ
simplify.( Q*[r 0 ; 0 -r]*Q' )
X = [p r;q s]
vec
The vec
command in Julia and in standard mathematics flattens a matrix column by column.
md"""
## vec
The `vec` command in Julia and in standard mathematics flattens a matrix column by column.
"""
vec(X)
1) The matrix square function
md"""
# 1) The matrix square function
"""
X^2
vec(X^2)
Symbolic Jacobian
The Jacobian of the (flattened) matrix function X² symbolically
md"""
## Symbolic Jacobian
The Jacobian of the (flattened) matrix function X² symbolically
"""
jac (generic function with 1 method)
jac(Y,X) = Symbolics.jacobian(vec(Y),vec(X))
J = jac(X^2, X)
Numerical Jacobian
md"""
## Numerical Jacobian
"""
begin
M = [1 2;3 4]
E = [.0001 .0002;.0003 .0004]
substitute(J,Dict(p=>1,q=>3,r=>2,s=>4))
end
substitute(J,Dict(p=>1,q=>3,r=>2,s=>4)) * vec(E)
2×2 Matrix{Float64}:
0.00140007 0.0020001
0.00300015 0.00440022
(M+E)^2 - M^2
Linear Transformation Jacobian
Notice: there is no flattening; this is just matrix to matrix.
md"""
## Linear Transformation Jacobian
Notice: there is no flattening; this is just matrix to matrix.
"""