You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ef08d4d
Browse filesBrowse the repository at this point in the historyBrowse files
feat(math): diagonal matrices and diagonal products (#383)
* feat(math): diagonal matrices and diagonal products
Diagonal(d) and DiagonalOf(M) convert between a vector and a diagonal
matrix. ScaleColumns(M, d) and DiagonalCongruence(d, M) compute
M diag(d) and diag(d) M diag(d) entry by entry, so applying per-joint
gains, sign conventions or unit scalings to a Jacobian or a mass matrix
costs one or two multiplications per entry instead of full matrix
products.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU
* docs(math): list the diagonal helpers in the math index
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU
---------
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: doc/math/MatrixOperations.md
+19-5Lines changed: 19 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,10 @@ Small structural matrix utilities that are needed across the library but do not
7
7
-**`Symmetrize`** enforces exact symmetry on a matrix that should be symmetric in theory but drifts under floating-point round-off.
8
8
-**`CongruenceTransform`** computes the quadratic form `A·M·Aᵀ` — the single most common shape in covariance-propagating code (Kalman predict `F·P·Fᵀ`, innovation covariance `H·P·Hᵀ`, Joseph update `(I−KH)·P·(I−KH)ᵀ`, etc.).
9
9
10
-
Both are recurring needs in Kalman filters, EM parameter updates, and Riccati/Lyapunov solvers.
10
+
-**`Diagonal`** and **`DiagonalOf`** convert between a vector and a diagonal matrix.
11
+
-**`ScaleColumns`** and **`DiagonalCongruence`** compute `M·diag(d)` and `diag(d)·M·diag(d)` without forming the diagonal matrix: per-joint gains, sign conventions and unit scalings applied to Jacobians and mass matrices.
12
+
13
+
The first two are recurring needs in Kalman filters, EM parameter updates, and Riccati/Lyapunov solvers; the diagonal products recur wherever a matrix is expressed in rescaled coordinates.
If $M$ is symmetric, `CongruenceTransform` returns a symmetric result exactly (in exact arithmetic): $(AMA^\top)^\top = A M^\top A^\top = A M A^\top$. This makes it the natural building block for propagating a covariance $P$ through a linear map $A$: $P \mapsto A P A^\top$.
21
24
25
+
With $D = \operatorname{diag}(d)$, a product with a diagonal matrix scales columns, or rows and columns, entry by entry:
so neither product needs a matrix multiplication. $D M D$ is a congruence: it keeps a symmetric $M$ symmetric, and a positive-definite $M$ positive definite when every $d_i \neq 0$.
**CongruenceTransform** — with $A \in \mathbb{R}^{n\times m}$ and symmetric $M \in \mathbb{R}^{m\times m}$, the result $A M A^\top \in \mathbb{R}^{n\times n}$ is the covariance of $A x$ when $x$ has covariance $M$.
34
46
47
+
**DiagonalCongruence** — for $d = (2, -3)$ and $M = \begin{bmatrix}1 & 3 \\ -1 & 2\end{bmatrix}$: $(DMD)_{01} = 2 \cdot 3 \cdot (-3) = -18$, $(DMD)_{10} = -3 \cdot (-1) \cdot 2 = 6$ and $(DMD)_{11} = 9 \cdot 2 = 18$, as $\operatorname{diag}(d)\,M\,\operatorname{diag}(d)$ gives with two full products.
48
+
35
49
## Pitfalls & Edge Cases
36
50
37
51
**Symmetrize is not a fix for indefiniteness** — it removes the skew part but does not make a matrix positive-definite; covariance code typically also adds a small diagonal jitter (`+ εI`) separately.
|[Step Response Metrics](StepResponseMetrics.md)| Rise time, settling time, percent overshoot, peak time, and steady-state error from a bounded step-response vector |
19
19
|[Matrix Exponential](MatrixExponential.md)| Scaling-and-squaring with diagonal (6,6) Padé approximant — exact ODE solution operator and discretisation engine |
20
20
|[Consistency Metrics](ConsistencyMetrics.md)| NEES/NIS estimator consistency with χ² gates — normalised estimation error squared and normalised innovation squared |
0 commit comments