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,12 +22,8 @@ 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. */ /* computation of dense approximate jacobian. */
for (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);
@ -36,32 +32,22 @@ int ei_fdjac1(
x[j] = temp + h; x[j] = temp + h;
iflag = Functor::f(x, wa1); iflag = Functor::f(x, wa1);
if (iflag < 0) 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; return iflag;
L40: x[j] = temp;
fjac.col(j) = (wa1-fvec)/h;
}
}else {
/* computation of banded approximate jacobian. */ /* 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) {
/* goto L100; */
return iflag; return iflag;
} }
for (j = k; msum< 0 ? j > n: j < n; j += msum) { for (j = k; msum< 0 ? j > n: j < n; j += msum) {
@ -73,17 +59,10 @@ L40:
if (i >= j - mu && i <= j + ml) { if (i >= j - mu && i <= j + ml) {
fjac(i,j) = (wa1[i] - fvec[i]) / h; 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_ */