wrapper for chkder() : this was the last wrapper missing

This commit is contained in:
Thomas Capricelli 2009-08-19 18:32:37 +02:00
parent 3f63d6f97f
commit 703198a1a6
2 changed files with 48 additions and 34 deletions

View File

@ -356,5 +356,31 @@ int ei_lmdif1(
); );
} }
template<typename Scalar>
void ei_chkder(
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &x,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &fvec,
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > &fjac,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &xp,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &fvecp,
int mode,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &err
)
{
int ldfjac = fvec.size();
if (mode==1)
xp.resize(ldfjac);
else
err.resize(ldfjac);
chkder(
fvec.size(), x.size(), x.data(), fvec.data(),
fjac.data(), ldfjac,
xp.data(),
fvecp.data(),
mode,
err.data()
);
}
#endif // EIGEN_NONLINEAR_MATHFUNCTIONS_H #endif // EIGEN_NONLINEAR_MATHFUNCTIONS_H

View File

@ -57,59 +57,47 @@ int fcn_chkder(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjac
void testChkder() void testChkder()
{ {
int i, m, n, ldfjac; int m=15, n=3;
double x[3], fvec[15], fjac[15*3], xp[3], fvecp[15], Eigen::VectorXd x(n), fvec(m), xp, fvecp(m), err;
err[15]; Eigen::MatrixXd fjac(m,n);
VectorXi ipvt;
m = 15;
n = 3;
/* the following values should be suitable for */ /* the following values should be suitable for */
/* checking the jacobian matrix. */ /* checking the jacobian matrix. */
x << 9.2e-1, 1.3e-1, 5.4e-1;
x[1-1] = 9.2e-1; ei_chkder<double>(x, fvec, fjac, xp, fvecp, 1, err);
x[2-1] = 1.3e-1; fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 1);
x[3-1] = 5.4e-1; fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 2);
fcn_chkder(m, n, xp.data(), fvecp.data(), fjac.data(), m, 1);
ei_chkder<double>(x, fvec, fjac, xp, fvecp, 2, err);
ldfjac = 15; fvecp -= fvec;
chkder(m, n, x, fvec, fjac, ldfjac, xp, fvecp, 1, err); // check those
fcn_chkder(m, n, x, fvec, fjac, ldfjac, 1); VectorXd fvec_ref(m), fvecp_ref(m), err_ref(m);
fcn_chkder(m, n, x, fvec, fjac, ldfjac, 2); fvec_ref <<
fcn_chkder(m, n, xp, fvecp, fjac, ldfjac, 1);
chkder(m, n, x, fvec, fjac, ldfjac, xp, fvecp, 2, err);
for (i=1; i<=m; i++)
{
fvecp[i-1] = fvecp[i-1] - fvec[i-1];
}
double fvec_ref[] = {
-1.181606, -1.429655, -1.606344, -1.181606, -1.429655, -1.606344,
-1.745269, -1.840654, -1.921586, -1.745269, -1.840654, -1.921586,
-1.984141, -2.022537, -2.468977, -1.984141, -2.022537, -2.468977,
-2.827562, -3.473582, -4.437612, -2.827562, -3.473582, -4.437612,
-6.047662, -9.267761, -18.91806 -6.047662, -9.267761, -18.91806;
}; fvecp_ref <<
double fvecp_ref[] = {
-7.724666e-09, -3.432406e-09, -2.034843e-10, -7.724666e-09, -3.432406e-09, -2.034843e-10,
2.313685e-09, 4.331078e-09, 5.984096e-09, 2.313685e-09, 4.331078e-09, 5.984096e-09,
7.363281e-09, 8.53147e-09, 1.488591e-08, 7.363281e-09, 8.53147e-09, 1.488591e-08,
2.33585e-08, 3.522012e-08, 5.301255e-08, 2.33585e-08, 3.522012e-08, 5.301255e-08,
8.26666e-08, 1.419747e-07, 3.19899e-07 8.26666e-08, 1.419747e-07, 3.19899e-07;
}; err_ref <<
double err_ref[] = {
0.1141397, 0.09943516, 0.09674474, 0.1141397, 0.09943516, 0.09674474,
0.09980447, 0.1073116, 0.1220445, 0.09980447, 0.1073116, 0.1220445,
0.1526814, 1, 1, 0.1526814, 1, 1,
1, 1, 1, 1, 1, 1,
1, 1, 1 1, 1, 1;
};
for (i=1; i<=m; i++) VERIFY_IS_APPROX(fvec[i-1], fvec_ref[i-1]); VERIFY_IS_APPROX(fvec, fvec_ref);
for (i=1; i<=m; i++) VERIFY_IS_APPROX(fvecp[i-1], fvecp_ref[i-1]); VERIFY_IS_APPROX(fvecp, fvecp_ref);
for (i=1; i<=m; i++) VERIFY_IS_APPROX(err[i-1], err_ref[i-1]); VERIFY_IS_APPROX(err, err_ref);
} }