1 /* 2 To use the bissection solver to find the root of a scalar function 3 when the secant solver fails. 4 (the parametric object E must have public function such as E->f(x), 5 where x is the point at which evaluate f.) 6 1- construct the solver : solver = new bissect<E>(); 7 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are the interval's bounds 8 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed 9 */ 10 #ifndef BISSECTION_H 11 #define BISSECTION_H 12 13 #include "defines.hpp" 14 using namespace std; 15 16 template <class E> 17 class bissection { 18 private: 19 double x1, xm, x2; 20 double f1, fm, f2; 21 int i; 22 bool OK; 23 E *unit; 24 25 public: bissection()26 bissection(){x1=xm=x2=f1=fm=f2=0; OK=false;} set(E * tmp,double xx1,double xx2)27 void set(E* tmp, double xx1, double xx2) {unit=tmp; x1=xx1; x2=xx2;} 28 bool run(); ~bissection()29 ~bissection(){} 30 }; 31 #endif 32