It is required to write a search function for the root of an equation on an interval using simple iterations with a given accuracy. The equation . I found the interval, [1; 2] [1; 2] . The problem is my misunderstanding of the essence of the method itself. It is necessary to express the function as x = fi(x) - how to do it in general? Well, the implementation of this algorithm in C ++ is interesting, at least a similar example.

  • Formulas look good when styled as a code. Ctrl + K or manually backtick (`) on both sides. - Nick Volynkin
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

For a long time to tell the theory, read it yourself. In general, if there is an equation x = f(x) , and at the same time near the root (or rather, where we will work) the derivative f(x) was less than unity modulo, then just another approximation is obtained as a function value from the previous one.

In your case, you can bring to mind

 x = (1/(4*ln(x))-1)^2 

or

 x = e^(1/(4(1+sqrt(x)))) 

Check for yourself that the condition is satisfied in the second case. I note casually that there is an option when the convergence condition is simply not fulfilled and you have to suffer, modifying functions slyly, but this is completely beyond the scope of the answer.

And then everything is as simple as a stool:

 using namespace std; inline double sq(double x) { return x*x; } const double eps = 0.00000001; int main(int argc, const char * argv[]) { double x0 = 1.5, // Начальное приближение x1 = 2; for(;;) { x1 = exp(1.0/(4.0*(1+sqrt(x0)))); if (fabs(x1 - x0) < eps) break; x0 = x1; } cout << x1 << endl; }