cleaning fdjac*()

This commit is contained in:
Thomas Capricelli 2009-08-23 06:04:06 +02:00
parent f01332043b
commit 264e61932c
2 changed files with 42 additions and 76 deletions

View File

@ -22,68 +22,47 @@ int ei_fdjac1(
eps = ei_sqrt((std::max(epsfcn,epsmch))); eps = ei_sqrt((std::max(epsfcn,epsmch)));
msum = ml + mu + 1; msum = ml + mu + 1;
if (msum < n) { if (msum >= n) {
goto L40; /* computation of dense approximate jacobian. */
} for (j = 0; j < n; ++j) {
temp = x[j];
/* computation of dense approximate jacobian. */ h = eps * ei_abs(temp);
if (h == 0.)
for (j = 0; j < n; ++j) { h = eps;
temp = x[j]; x[j] = temp + h;
h = eps * ei_abs(temp); iflag = Functor::f(x, wa1);
if (h == 0.) if (iflag < 0)
h = eps; return iflag;
x[j] = temp + h; x[j] = temp;
iflag = Functor::f(x, wa1); fjac.col(j) = (wa1-fvec)/h;
if (iflag < 0)
goto L30;
x[j] = temp;
for (i = 0; i < n; ++i) {
fjac(i,j) = (wa1[i] - fvec[i]) / h;
/* L10: */
} }
/* L20: */
}
L30:
/* goto L110; */
return iflag;
L40:
/* computation of banded approximate jacobian. */ }else {
/* computation of banded approximate jacobian. */
for (k = 0; k < msum; ++k) { for (k = 0; k < msum; ++k) {
for (j = k; msum< 0 ? j > n: j < n; j += msum) { for (j = k; msum< 0 ? j > n: j < n; j += msum) {
wa2[j] = x[j]; wa2[j] = x[j];
h = eps * ei_abs(wa2[j]); h = eps * ei_abs(wa2[j]);
if (h == 0.) h = eps; if (h == 0.) h = eps;
x[j] = wa2[j] + h; x[j] = wa2[j] + h;
/* L60: */ }
} iflag = Functor::f(x, wa1);
iflag = Functor::f(x, wa1); if (iflag < 0) {
if (iflag < 0) { return iflag;
/* goto L100; */ }
return iflag; for (j = k; msum< 0 ? j > n: j < n; j += msum) {
} x[j] = wa2[j];
for (j = k; msum< 0 ? j > n: j < n; j += msum) { h = eps * ei_abs(wa2[j]);
x[j] = wa2[j]; if (h == 0.) h = eps;
h = eps * ei_abs(wa2[j]); for (i = 0; i < n; ++i) {
if (h == 0.) h = eps; fjac(i,j) = 0.;
for (i = 0; i < n; ++i) { if (i >= j - mu && i <= j + ml) {
fjac(i,j) = 0.; fjac(i,j) = (wa1[i] - fvec[i]) / h;
if (i >= j - mu && i <= j + ml) { }
fjac(i,j) = (wa1[i] - fvec[i]) / h; }
}
/* L70: */
} }
/* L80: */
} }
/* L90: */
} }
/* L100: */
/* L110: */
return iflag; return iflag;
/* last card of subroutine fdjac1. */
} /* fdjac1_ */ } /* fdjac1_ */

View File

@ -8,18 +8,15 @@ int ei_fdjac2(
Matrix< Scalar, Dynamic, 1 > &wa) Matrix< Scalar, Dynamic, 1 > &wa)
{ {
/* Local variables */ /* Local variables */
Scalar h; Scalar h, temp;
int i, j;
Scalar eps, temp;
int iflag; int iflag;
/* Function Body */ /* Function Body */
const Scalar epsmch = epsilon<Scalar>(); const Scalar epsmch = epsilon<Scalar>();
const int n = x.size(); const int n = x.size();
const int m = fvec.size(); const Scalar eps = ei_sqrt((std::max(epsfcn,epsmch)));
eps = ei_sqrt((std::max(epsfcn,epsmch))); for (int j = 0; j < n; ++j) {
for (j = 0; j < n; ++j) {
temp = x[j]; temp = x[j];
h = eps * ei_abs(temp); h = eps * ei_abs(temp);
if (h == 0.) { if (h == 0.) {
@ -27,21 +24,11 @@ int ei_fdjac2(
} }
x[j] = temp + h; x[j] = temp + h;
iflag = Functor::f(x, wa); iflag = Functor::f(x, wa);
if (iflag < 0) { if (iflag < 0)
/* goto L30; */
return iflag; return iflag;
}
x[j] = temp; x[j] = temp;
for (i = 0; i < m; ++i) { fjac.col(j) = (wa-fvec)/h;
fjac(i,j) = (wa[i] - fvec[i]) / h;
/* L10: */
}
/* L20: */
} }
/* L30: */
return iflag; return iflag;
}
/* last card of subroutine fdjac2. */
} /* fdjac2_ */