1 subroutine fdjac2
(fcn
,m
,n
,x
,fvec
,fjac
,ldfjac
,iflag
,epsfcn
,wa
)
2 integer m
,n
,ldfjac
,iflag
3 double precision epsfcn
4 double precision x
(n
),fvec
(m
),fjac
(ldfjac
,n
),wa
(m
)
9 c this subroutine computes a forward-difference approximation
10 c to the m by n jacobian matrix associated with a specified
11 c problem of m functions in n variables.
13 c the subroutine statement is
15 c subroutine fdjac2(fcn,m,n,x,fvec,fjac,ldfjac,iflag,epsfcn,wa)
19 c fcn is the name of the user-supplied subroutine which
20 c calculates the functions. fcn must be declared
21 c in an external statement in the user calling
22 c program, and should be written as follows.
24 c subroutine fcn(m,n,x,fvec,iflag)
26 c double precision x(n),fvec(m)
28 c calculate the functions at x and
29 c return this vector in fvec.
34 c the value of iflag should not be changed by fcn unless
35 c the user wants to terminate execution of fdjac2.
36 c in this case set iflag to a negative integer.
38 c m is a positive integer input variable set to the number
41 c n is a positive integer input variable set to the number
42 c of variables. n must not exceed m.
44 c x is an input array of length n.
46 c fvec is an input array of length m which must contain the
47 c functions evaluated at x.
49 c fjac is an output m by n array which contains the
50 c approximation to the jacobian matrix evaluated at x.
52 c ldfjac is a positive integer input variable not less than m
53 c which specifies the leading dimension of the array fjac.
55 c iflag is an integer variable which can be used to terminate
56 c the execution of fdjac2. see description of fcn.
58 c epsfcn is an input variable used in determining a suitable
59 c step length for the forward-difference approximation. this
60 c approximation assumes that the relative errors in the
61 c functions are of the order of epsfcn. if epsfcn is less
62 c than the machine precision, it is assumed that the relative
63 c errors in the functions are of the order of the machine
66 c wa is a work array of length m.
70 c user-supplied ...... fcn
72 c minpack-supplied ... dpmpar
74 c fortran-supplied ... dabs,dmax1,dsqrt
76 c argonne national laboratory. minpack project. march 1980.
77 c burton s. garbow, kenneth e. hillstrom, jorge j. more
81 double precision eps
,epsmch
,h
,temp
,zero
82 double precision dpmpar
85 c epsmch is the machine precision.
89 eps
= dsqrt
(dmax1
(epsfcn
,epsmch
))
93 if (h
.eq
. zero
) h
= eps
95 call fcn
(m
,n
,x
,wa
,iflag
)
96 if (iflag
.lt
. 0) go to 30
99 fjac
(i
,j
) = (wa
(i
) - fvec
(i
))/h
105 c last card of subroutine fdjac2.