4 #include <UnitTest++.h>
10 TEST(IterTrackBasicFloat)
15 while( abs(x-xnew) > 2.f*FLT_EPSILON*abs(x) )
26 while( abs(x-xnew) > 2.f*FLT_EPSILON*abs(x) )
36 TEST(IterTrackBasicDouble)
41 while( abs(x-xnew) > 2.*DBL_EPSILON*abs(x) )
51 TEST(IterTrackBasicUnstable)
56 while( abs(x-xnew) > 2.*DBL_EPSILON*abs(x) )
60 xnew = track.
next_val( x, 1./x - 2.*x );
63 CHECK(
fp_equal( abs(xnew), 1./sqrt(3.) ) );
67 TEST(IterTrackBasicStableNeg)
73 while( abs(x-xnew) > 2.*DBL_EPSILON*abs(x) )
77 xnew = track.
next_val( x, 1./x + x/3. );
79 CHECK(
fp_equal( xnew, sqrt(1.5) ) );
82 TEST(IterTrackBasicStablePos)
88 while( abs(x-xnew) > 2.*DBL_EPSILON*abs(x) )
92 xnew = track.
next_val( x, 1./x + 2.*x/3. );
97 double testfun(
double x)
104 double x1, fx1,
x2, fx2, x3, fx3;
117 track.
add( x2, fx2 );
121 vector<double> xvals( navg );
122 for(
int i=0; i < 100 && !track.
lgConverged(); ++i )
126 track.
add( x2, fx2 );
131 double exact_root = asin(0.5);
134 double val = track.
deriv( navg, sigma );
135 double delta_lo = *min_element( xvals.begin(), xvals.end() ) - exact_root;
136 double delta_hi = *max_element( xvals.begin(), xvals.end() ) - exact_root;
137 CHECK( delta_lo < 0. );
138 CHECK( delta_hi > 0. );
141 double err_lo = -0.5*delta_lo;
142 double err_hi = -0.5*delta_hi;
143 CHECK(
fp_bound( sqrt(3.)/2.+err_hi, val, sqrt(3.)/2.+err_lo ) );
149 CHECK( sigma <
max(
pow2(err_lo),
pow2(err_hi) ) );
151 val = track.
deriv( 200 );
152 double val2 = track.
deriv();
154 val = track.
deriv( 200, sigma );
156 val = track.
deriv( sigma2 );
160 val = track.
zero_fit( navg, sigma );
172 TEST(AmsterdamMethod)
174 double x1, fx1,
x2, fx2;
182 CHECK_EQUAL( 0, err );
187 double testfun2(
double x)
193 TEST(AmsterdamMethod2)
195 double x1, fx1,
x2, fx2;
203 CHECK_EQUAL( 0, err );
207 double testfun3(
double x)
213 TEST(AmsterdamMethod3)
215 double x1, fx1,
x2, fx2;
223 CHECK_EQUAL( 0, err );
double bracket_width() const
void add(double x, double fx)
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
double Amsterdam_Method(double(*f)(double), double a, double fa, double c, double fc, double tol, int max_iter, int &err)
T next_val(T current, T next_est)
bool fp_equal(sys_float x, sys_float y, int n=3)
int init_bracket(double x1, double fx1, double x2, double fx2)
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
double zero_fit(int n, double &sigma) const
double deriv(int n, double &sigma) const