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



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






In [13]:
Q = matrix(W).T
show(Q)



In [14]:
D = Q.T * A *Q
show(D)



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)