9 #include <unsupported/Eigen/NumericalDiff> 12 template<
typename _Scalar,
int NX=Dynamic,
int NY=Dynamic>
20 typedef Matrix<Scalar,InputsAtCompileTime,1>
InputType;
21 typedef Matrix<Scalar,ValuesAtCompileTime,1>
ValueType;
22 typedef Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime>
JacobianType;
39 double tmp1, tmp2, tmp3;
40 double y[15] = {1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
41 3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};
43 for (
int i = 0; i <
values(); i++)
47 tmp3 = (i>=8)? tmp2 : tmp1;
48 fvec[i] = y[i] - (x[0] + tmp1/(x[1]*tmp2 + x[2]*tmp3));
53 int actual_df(
const VectorXd &x, MatrixXd &fjac)
const 55 double tmp1, tmp2, tmp3, tmp4;
56 for (
int i = 0; i <
values(); i++)
60 tmp3 = (i>=8)? tmp2 : tmp1;
61 tmp4 = (x[1]*tmp2 + x[2]*tmp3); tmp4 = tmp4*tmp4;
63 fjac(i,1) = tmp1*tmp2/tmp4;
64 fjac(i,2) = tmp1*tmp3/tmp4;
74 MatrixXd actual_jac(15,3);
77 x << 0.082, 1.13, 2.35;
84 NumericalDiff<my_functor> numDiff(functor);
88 VERIFY_IS_APPROX(jac, actual_jac);
95 MatrixXd actual_jac(15,3);
98 x << 0.082, 1.13, 2.35;
104 NumericalDiff<my_functor,Central> numDiff(functor);
107 VERIFY_IS_APPROX(jac, actual_jac);
Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
int operator()(const VectorXd &x, VectorXd &fvec) const
Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
void test_NumericalDiff()
int actual_df(const VectorXd &x, MatrixXd &fjac) const
Functor(int inputs, int values)