added some exercises
This commit is contained in:
parent
778fb469ee
commit
0c62b308cc
20
ex_41.py
Normal file
20
ex_41.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
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)))
|
25
ex_42.py
Normal file
25
ex_42.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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, 0, 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()
|
||||||
|
|
||||||
|
for k in range(1, 21):
|
||||||
|
print("some kind of error for k =", k, ":", some_norm(A**k - l_max**k * np.outer(v_max, v_max.T)))
|
||||||
|
|
||||||
|
|
15
ex_43.py
Normal file
15
ex_43.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
P = np.array(
|
||||||
|
[ [1/6, 1/6, 1/6, 1/6, 1/6, 0]
|
||||||
|
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
|
||||||
|
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
|
||||||
|
, [1/6, 1/6, 1/6, 1/6, 1/6, 0]
|
||||||
|
, [1/6, 1/6, 1/6, 1/6, 1/6, 1/10]
|
||||||
|
, [1/6, 1/6, 1/6, 1/6, 1/6, 9/10]])
|
||||||
|
print(P.shape)
|
||||||
|
|
||||||
|
v = np.array([0, 1, 0, 0, 0, 0])
|
||||||
|
w = np.power(np.dot(P**4, v), 1/4)
|
||||||
|
print(w)
|
||||||
|
print(w[-1])
|
Loading…
Reference in New Issue
Block a user