1 #include "bissection.hpp" 2 using namespace std; 3 4 template <class E> run()5bool bissection<E>::run() 6 { 7 for (i=1; i<MAX_ITER_BISSECTION; i++) 8 { 9 xm=(x1+x2)/2; 10 // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; 11 if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) 12 { 13 i=MAX_ITER_BISSECTION; 14 OK=true; 15 } 16 else 17 { 18 f1 = unit->f(x1); 19 fm = unit->f(xm); 20 f2 = unit->f(x2); 21 if (f1*fm < 0.0) x2 = xm; 22 if (fm*f2 < 0.0) x1 = xm; 23 } 24 } 25 // if (DEBUG) system("pause"); 26 return OK; 27 } 28