scientific-programming-exer.../ex_42.py

30 lines
534 B
Python

import numpy as np
A = np.array(
[ [0, 1, 1, 0, 0, 0]
, [1, 0, 1, 0, 1, 0]
, [1, 1, 0, 1, 0, 0]
, [0, 0, 1, 0, 1, 0]
, [0, 1, 0, 1, 0, 1]
, [0, 0, 0, 0, 1, 0]
])
eigvalues, eigvectors = np.linalg.eig(A)
l_max_i = eigvalues.argmax()
l_max = eigvalues[l_max_i]
v_max = eigvectors[l_max_i]
def some_norm(M):
return np.abs(M).max()
B = A
for k in range(1, 21):
B = B.dot(A)
print(B)
print(l_max**k * np.outer(v_max, v_max))
print("some kind of error for k =", k, ":", some_norm(B - l_max**k * np.outer(v_max, v_max)))