Diagonalización de matrices simétricas por semejanza ortogonal

Para ilustrar cómo diagonalizar matrices simétricas por semejanza ortogonal, vamos a usar el Ejemplo 9 (Capítulo IV) de [L. Merino, E. Santos Álgebra Lineal con Métodos Elementales].

Ejemplo

Encuentra una matriz ortogonal \(P\) tal que \(P^tAP\) sea diagonal, con \[ A=\begin{pmatrix}3 & 1 & 1\\ 1 & 3 & 1\\ 1 & 1 & 3 \end{pmatrix}. \]

from sympy import Matrix,eye,GramSchmidt
A=Matrix([(3,1,1),(1,3,1),(1,1,3)])
A

\(\displaystyle \left[\begin{matrix}3 & 1 & 1\\1 & 3 & 1\\1 & 1 & 3\end{matrix}\right]\)

Vamos a calcular los autovalores y los subespacios propios asociados.

A.charpoly().all_roots()
[2, 2, 5]
V2=(A-2*eye(3)).nullspace()
V2
[Matrix([
 [-1],
 [ 1],
 [ 0]]),
 Matrix([
 [-1],
 [ 0],
 [ 1]])]

Usamos GramSchmidt para calcular una base ortonormal de V2.

V2o=GramSchmidt(V2,True)
V2o
[Matrix([
 [-sqrt(2)/2],
 [ sqrt(2)/2],
 [         0]]),
 Matrix([
 [-sqrt(6)/6],
 [-sqrt(6)/6],
 [ sqrt(6)/3]])]

Ahora procedemos con el valor propio 5.

V5=(A-5*eye(3)).nullspace()
V5o=GramSchmidt(V5,True)
V5o
[Matrix([
 [sqrt(3)/3],
 [sqrt(3)/3],
 [sqrt(3)/3]])]

Juntamos las bases y creamos la matrix de paso P.

P=Matrix.hstack(*(V2o+V5o))
P

\(\displaystyle \left[\begin{matrix}- \frac{\sqrt{2}}{2} & - \frac{\sqrt{6}}{6} & \frac{\sqrt{3}}{3}\\\frac{\sqrt{2}}{2} & - \frac{\sqrt{6}}{6} & \frac{\sqrt{3}}{3}\\0 & \frac{\sqrt{6}}{3} & \frac{\sqrt{3}}{3}\end{matrix}\right]\)

P.T*A*P

\(\displaystyle \left[\begin{matrix}2 & 0 & 0\\0 & 2 & 0\\0 & 0 & 5\end{matrix}\right]\)