void Jacobi vector vector double vector double vector double double ep

 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
void Jacobi(vector <vector <double>> A, vector <double> B, vector <double> &X, double eps, int N)
{
vector <double> temp;
double norm;
do{
for (int i = 0; i < N; i++)
{
temp[i] = B[i];
for (int g = 0; g < N; g++)
{
if (i != g)
temp[i] -= A[i][g] * X[g];
}
temp[i] /= A[i][i];
}
norm = fabs(X[0] - temp[0]);
for (int h = 0; h < N; h++)
{
if (fabs(X[h] - temp[h]) > norm)
norm = fabs(X[h] - temp[h]);
X[h] = temp[h];
}
} while (norm > eps);
}