# Diagonalization of 3x3 symmetric matrix

The `MassMatrix3` class uses an algorithm described in [A Method for Fast Diagonalization of a 2x2 or 3x3 Real Symmetric Matrix](http://arxiv.org/abs/1306.6291v4) by M.J. Kronenburg. This document proves that when a matrix $\textbf{A}$ has a repeated eigenvalue and the vector $\textbf{f}_2$ has length 0, then $\textbf{A}$ is a diagonal matrix.

The symmetric 3x3 matrix $\textbf{A}$ has diagonal elements $A_{11}$, $A_{22}$, and $A_{33}$ and off-diagonal terms $A_{12}$, $A_{13}$, and $A_{23}$. The vector $\textbf{f}_2$ is defined in (5.6) as

$\textbf{f}_2 = [A_{22} - A_{33}, -2A_{23}]^T$

When $\textbf{f}_2$ has length zero, the following are true:

$A_{22} = A_{33} = A$

$A_{23} = 0$

In Section 4, conditions are given for which a matrix will have at least 1 repeated eigenvalue $\lambda$ based on the coefficients of its characteristic equation:

$\lambda^3 - b \lambda^2 + c \lambda + d = 0$

With $p = b^2 - 3c$ and $q = 2b^3 - 9bc - 27d$, there is at least one repeated eigenvalue when $q^2 = 4p^3$

These conditions are manipulated symbolically below:


```
from sympy import *
```


```
# Identify condition in which there is a repeated eigenvalue (Q^2 - 4P^3 = 0)
B, C, D, P, Q = symbols('B C D P Q')
P = B**2 - 3*C
Q = 2*B**3 - 9*B*C - 27*D
simplify(expand(Q**2 - 4*P**3))
```




    -108*B**3*D - 27*B**2*C**2 + 486*B*C*D + 108*C**3 + 729*D**2



First the condition in which there is a repeated eigen value ($q^2 = 4p^3$) is expressed in terms of $b$, $c$, and $d$ and simplified to:

$-108b^3d - 27b^2c^2 + 486bcd + 108c^3 + 729d^2 = 0$


```
# Expand expression for which there is a repeated eigenvalue
A11, A12, A13, A = symbols('A11 A12 A13 A')
b, c, d = symbols('b c d')
b = A11 + 2*A
c = A11*A + A11*A + A**2 - A12**2 - A13**2
d = A*A13**2 + A*A12**2 - A11*A**2
factor(simplify(-108*b**3*d - 27*b**2*c**2 + 486*b*c*d + 108*c**3 + 729*d**2))
```




    -27*(A12**2 + A13**2)**2*(A**2 - 2*A*A11 + A11**2 + 4*A12**2 + 4*A13**2)



This condition is then expressed in terms of $A11$, $A$, $A12$, and $A13$ corresponding to $\textbf{f}_2 = 0$.
After simplification and factoring, there are 2 cases for which the expression is equal to zero:

$A_{12}^2 + A_{13}^2 = 0$

$4A_{12}^2 + 4A_{13}^2 + (A - A_{11})^2 = 0$

In both cases, $A_{12} = A_{13} = 0$ is a pre-requisite. Since $A_{23} = 0$ was already assumed, this implies that
the matrix must be diagonal if it has any repeated eigenvalues and $\textbf{f}_2 = 0$.


```

```

0e94e9603170dad747e9e965775533947a8abbe9
ipynb
Jupyter Notebook
include/ignition/math/MassMatrix3.ipynb
srmainwaring/ign-math
ff55578b52b9c42daaea666c3c1205551b07afbb
ECL-2.0 Apache-2.0
2019-08-21T20:50:05.000Z
2022-03-27T11:48:25.000Z
include/ignition/math/MassMatrix3.ipynb
srmainwaring/ign-math
ff55578b52b9c42daaea666c3c1205551b07afbb
ECL-2.0 Apache-2.0
2020-04-16T23:38:50.000Z
2022-03-31T11:11:58.000Z
include/ignition/math/MassMatrix3.ipynb
srmainwaring/ign-math
ff55578b52b9c42daaea666c3c1205551b07afbb
ECL-2.0 Apache-2.0
2020-04-15T21:15:43.000Z
2022-03-14T19:29:04.000Z
Qwen/Qwen-72B
1. YES
2. YES