TMB Documentation  v1.9.2
Functions
romberg Namespace Reference

Univariate and multivariate numerical integration. More...

Functions

template<class Type , class F >
Type integrate (F f, Type a, Type b, int n=7, int p=2)
 1D numerical integration using Romberg's method. More...
 
template<class Type , class F >
Type integrate (F f, vector< Type > a, vector< Type > b, int n=7, int p=2)
 Multi-dimensional numerical integration using Romberg's method. Dimension need not be known at compile time. More...
 

Detailed Description

Univariate and multivariate numerical integration.

Function Documentation

§ integrate() [1/2]

template<class Type , class F >
Type romberg::integrate ( f,
Type  a,
Type  b,
int  n = 7,
int  p = 2 
)

1D numerical integration using Romberg's method.

Parameters
fUnivariate functor
aLower scalar integration limit
bUpper scalar integration limit
nSubdivisions ( \(2^{n-1}+1\) function evaluations).
Note
The method is not adaptive and the user may have to specify a larger n.

Example:

#include <TMB.hpp>
template<class Type>
struct univariate {
Type theta; // Parameter in integrand
univariate(Type theta_) // Constructor of integrand
: theta (theta_) {} // Initializer list
Type operator()(Type x){ // Evaluate integrand
return exp( -theta * (x * x) );
}
};
template<class Type>
Type objective_function<Type>::operator() () {
PARAMETER(theta);
univariate<Type> f(theta);
Type res = romberg::integrate(f, a, b);
return res;
}
Examples:
adaptive_integration.cpp, register_atomic.cpp, and register_atomic_parallel.cpp.

Definition at line 52 of file romberg.hpp.

§ integrate() [2/2]

template<class Type , class F >
Type romberg::integrate ( f,
vector< Type >  a,
vector< Type >  b,
int  n = 7,
int  p = 2 
)

Multi-dimensional numerical integration using Romberg's method. Dimension need not be known at compile time.

Parameters
fMultivariate functor
aLower vector integration limit
bUpper vector integration limit
nSubdivisions per dimension ( \((2^{n-1}+1)^d\) function evaluations).
Note
The method is not adaptive and the user may have to specify a larger n.

Example:

#include <TMB.hpp>
template<class Type>
struct multivariate {
Type theta; // Parameter in integrand
multivariate(Type theta_) // Constructor of integrand
: theta (theta_) {} // Initializer list
Type operator() // Evaluate integrand
return exp( -theta * (x * x).sum() );
}
};
template<class Type>
Type objective_function<Type>::operator() () {
PARAMETER(theta);
multivariate<Type> f(theta);
Type res = romberg::integrate(f, a, b);
return res;
}

Definition at line 154 of file romberg.hpp.

License: GPL v2