scientific-programming-exer.../ex_41.py

21 lines
439 B
Python

import numpy as np
A = np.array([ [1, 5, 1]
, [5, 0, -3]
, [1, -3, 7]])
print(np.linalg.eig(A))
O = np.linalg.eig(A)[1]
D = np.zeros((3, 3))
for i, v in enumerate(np.linalg.eig(A)[0]):
D[i][i] = v
I = np.zeros((3, 3))
for i in range(3):
I[i][i] = 1
print("(2)", np.allclose(np.dot(O.T, O), I))
print("(3)", np.allclose(A, np.dot(np.dot(O, D), O.T)))
print("(4)", np.allclose(np.dot(A, A), np.dot(np.dot(O, np.dot(D, D)), O.T)))