# Orthogonale Diagonalisierung

• Gegeben: Matrix $A \in M( n \times n)$
• Gesucht: Diagonalisierende Matrix $Q$ sodass $Q^T A Q = D$ wobei $D$ die Eigenwerte von A in der Hauptdiagonale enthält


In [9]:

# input:
A = matrix([
[1, -1, 2],
[-1, 1, 2],
[2, 2, -2]
])
#




In [10]:

V = []
EW = []
i = 0
for x in A.eigenvectors_left():
for y in x[1]:
EW.append(x[0])
show(LatexExpr(r"\lambda_{} = ".format(i)), x[0])
V.append(vector([val for val in y]))
show(LatexExpr(r"v_{} = ".format(i)), y)
i += 1




\newcommand{\Bold}[1]{\mathbf{#1}}\lambda_0 =  -4

\newcommand{\Bold}[1]{\mathbf{#1}}v_0 =  \left(1,\,1,\,-2\right)

\newcommand{\Bold}[1]{\mathbf{#1}}\lambda_1 =  2

\newcommand{\Bold}[1]{\mathbf{#1}}v_1 =  \left(1,\,0,\,\frac{1}{2}\right)

\newcommand{\Bold}[1]{\mathbf{#1}}\lambda_1 =  2

\newcommand{\Bold}[1]{\mathbf{#1}}v_1 =  \left(0,\,1,\,\frac{1}{2}\right)




In [11]:

# optional input: EW, V if chosen in different order
#EW = []
V = [
vector([-1, -1, 2]),
vector([2,0,1]),
vector([-1,1,0]),
]



Orthonormalisieren mit Gram-Schmidt Verfahren

$$w_1 = \frac{1}{\| v_1 \|} v_1$$$$u_i = v_i - \sum_{k=1}^{i-1} \langle v_i, w_k \rangle w_k$$$$w_i = \frac{1}{\| u_i \|} u_i$$


In [12]:

W = []
U = []
W.append((1/(V[0].norm())) * V[0])
show(LatexExpr("v_0 ="), V[0])
show(LatexExpr("w_0 ="), W[0])
print
for i, v in enumerate(V[1:]):
show(LatexExpr("v_{} =".format(i+1)), v)
s = sum([(v.dot_product(w) * w) for w in W])
u = v - s
show(LatexExpr("u_{} =".format(i+1)), u)
U.append(u)
w = (1/u.norm()) * u
show(LatexExpr("w_{} =".format(i+1)), w)
W.append(w)
print




\newcommand{\Bold}[1]{\mathbf{#1}}v_0 = \left(-1,\,-1,\,2\right)

\newcommand{\Bold}[1]{\mathbf{#1}}w_0 = \left(-\frac{1}{6} \, \sqrt{6},\,-\frac{1}{6} \, \sqrt{6},\,\frac{1}{3} \, \sqrt{6}\right)

\newcommand{\Bold}[1]{\mathbf{#1}}v_1 = \left(2,\,0,\,1\right)

\newcommand{\Bold}[1]{\mathbf{#1}}u_1 = \left(2,\,0,\,1\right)

\newcommand{\Bold}[1]{\mathbf{#1}}w_1 = \left(\frac{2}{5} \, \sqrt{5},\,0,\,\frac{1}{5} \, \sqrt{5}\right)

\newcommand{\Bold}[1]{\mathbf{#1}}v_2 = \left(-1,\,1,\,0\right)

\newcommand{\Bold}[1]{\mathbf{#1}}u_2 = \left(-\frac{1}{5},\,1,\,\frac{2}{5}\right)

\newcommand{\Bold}[1]{\mathbf{#1}}w_2 = \left(-\frac{1}{6} \, \sqrt{\frac{6}{5}},\,\frac{5}{6} \, \sqrt{\frac{6}{5}},\,\frac{1}{3} \, \sqrt{\frac{6}{5}}\right)




In [13]:

Q = matrix(W).T
show(Q)




\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr}
-\frac{1}{6} \, \sqrt{6} & \frac{2}{5} \, \sqrt{5} & -\frac{1}{6} \, \sqrt{\frac{6}{5}} \\
-\frac{1}{6} \, \sqrt{6} & 0 & \frac{5}{6} \, \sqrt{\frac{6}{5}} \\
\frac{1}{3} \, \sqrt{6} & \frac{1}{5} \, \sqrt{5} & \frac{1}{3} \, \sqrt{\frac{6}{5}}
\end{array}\right)




In [14]:

D = Q.T * A *Q
show(D)




\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr}
-4 & 0 & 0 \\
0 & 2 & 0 \\
0 & 0 & 2
\end{array}\right)




In [15]:

assert D.ncols() == D.nrows(), "not a n x n matrix!"
for i in range(D.ncols()):
assert D[i,i] == EW[i], "D[{1},{1}] != EW[{1}]".format(i)