35#ifndef STK_ALGO_FINDZERO_H
36#define STK_ALGO_FINDZERO_H
50template <
class Function>
52template <
class Function>
54template <
class Function>
78template <
class Function>
83 if (std::abs(
fa) < std::abs(
fb))
89 if (std::abs(
fb)<
tol)
return b;
93 while( std::abs(b-a)>
tol )
99 { s = (b + std::max(
f.xmin(), b - std::abs(b-a))/8 )/2.;
delta = b-s;}
101 { s = (b + std::min(
f.xmax(), b + std::abs(b-a))/8 )/2.;
delta = b-s;}
107 if (std::abs(
fs)>std::abs(
fb))
110 for (
int i=0;
i<16;
i++)
118 if (std::abs(
fs)<std::abs(
fb)) {
dv =
false;
break ;}
127 if (std::abs(
fa) < std::abs(
fb))
133 if (std::abs(
fb) <
tol)
return b;
147template <
class Function>
152 if (std::abs(
fa) < std::abs(
fb))
158 if (std::abs(
fb)<
tol)
return b;
166#ifdef STK_ANALYSIS_VERBOSE
167 stk_cout <<
_T(
"iter = ") << iter <<
_T(
". bkm1, a, b = ") <<
bkm1 <<
_T(
" ") << a <<
_T(
" ") << b <<
_T(
"\n");
171 while( std::abs(b-a)>
tol )
183 { s = b -
fb * (b - a) / (
fb -
fa);}
186 if (!( ((s >
tmp) && (s < b)) || ((s <
tmp) && (s > b)) )
189 ||(s<=
f.xmin())||(s>=
f.xmax())
195 else {
mflag =
false;}
201 if (
fa *
fs < 0) { b = s;
fb =
fs; }
202 else { a = s;
fa =
fs; }
204 if (std::abs(
fa) < std::abs(
fb))
209#ifdef STK_ANALYSIS_VERBOSE
213 if (std::abs(
fb) <
tol )
return b;
230template <
class Function>
233 if (
x0<
f.xmin() ||
x0>
f.xmax() ||
x1<
f.xmin() ||
x1>
f.xmax() ||
tol<=0 )
In this file we define Interface base class for Real functions.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
This file include all the other header files of the project Sdk.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Real SecantMethod(IFunction< Function > const &f, Real const &x0, Real const &x1, Real tol)
apply the secant method for finding the zero of a function.
Real BrentMethod(IFunction< Function > const &f, Real const &x0, Real const &x1, Real tol)
perform the brent's algorithm.
Real findZero(IFunction< Function > const &f, Real const &x0, Real const &x1, Real tol)
find the zero of a function.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
static Type NA()
Adding a Non Available (NA) special number.