1 subroutine chkder
(m
,n
,x
,fvec
,fjac
,ldfjac
,xp
,fvecp
,mode
,err
)
2 integer m
,n
,ldfjac
,mode
3 double precision x
(n
),fvec
(m
),fjac
(ldfjac
,n
),xp
(n
),fvecp
(m
),
9 c this subroutine checks the gradients of m nonlinear functions
10 c in n variables, evaluated at a point x, for consistency with
11 c the functions themselves. the user must call chkder twice,
12 c first with mode = 1 and then with mode = 2.
14 c mode = 1. on input, x must contain the point of evaluation.
15 c on output, xp is set to a neighboring point.
17 c mode = 2. on input, fvec must contain the functions and the
18 c rows of fjac must contain the gradients
19 c of the respective functions each evaluated
20 c at x, and fvecp must contain the functions
22 c on output, err contains measures of correctness of
23 c the respective gradients.
25 c the subroutine does not perform reliably if cancellation or
26 c rounding errors cause a severe loss of significance in the
27 c evaluation of a function. therefore, none of the components
28 c of x should be unusually small (in particular, zero) or any
29 c other value which may cause loss of significance.
31 c the subroutine statement is
33 c subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err)
37 c m is a positive integer input variable set to the number
40 c n is a positive integer input variable set to the number
43 c x is an input array of length n.
45 c fvec is an array of length m. on input when mode = 2,
46 c fvec must contain the functions evaluated at x.
48 c fjac is an m by n array. on input when mode = 2,
49 c the rows of fjac must contain the gradients of
50 c the respective functions evaluated at x.
52 c ldfjac is a positive integer input parameter not less than m
53 c which specifies the leading dimension of the array fjac.
55 c xp is an array of length n. on output when mode = 1,
56 c xp is set to a neighboring point of x.
58 c fvecp is an array of length m. on input when mode = 2,
59 c fvecp must contain the functions evaluated at xp.
61 c mode is an integer input variable set to 1 on the first call
62 c and 2 on the second. other values of mode are equivalent
65 c err is an array of length m. on output when mode = 2,
66 c err contains measures of correctness of the respective
67 c gradients. if there is no severe loss of significance,
68 c then if err(i) is 1.0 the i-th gradient is correct,
69 c while if err(i) is 0.0 the i-th gradient is incorrect.
70 c for values of err between 0.0 and 1.0, the categorization
71 c is less certain. in general, a value of err(i) greater
72 c than 0.5 indicates that the i-th gradient is probably
73 c correct, while a value of err(i) less than 0.5 indicates
74 c that the i-th gradient is probably incorrect.
78 c minpack supplied ... dpmpar
80 c fortran supplied ... dabs,dlog10,dsqrt
82 c argonne national laboratory. minpack project. march 1980.
83 c burton s. garbow, kenneth e. hillstrom, jorge j. more
87 double precision eps
,epsf
,epslog
,epsmch
,factor
,one
,temp
,zero
88 double precision dpmpar
89 data factor
,one
,zero
/1.0d2
,1.0d0
,0.0d0
/
91 c epsmch is the machine precision.
97 if (mode
.eq
. 2) go to 20
102 temp
= eps*dabs
(x
(j
))
103 if (temp
.eq
. zero
) temp
= eps
118 if (temp
.eq
. zero
) temp
= one
120 err
(i
) = err
(i
) + temp*fjac
(i
,j
)
125 if (fvec
(i
) .ne
. zero
.and
. fvecp
(i
) .ne
. zero
126 * .and
. dabs
(fvecp
(i
)-fvec
(i
)) .ge
. epsf*dabs
(fvec
(i
)))
127 * temp
= eps*dabs
((fvecp
(i
)-fvec
(i
))/eps
-err
(i
))
128 * /(dabs
(fvec
(i
)) + dabs
(fvecp
(i
)))
130 if (temp
.gt
. epsmch
.and
. temp
.lt
. eps
)
131 * err
(i
) = (dlog10
(temp
) - epslog
)/epslog
132 if (temp
.ge
. eps
) err
(i
) = zero
138 c last card of subroutine chkder.