VERB_code_2.3
bisection.cpp
Go to the documentation of this file.
1 
10 #include <assert.h>
11 #include <math.h>
12 #include "bisection.h"
13 
22 double bisection (double (*f)(double x, double Alpha), double Alpha, double x0, double x1, double eps) {
23 
24  // assert... some sort of checking and notifiyng
25  assert(x0 < x1);
26 
27  double x;
28  do {
29 
30  x = (x0 + x1) / 2;
31  double y0 = f(x0, Alpha), yy = f(x, Alpha);
32 
33  if (yy * y0 < 0) x1 = x;
34  else
35  if (yy * y0 > 0) x0 = x;
36  else
37  return x;
38 
39  } while (fabs(x1 - x0) > eps);
40 
41  return x;
42 
43 }
double bisection(double(*f)(double x, double Alpha), double Alpha, double x0, double x1, double eps)
Looking for roots of function f for given Alpha on the interval x0-x1.
Definition: bisection.cpp:22