Bisection.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 // to compile:  g++ -I. -lm Bisection.cpp<br />
00008 // to compile with debugging: g++ -g -I. -lm Bisection.cpp<br />
00009 #include "Bisection.h"
00010 #include <math.h>
00011 
00013 class secant_functor {
00014 public:
00016   double _offset;
00017   
00019   secant_functor( double offset) : _offset(offset) { }
00020 
00022   double f( double x) {
00023     return - (exp( x) - _offset);
00024   }
00025   
00026 };
00027 
00028 int main() {
00029   double x0=1.0, x1=10.0, fx0, fx1;
00030   secant_functor sf( 5);
00031 
00032   stradle_value( x0, x1, fx0, fx1, 0.0, sf, &secant_functor::f);
00033 
00034   Bisection< secant_functor, double > 
00035     foobar( 1.0, 10.0, fx0, fx1, 0.0, 1e-8, 1e-8, 100, sf, &secant_functor::f);
00036 
00037   foobar.do_iteration( true);
00038 
00039   cout << "***************************" << endl;
00040 
00041   cout << foobar.get_x_mid() << endl;
00042 
00043   return 0;
00044 }

Generated on Fri Jan 7 12:36:18 2011 for public_options by  doxygen 1.5.1