26 #ifndef O2SCL_DERIV_CERN_H 27 #define O2SCL_DERIV_CERN_H 29 #include <o2scl/deriv.h> 30 #include <o2scl/funct.h> 31 #include <o2scl/string_conv.h> 32 #include <o2scl/err_hnd.h> 34 #ifndef DOXYGEN_NO_O2NS 117 w[1][1]=1.3333333333333333;
118 w[3][1]=1.0666666666666667;
119 w[5][1]=1.0158730158730159;
120 w[7][1]=1.0039215686274510;
122 w[2][1]=3.3333333333333333e-1;
123 w[4][1]=6.6666666666666667e-2;
124 w[6][1]=1.5873015873015873e-2;
125 w[8][1]=3.9215686274509804e-3;
127 w[0][2]=2.2857142857142857;
128 w[2][2]=1.1636363636363636;
129 w[4][2]=1.0364372469635628;
130 w[6][2]=1.0088669950738916;
131 w[8][2]=1.0022021042329337;
133 w[1][2]=1.2857142857142857;
134 w[3][2]=1.6363636363636364e-1;
135 w[5][2]=3.6437246963562753e-2;
136 w[7][2]=8.8669950738916256e-3;
137 w[9][2]=2.2021042329336922e-3;
139 w[0][3]=1.8000000000000000;
140 w[2][3]=1.1250000000000000;
141 w[4][3]=1.0285714285714286;
142 w[6][3]=1.0069930069930070;
143 w[8][3]=1.0017391304347826;
145 w[1][3]=8.0000000000000000e-1;
146 w[3][3]=1.2500000000000000e-1;
147 w[5][3]=2.8571428571428571e-2;
148 w[7][3]=6.9930069930069930e-3;
149 w[9][3]=1.7391304347826087e-3;
159 double &dfdx,
double &err) {
160 return deriv_tlate<func_t>(x,func,dfdx,err);
164 virtual const char *
type() {
return "deriv_cern"; }
168 #ifndef DOXYGEN_INTERNAL 173 double &dfdx,
double &err) {
175 double t[10][10], a[10], del, hh;
176 bool lev[10]={1,0,1,0,1,0,1,0,1,0}, lmt;
179 del=10.0*fabs(delta);
186 if (is==0 || x+del*dx[9]==x) {
190 std::string str=
"Calculation of derivative failed (is="+
191 itos(is)+
" and del*dx[9]="+
dtos(del*dx[9])+
192 ") in deriv_cern::deriv_tlate().";
198 t[k][0]=(func(x+hh)-func(x-hh))/(hh+hh);
203 for(k=0;k<=9;k++) a[k]=-a[k];
209 lmt=(lmt && (hh<=0.0 || fabs(hh)<=eps*fabs(a[k])));
213 std::cout <<
"deriv_cern, iteration: " << 10-is << std::endl;
214 std::cout <<
"(hh, a[k], derivative) list: " 217 std::cout << a[k-1]-a[k] <<
" " << eps*fabs(a[k]) <<
" " 218 << t[k][0] << std::endl;
220 std::cout <<
"Converged: " << lmt << std::endl;
227 }
while (lmt==
false);
230 for(k=0;k<=9-m;k++) {
232 t[k][m]=w[m-1][1]*t[k+1][m-1]-w[m][1]*t[k][m-1];
234 t[k][m]=w[m-1][2]*t[k+1][m-1]-w[m][2]*t[k][m-1];
236 t[k][m]=w[m-1][3]*t[k+1][m-1]-w[m][3]*t[k][m-1];
241 if (dfdx!=0.0) err=(dfdx-t[0][8])/dfdx;
255 return deriv_tlate<>(x,func,dfdx,err);
268 #ifndef DOXYGEN_NO_O2NS virtual const char * type()
Return string denoting type ("deriv_cern")
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
double delta
A scaling factor (default 1.0)
std::function< double(double)> funct11
One-dimensional function typedef.
Numerical differentiation routine (CERNLIB)
int deriv_tlate(double x, func2_t &func, double &dfdx, double &err)
Internal template version of the derivative function.
double eps
Extrapolation tolerance (default is )
Numerical differentiation base [abstract base].
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
int verbose
Output control.
virtual int deriv_err(double x, func_t &func, double &dfdx, double &err)
Calculate the first derivative of func w.r.t. x and the uncertainty.
virtual int deriv_err_int(double x, funct11 &func, double &dfdx, double &err)
Calculate the first derivative of func w.r.t. x.
std::string itos(int x)
Convert an integer to a string.