25 template <
class VECTORLIKE,
class VECTORLIKE2,
class VECTORLIKE3,
class MATRIXLIKE,
class USERPARAM >
28 void (*functor) (
const VECTORLIKE &
x,
const USERPARAM &
y, VECTORLIKE3 &out),
29 const VECTORLIKE2 &increments,
30 const USERPARAM &userParam,
31 MATRIXLIKE &out_Jacobian )
34 ASSERT_(
x.size()>0 && increments.size() ==
x.size());
37 const size_t n =
x.size();
39 for (
size_t j=0;j<
n;j++) {
ASSERT_( increments[j]>0 ) }
41 VECTORLIKE3 f_minus, f_plus;
45 for (
size_t j=0;j<
n;j++)
48 x_mod[j]=
x[j]+increments[j];
49 functor(x_mod,userParam, f_plus);
51 x_mod[j]=
x[j]-increments[j];
52 functor(x_mod,userParam, f_minus);
55 const double Ax_2_inv = 0.5/increments[j];
61 out_Jacobian.setSize(m,
n);
64 for (
size_t i=0;i<m;i++)
65 out_Jacobian.get_unsafe(i,j) = Ax_2_inv* (f_plus[i]-f_minus[i]);
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void estimateJacobian(const VECTORLIKE &x, void(*functor)(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out), const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...