51 template<
class Type,
class F>
52 Type
integrate(F f, Type a, Type b,
int n = 7,
int p = 2){
54 return CppAD::RombergOne(f, a, b, n, p, e);
58 template<
class Type,
class F>
64 f=f_; x=x_; slice=slice_;
66 Type operator()(Type y){
68 return f->operator()(x);
73 template<
class Type,
class F>
74 Type integrate_slice(F &f,
vector<Type> x,
int i, Type a, Type b,
int n=7,
int p=2){
75 return integrate(slicefun<Type, F>(&f, x, i), a, b, n, p);
79 struct multivariate_integrand{
84 struct integratelast : multivariate_integrand<Type>{
85 slicefun<Type,multivariate_integrand<Type> >* fslice;
88 integratelast(multivariate_integrand<Type> &f,
int dim, Type a_, Type b_,
int n_ = 7,
int p_ = 2){
91 fslice =
new slicefun<Type,multivariate_integrand<Type> >(&f, x, slice);
95 ~integratelast(){
delete fslice;}
97 for(
int i=0; i < y.size(); i++) fslice->x[i] = y[i];
105 integratelast<Type> ffirst(f, dim, a(dim - 1), b(dim - 1), n, p);
112 return integrate_multi(ffirst, afirst, bfirst, n, p);
153 template<
class Type,
class F>
156 struct integrand : multivariate_integrand<Type>{
158 integrand(F f_) : f(f_) {}
164 return integrate_multi(f_cpy, a, b, n, p);
Vector class used by TMB.
Type integrate(F f, Type a, Type b, int n=7, int p=2)
1D numerical integration using Romberg's method.
Univariate and multivariate numerical integration.