include iostream include vector include cmath using namespace std int

 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
//ввод матрицы
freopen("input.txt", "r", stdin);
int n;
cin >> n;
vector <vector<double> > a(n, vector <double> (n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >>a[i][j];
}
}
vector <double> b(n);
for (int i = 0; i < n; ++i) {
cin >>b[i];
}
vector <double> xOld(n);
for (int i = 0; i < n; ++i) {
cin >> xOld[i];
}
vector <double> xNew(n);
double eps = 1e-8;
double error = eps + 1.0;
//вывод матрицы
cout << "n:" << n << endl;
cout << "matr a:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << a[i][j] <<" ";
cout << endl;
}
cout << "vect b:" << endl;
for (int i; i < n; i++) {
cout << b[i] << endl;
}
cout << "zero iteration:" << endl;
for (int i; i < n; i++) {
cout << xOld[i] << endl;
}
cout << "eps:" << eps << endl;
cout << endl;
int j = 0;
for (int k = 1; error > eps; k++) {
for (int i = 0; i < n; i++) {
xNew[i] = (b[i] / a[i][i]);
for (int j = 0; j < n; j++) {
if (j == i) {
continue;
}
xNew[i] = xNew[i] - ((a[i][j] / a[i][i]) * xOld[j]);
}
}
double maxNew = xNew[0];
double maxOld = xOld[0];
for (int i = 1; i < n; ++i){
if (maxNew < xNew[i]){
maxNew = xNew[i];
}
if (maxOld < xOld[i]){
maxOld = xOld[i];
}
}
error = abs(maxNew - maxOld);
xOld = xNew;
cout << error << endl;
cout << maxNew << " " << maxOld << endl;
}
cout << "Answer:" << endl;
for (int i = 0; i < n; i++){
cout << xOld[i] << endl;
}
}