According to my function, this method should count the zero of the function = 3.75, but it counts only 3, and at any intervals. Function: f(x)=(x - 48) * (x - 48) + (sin (x - 48)) Here is the graph of the function: alt text

Algorithm code:

 double f4(double x) { return ((1/8) * (sin (x - (30/8))) + (30/8)); } double iter(double a, double b, double eps) { int k=0; double x0,xk; x0=(a+b)/2; do { xk=f4(x0); if (fabs(xk-x0)<eps) break; else x0=xk; } while (fabs(a-x0)>eps && fabs(b-x0)>eps); cout << "Ноль функции = "<<xk<<"\n"; return xk; } 
  • Perhaps this will help you: neerc.ifmo.ru/mediawiki/index.php/ Real binary search - andrybak
  • What does the f4 () function do? - andrybak
  • f4 () added code - gvenog
  • this is not a search, here you need to find the zero function, I read about the algorithm of iterations, but some φ (x) is used there: "To apply this method, the original equation f (x) = 0 should be reduced to the form x = φ (x ) "I watched here: intuit.ru/department/calculate/intromathmodel/4/2.html - gvenog

1 answer 1

Due to the fact that you have all the constants integer in the f4 function, it always returns 3. It would be correct like this:

 double f4(double x) { return ((1.0/8.0) * (sin (x - (30.0/8.0))) + (30.0/8.0)); } 

and even better:

 double f4(double x) { return 0.125 * sin(x - 3.75) + 3.75; } 
  • Thank! Everything worked out. - gvenog