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
26
void Jacobi(vector <vector<double>> A, vector<double> B, vector<double> &X, double eps, int n)
{
int flag = 1;
vector<double> temp(n, 0);
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])) <= eps) flag = 0;
X[h] = temp[h];
}
} while (flag);
temp.clear();
}