22 double x1, x2, wert_min, wert_max;
31 NoRoot1d(
double x_min,
double x_max,
double wert_min,
double wert_max): x1(x_min), x2(x_max), wert_min(wert_min), wert_max(wert_max){}
36 std::cerr <<
"Between " <<x1<<
"/"<<wert_min <<
" and "<<x2<<
"/"<<wert_max<<
" is no root!\n";
41 char const*
what()
const throw(){
return "There is no root!";}
63template <
typename UnaryOp>
64int bisection1d (UnaryOp& op,
double& x_min,
double& x_max,
const double eps)
67 double wert_max, wert_mitte, wert_min;
71 if(wert_max*wert_min>=0)
72 throw NoRoot1d(x_min, x_max, wert_min, wert_max);
75 for(
int j=0; j<j_max; j++)
77 wert_mitte = op( mitte =(x_min+x_max)/2.0 );
78 if(wert_mitte==0) {x_min=x_max=mitte;
return j+3;}
79 else if(wert_mitte*wert_max>0) x_max = mitte;
81 if( fabs(x_max-x_min)<eps*fabs(x_max) + eps)
return j+3;
83 throw std::runtime_error(
"Too many steps in root finding!");
Exception class, that stores boundaries for 1D root finding.
Definition: nullstelle.h:20
char const * what() const
what string
Definition: nullstelle.h:41
NoRoot1d(double x_min, double x_max, double wert_min, double wert_max)
construct
Definition: nullstelle.h:31
void display() const
display left and right boundary on std::cerr
Definition: nullstelle.h:34
Error classes or the dg library.
int bisection1d(UnaryOp &op, double &x_min, double &x_max, const double eps)
Find a root of a 1d function .
Definition: nullstelle.h:64
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...