Section B.3 Diagonal form
In this example we apply the diagonalization procedure to a 3 \times 3
\begin{equation*}
A = \begin{bmatrix} 7 \amp -12 \amp -4 \\ 4 \amp -9 \amp -4 \\ -4 \amp 12 \amp 7 \end{bmatrix} \text{.}
\end{equation*}
xxxxxxxxxx
A = matrix( [ [7,-12,-4], [4,-9,-4], [-4,12,7] ] )
print(A)
Eigenvalues.
We can calculate the characteristic polynomial ourselves.xxxxxxxxxx
xA = x*identity_matrix(3) - A
print(xA)
print()
xA.det().factor()
xxxxxxxxxx
A.charpoly().factor()
xxxxxxxxxx
A.eigenvalues()
Eigenvectors.
Let's analyze \lambda = 3\text{,} since this eigenvalue had algebraic multiplicity 2\text{.} We also need geometric multiplicity 2 in order for matrix A to be diagonalizable; if this geometric multiplicity is only 1\text{,} then analyzing \lambda = -1 would be a waste of time.xxxxxxxxxx
C = 3 * identity_matrix(3) - A
print(C)
print()
C.rref()
\begin{align*}
\uvec{p}_1 \amp = (3,1,0) \text{,} \amp \uvec{p}_2 \amp = (1,0,1) \text{.}
\end{align*}
xxxxxxxxxx
p1 = vector((3,1,0))
p2 = vector((1,0,1))
print(p1,p2)
print(A*p1,A*p2)
xxxxxxxxxx
C = -1 * identity_matrix(3) - A
print(C)
print()
C.rref()
xxxxxxxxxx
p3 = vector((-1,-1,1))
print(p3)
A*p3
The transition matrix.
We now have our basis of independent eigenvectors to form the transition matrix P\text{.}xxxxxxxxxx
P = column_matrix( [ p1, p2, p3 ] )
print(P)
print()
print("rank is", P.rank())
The diagonal matrix.
Let's compute \inv{P} A P in two different ways. First, directly.xxxxxxxxxx
P.inverse() * A * P
xxxxxxxxxx
Q = column_matrix([p3, p1, p2])
Q.inverse() * A * Q
\begin{equation*}
\left[\begin{array}{c|c} P \amp AP \end{array}\right] \qquad \rowredarrow \qquad
\left[\begin{array}{c|c} I \amp \inv{P}(AP) \end{array}\right]
\end{equation*}
xxxxxxxxxx
P_AP = P.augment(A*P)
print(P_AP)
print()
I_iPAP = P_AP.rref()
print(I_iPAP)
xxxxxxxxxx
D = I_iPAP[:,3:6]
print(D)
:
says βtake all rows.β The second list-range specifier 3:6
says βtake columns with index starting at 3 and ending before 6.β Remember that Python uses 0-based indexing, so the column with index 3 is actually the fourth column. And the last column has index 5, so we want to stop before 6 to include it.