eigenization of fcn_chkder + bugfix

This commit is contained in:
Thomas Capricelli 2009-08-29 02:46:19 +02:00
parent c1265ebbfe
commit c990938415
2 changed files with 10 additions and 8 deletions

View File

@ -22,7 +22,7 @@ void ei_chkder(
const int m = fvec.size(), n = x.size(); const int m = fvec.size(), n = x.size();
if (mode != 2) { if (mode != 2) {
xp.resize(m); xp.resize(n);
/* mode = 1. */ /* mode = 1. */
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
temp = eps * ei_abs(x[j]); temp = eps * ei_abs(x[j]);

View File

@ -8,11 +8,13 @@
#include "main.h" #include "main.h"
#include <unsupported/Eigen/NonLinear> #include <unsupported/Eigen/NonLinear>
int fcn_chkder(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjac, int ldfjac, int iflag) int fcn_chkder(const VectorXd &x, VectorXd &fvec, MatrixXd &fjac, int iflag)
{ {
/* subroutine fcn for chkder example. */ /* subroutine fcn for chkder example. */
int i; int i;
assert(15 == fvec.size());
assert(3 == x.size());
double tmp1, tmp2, tmp3, tmp4; double tmp1, tmp2, tmp3, tmp4;
double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1, double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39}; 3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};
@ -40,9 +42,9 @@ int fcn_chkder(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjac
tmp3 = tmp2; tmp3 = tmp2;
if (i >= 8) tmp3 = tmp2; if (i >= 8) tmp3 = tmp2;
tmp4 = (x[1]*tmp2 + x[2]*tmp3); tmp4=tmp4*tmp4; tmp4 = (x[1]*tmp2 + x[2]*tmp3); tmp4=tmp4*tmp4;
fjac[i+ ldfjac*(0)] = -1.; fjac(i,0) = -1.;
fjac[i+ ldfjac*(1)] = tmp1*tmp2/tmp4; fjac(i,1) = tmp1*tmp2/tmp4;
fjac[i+ ldfjac*(2)] = tmp1*tmp3/tmp4; fjac(i,2) = tmp1*tmp3/tmp4;
} }
} }
return 0; return 0;
@ -61,9 +63,9 @@ void testChkder()
x << 9.2e-1, 1.3e-1, 5.4e-1; x << 9.2e-1, 1.3e-1, 5.4e-1;
ei_chkder(x, fvec, fjac, xp, fvecp, 1, err); ei_chkder(x, fvec, fjac, xp, fvecp, 1, err);
fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 1); fcn_chkder(x, fvec, fjac, 1);
fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 2); fcn_chkder(x, fvec, fjac, 2);
fcn_chkder(m, n, xp.data(), fvecp.data(), fjac.data(), m, 1); fcn_chkder(xp, fvecp, fjac, 1);
ei_chkder(x, fvec, fjac, xp, fvecp, 2, err); ei_chkder(x, fvec, fjac, xp, fvecp, 2, err);
fvecp -= fvec; fvecp -= fvec;