Для записки к 4 лабе чмы

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
double NewtonMethod(double x) {
int n = 0;
while (abs(function(x)) > eps) {
n++;
x -= function(x) / derivative(x);
}
cout << "\tsteps = " << n << endl;
return x;
}
double BinarySearch(double left, double right) {
int n = 0;
while (abs(right - left) > eps) {
n++;
double mid = (left + right) / 2.0;
(sign(function(left)) != sign(function(mid))) ? right = mid: left = mid;
}
cout << "\tsteps = " << n << endl;
return (left + right) / 2.0;
}