2 SUBROUTINE CHKDER (M, N, X, FVEC, FJAC, LDFJAC, XP, FVECP, MODE,
4 C***BEGIN PROLOGUE CHKDER
5 C***PURPOSE Check the gradients of M nonlinear functions in N
6 C variables, evaluated at a point X, for consistency
7 C with the functions themselves.
10 C***TYPE SINGLE PRECISION (CHKDER-S, DCKDER-D)
11 C***KEYWORDS GRADIENTS, JACOBIAN, MINPACK, NONLINEAR
12 C***AUTHOR Hiebert, K. L. (SNLA)
15 C This subroutine is a companion routine to SNLS1,SNLS1E,SNSQ,and
16 C SNSQE which may be used to check the calculation of the Jacobian.
20 C This subroutine checks the gradients of M nonlinear functions
21 C in N variables, evaluated at a point X, for consistency with
22 C the functions themselves. The user must call CKDER twice,
23 C first with MODE = 1 and then with MODE = 2.
25 C MODE = 1. On input, X must contain the point of evaluation.
26 C On output, XP is set to a neighboring point.
28 C MODE = 2. On input, FVEC must contain the functions and the
29 C rows of FJAC must contain the gradients
30 C of the respective functions each evaluated
31 C at X, and FVECP must contain the functions
33 C On output, ERR contains measures of correctness of
34 C the respective gradients.
36 C The subroutine does not perform reliably if cancellation or
37 C rounding errors cause a severe loss of significance in the
38 C evaluation of a function. Therefore, none of the components
39 C of X should be unusually small (in particular, zero) or any
40 C other value which may cause loss of significance.
42 C The SUBROUTINE statement is
44 C SUBROUTINE CHKDER(M,N,X,FVEC,FJAC,LDFJAC,XP,FVECP,MODE,ERR)
48 C M is a positive integer input variable set to the number
51 C N is a positive integer input variable set to the number
54 C X is an input array of length N.
56 C FVEC is an array of length M. On input when MODE = 2,
57 C FVEC must contain the functions evaluated at X.
59 C FJAC is an M by N array. On input when MODE = 2,
60 C the rows of FJAC must contain the gradients of
61 C the respective functions evaluated at X.
63 C LDFJAC is a positive integer input parameter not less than M
64 C which specifies the leading dimension of the array FJAC.
66 C XP is an array of length N. On output when MODE = 1,
67 C XP is set to a neighboring point of X.
69 C FVECP is an array of length M. On input when MODE = 2,
70 C FVECP must contain the functions evaluated at XP.
72 C MODE is an integer input variable set to 1 on the first call
73 C and 2 on the second. Other values of MODE are equivalent
76 C ERR is an array of length M. On output when MODE = 2,
77 C ERR contains measures of correctness of the respective
78 C gradients. If there is no severe loss of significance,
79 C then if ERR(I) is 1.0 the I-th gradient is correct,
80 C while if ERR(I) is 0.0 the I-th gradient is incorrect.
81 C For values of ERR between 0.0 and 1.0, the categorization
82 C is less certain. In general, a value of ERR(I) greater
83 C than 0.5 indicates that the I-th gradient is probably
84 C correct, while a value of ERR(I) less than 0.5 indicates
85 C that the I-th gradient is probably incorrect.
87 C***REFERENCES M. J. D. Powell, A hybrid method for nonlinear equa-
88 C tions. In Numerical Methods for Nonlinear Algebraic
89 C Equations, P. Rabinowitz, Editor. Gordon and Breach,
91 C***ROUTINES CALLED R1MACH
92 C***REVISION HISTORY (YYMMDD)
94 C 890531 Changed all specific intrinsics to generic. (WRB)
95 C 890831 Modified array declarations. (WRB)
96 C 890831 REVISION DATE from Version 3.2
97 C 891214 Prologue converted to Version 4.0 format. (BAB)
98 C 900326 Removed duplicate information from DESCRIPTION section.
100 C 920501 Reformatted the REFERENCES section. (WRB)
101 C***END PROLOGUE CHKDER
102 INTEGER M,N,LDFJAC,MODE
103 REAL X(*),FVEC(*),FJAC(LDFJAC,*),XP(*),FVECP(*),ERR(*)
105 REAL EPS,EPSF,EPSLOG,EPSMCH,FACTOR,ONE,TEMP,ZERO
107 SAVE FACTOR, ONE, ZERO
109 DATA FACTOR,ONE,ZERO /1.0E2,1.0E0,0.0E0/
110 C***FIRST EXECUTABLE STATEMENT CHKDER
115 IF (MODE .EQ. 2) GO TO 20
121 IF (TEMP .EQ. ZERO) TEMP = EPS
136 IF (TEMP .EQ. ZERO) TEMP = ONE
138 ERR(I) = ERR(I) + TEMP*FJAC(I,J)
143 IF (FVEC(I) .NE. ZERO .AND. FVECP(I) .NE. ZERO
144 1 .AND. ABS(FVECP(I)-FVEC(I)) .GE. EPSF*ABS(FVEC(I)))
145 2 TEMP = EPS*ABS((FVECP(I)-FVEC(I))/EPS-ERR(I))
146 3 /(ABS(FVEC(I)) + ABS(FVECP(I)))
148 IF (TEMP .GT. EPSMCH .AND. TEMP .LT. EPS)
149 1 ERR(I) = (LOG10(TEMP) - EPSLOG)/EPSLOG
150 IF (TEMP .GE. EPS) ERR(I) = ZERO
156 C LAST CARD OF SUBROUTINE CHKDER.