Files
eigen/unsupported/Eigen/src/NonLinear/chkder.h

56 lines
1.6 KiB
C
Raw Normal View History

#define chkder_log10e 0.43429448190325182765
#define chkder_factor 100.
2009-08-20 23:26:40 +02:00
template<typename Scalar>
void ei_chkder(
Matrix< Scalar, Dynamic, 1 > &x,
Matrix< Scalar, Dynamic, 1 > &fvec,
Matrix< Scalar, Dynamic, Dynamic > &fjac,
Matrix< Scalar, Dynamic, 1 > &xp,
Matrix< Scalar, Dynamic, 1 > &fvecp,
int mode,
Matrix< Scalar, Dynamic, 1 > &err
)
{
2009-08-20 23:26:40 +02:00
const Scalar eps = ei_sqrt(epsilon<Scalar>());
const Scalar epsf = chkder_factor * epsilon<Scalar>();
const Scalar epslog = chkder_log10e * ei_log(eps);
Scalar temp;
2009-08-20 23:26:40 +02:00
int i,j;
2009-08-20 23:26:40 +02:00
const int m = fvec.size(), n = x.size();
if (mode != 2) {
2009-08-23 06:16:05 +02:00
xp.resize(m);
/* mode = 1. */
2009-08-20 23:26:40 +02:00
for (j = 0; j < n; ++j) {
temp = eps * ei_abs(x[j]);
if (temp == 0.)
temp = eps;
xp[j] = x[j] + temp;
}
}
2009-08-20 23:26:40 +02:00
else {
/* mode = 2. */
2009-08-23 06:16:05 +02:00
err.setZero(m);
2009-08-20 23:26:40 +02:00
for (j = 0; j < n; ++j) {
temp = ei_abs(x[j]);
if (temp == 0.)
temp = 1.;
err += temp * fjac.col(j);
}
2009-08-20 23:26:40 +02:00
for (i = 0; i < m; ++i) {
temp = 1.;
2009-08-23 06:16:05 +02:00
if (fvec[i] != 0. && fvecp[i] != 0. && ei_abs(fvecp[i] - fvec[i]) >= epsf * ei_abs(fvec[i]))
temp = eps * ei_abs((fvecp[i] - fvec[i]) / eps - err[i]) / (ei_abs(fvec[i]) + ei_abs(fvecp[i]));
2009-08-20 23:26:40 +02:00
err[i] = 1.;
2009-08-23 06:16:05 +02:00
if (temp > epsilon<Scalar>() && temp < eps)
err[i] = (chkder_log10e * ei_log(temp) - epslog) / epslog;
2009-08-23 06:16:05 +02:00
if (temp >= eps)
2009-08-20 23:26:40 +02:00
err[i] = 0.;
}
}
} /* chkder_ */