43 #ifndef O2SCL_DERIV_GSL_H
44 #define O2SCL_DERIV_GSL_H
54 #include <gsl/gsl_deriv.h>
55 #include <gsl/gsl_errno.h>
57 #include <o2scl/misc.h>
58 #include <o2scl/deriv.h>
59 #include <o2scl/funct.h>
60 #include <o2scl/err_hnd.h>
62 #ifndef DOXYGEN_NO_O2NS
124 template<
class func_t=funct,
class fp_t=
double>
class deriv_gsl :
161 virtual int deriv_err(fp_t x, func_t &func, fp_t &dfdx, fp_t &err) {
162 return deriv_tlate<func_t>(x,func,dfdx,err);
166 virtual const char *
type() {
return "deriv_gsl"; }
168 #ifndef DOXYGEN_INTERNAL
175 fp_t &dfdx, fp_t &err) {
180 if (x==0.0) hh=1.0e-4;
186 fp_t r_0, round, trunc, error;
189 fp_t one=1, two=2, three=3, ten=10;
193 while (fail && it_count<20) {
198 if (cret!=0) fail=
true;
202 if (fail==
false && round < trunc && (round > 0 && trunc > 0)) {
203 fp_t r_opt, round_opt, trunc_opt, error_opt;
209 h_opt=hh*pow(round/(two*trunc),one/three);
211 if (cret!=0) fail=
true;
212 error_opt=round_opt+trunc_opt;
217 if (fail==
false && error_opt < error &&
228 std::cout <<
"Function deriv_gsl::deriv_tlate out of range. "
229 <<
"Decreasing step." << std::endl;
234 if (fail==
true || it_count>=20) {
236 O2SCL_ERR2(
"Failed to find finite derivative in ",
252 (fp_t x,
typename deriv_base<func_t,fp_t>::internal_func_t &func,
253 fp_t &dfdx, fp_t &err) {
254 return deriv_tlate<>(x,func,dfdx,err);
267 template<
class func2_t>
269 fp_t &abserr_round, fp_t &abserr_trunc,
272 fp_t fm1, fp1, fmh, fph;
276 fp_t two=2, three=3, four=4, one=1;
278 fp_t eps=std::numeric_limits<fp_t>::epsilon();
287 std::cout <<
"deriv_gsl: " << std::endl;
288 std::cout <<
"step: " << hh << std::endl;
289 std::cout <<
"abscissas: " << x-hh/two <<
" " << x-hh <<
" "
290 << x+hh/two <<
" " << x+hh << std::endl;
291 std::cout <<
"ordinates: " << fm1 <<
" " << fmh <<
" " << fph <<
" "
304 fp_t r3=(fp1-fm1)/two;
305 fp_t r5=(four/three)*(fph-fmh)-(one/three)*r3;
327 std::cout <<
"res: " << result <<
" trc: " << abserr_trunc
328 <<
" rnd: " << abserr_round << std::endl;
342 #ifndef DOXYGEN_NO_O2NS