-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_2_2.py
31 lines (22 loc) · 825 Bytes
/
lab_2_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
def min_nevyazok(A, b, max_iterations=1000, eps=1e-6):
n = len(b)
x = b
r = b - np.dot(A, x)
iterations = 0
while np.linalg.norm(r) > eps and iterations < max_iterations:
r = b - np.dot(A, x)
Ar = np.dot(A, r)
tau = np.dot(Ar, r) / np.linalg.norm(Ar) ** 2
x = x + tau * r
iterations += 1
return x, iterations
if __name__ == "__main__":
A = np.array([[0.2293, -0.1507, -0.2609, 0.3152],
[-0.1507, 0.181, 0.1595, -0.3722],
[-0.2609, 0.1595, 0.481, -0.4852],
[0.3152, -0.3722, -0.4852, 1.2625]])
b = np.array([0.4708, -0.3697, -1.193, 2.0636])
print(min_nevyazok(A, b, eps=0.01))
print(min_nevyazok(A, b, eps=0.0001))
print(min_nevyazok(A, b, eps=0.00000000001))