static void SimpleIteration Mtr Mtr int getRows Mtr new Mtr Mtr new Mt

 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
32
33
34
35
static void SimpleIteration(Mtr A, Mtr b)
{
int n = A.getRows();
Mtr B = new Mtr(n, n);
Mtr C = new Mtr(n, 1);
Mtr X = new Mtr(n, 1);
decimal EPS = 0.0001m;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (i == j)
continue;
B.setValue(-A.getValue(i, j) / A.getValue(i, i), i, j);
}
C.setValue(b.getValue(i, 0) / A.getValue(i, i), i, 0);
X.setValue(1, i, 0);
}
Mtr oldX = new Mtr(n, 1);
for (int i = 0; i < n; ++i) oldX.setValue(100, i, 0);
for (int i = 0; i < 100; ++i)
{
X = B * X + C;
if (getNorm(X - oldX) < EPS)
break;
oldX = X;
}
Console.WriteLine("Метод простой итерации:");
X.printMatrix();
Console.WriteLine("-------------------------------------");
}