
KP_3_Mansurov_1323
.docx```//Задание 3 вариант 28 стр 141
import numpy as np
def simple_iteration_method(A, b, x0, e):
n = len(b)
x = np.zeros(n)
x_new = np.zeros(n)
T = np.zeros((n, n))
c = np.zeros(n)
error = e + 1 # initial error value
while error > e:
for i in range(n):
sum_ = 0
for j in range(n):
if i != j:
T[i, j] = -A[i, j] / A[i, i]
sum_ += T[i, j] * x0[j]
c[i] = b[i] / A[i, i]
x_new[i] = sum_ + c[i]
error = np.sum(np.abs(x_new - x0))
x0 = np.copy(x_new)
return x0
if __name__ == "__main__":
# Given values
A = np.array([
[1.00, -0.34, -0.23, 0.06],
[-0.11, 1.23, 0.18, -0.36],
[-0.23, 0.12, 0.84, 0.35],
[-0.12, -0.12, 0.47, 0.82]
])
b = np.array([1.4200, -0.6600, 1.0800, 1.7200])
x0 = np.zeros(len(b))
e = 1e-7
solution = simple_iteration_method(A, b, x0, e)
print("Solution of the system of equations using the simple iteration method:")
for i, sol in enumerate(solution):
print(f"x{i + 1} = {sol}")