include iostream include vector include algorithm using namespace std

 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<double> Vec;
typedef vector<Vec> Matrix;
double eps = 1e-3;
double phi1(double x, double y)
{
return sqrt((x*(y + 5) - 1) / 2);
}
double phi2(double x, double y)
{
return sqrt(x + 3 * log10(x));
}
void Zeidel(Vec &x)
{
int n = x.size();
double norm = 0;
Vec xNext(n);
do
{
xNext[0] = phi1(x[0], x[1]);
xNext[1] = phi2(x[0], x[1]);
norm = 0;
for (int i = 0; i < n; ++i)
{
norm = max(fabs(xNext[i] - x[i]), norm);
}
x = xNext;
} while (norm > eps);
}
int main()
{
Vec x = {1,1};
Zeidel(x);
for (int i = 0; i < x.size(); ++i)
{
cout << x[i] << endl;
}
}