1 subroutine fdjac1
(fcn
,n
,x
,fvec
,fjac
,ldfjac
,iflag
,ml
,mu
,epsfcn
,
3 integer n
,ldfjac
,iflag
,ml
,mu
4 double precision epsfcn
5 double precision x
(n
),fvec
(n
),fjac
(ldfjac
,n
),wa1
(n
),wa2
(n
)
10 c this subroutine computes a forward-difference approximation
11 c to the n by n jacobian matrix associated with a specified
12 c problem of n functions in n variables. if the jacobian has
13 c a banded form, then function evaluations are saved by only
14 c approximating the nonzero terms.
16 c the subroutine statement is
18 c subroutine fdjac1(fcn,n,x,fvec,fjac,ldfjac,iflag,ml,mu,epsfcn,
23 c fcn is the name of the user-supplied subroutine which
24 c calculates the functions. fcn must be declared
25 c in an external statement in the user calling
26 c program, and should be written as follows.
28 c subroutine fcn(n,x,fvec,iflag)
30 c double precision x(n),fvec(n)
32 c calculate the functions at x and
33 c return this vector in fvec.
38 c the value of iflag should not be changed by fcn unless
39 c the user wants to terminate execution of fdjac1.
40 c in this case set iflag to a negative integer.
42 c n is a positive integer input variable set to the number
43 c of functions and variables.
45 c x is an input array of length n.
47 c fvec is an input array of length n which must contain the
48 c functions evaluated at x.
50 c fjac is an output n by n array which contains the
51 c approximation to the jacobian matrix evaluated at x.
53 c ldfjac is a positive integer input variable not less than n
54 c which specifies the leading dimension of the array fjac.
56 c iflag is an integer variable which can be used to terminate
57 c the execution of fdjac1. see description of fcn.
59 c ml is a nonnegative integer input variable which specifies
60 c the number of subdiagonals within the band of the
61 c jacobian matrix. if the jacobian is not banded, set
62 c ml to at least n - 1.
64 c epsfcn is an input variable used in determining a suitable
65 c step length for the forward-difference approximation. this
66 c approximation assumes that the relative errors in the
67 c functions are of the order of epsfcn. if epsfcn is less
68 c than the machine precision, it is assumed that the relative
69 c errors in the functions are of the order of the machine
72 c mu is a nonnegative integer input variable which specifies
73 c the number of superdiagonals within the band of the
74 c jacobian matrix. if the jacobian is not banded, set
75 c mu to at least n - 1.
77 c wa1 and wa2 are work arrays of length n. if ml + mu + 1 is at
78 c least n, then the jacobian is considered dense, and wa2 is
83 c minpack-supplied ... dpmpar
85 c fortran-supplied ... dabs,dmax1,dsqrt
87 c argonne national laboratory. minpack project. march 1980.
88 c burton s. garbow, kenneth e. hillstrom, jorge j. more
92 double precision eps
,epsmch
,h
,temp
,zero
93 double precision dpmpar
96 c epsmch is the machine precision.
100 eps
= dsqrt
(dmax1
(epsfcn
,epsmch
))
102 if (msum
.lt
. n
) go to 40
104 c computation of dense approximate jacobian.
109 if (h
.eq
. zero
) h
= eps
111 call fcn
(n
,x
,wa1
,iflag
)
112 if (iflag
.lt
. 0) go to 30
115 fjac
(i
,j
) = (wa1
(i
) - fvec
(i
))/h
122 c computation of banded approximate jacobian.
128 if (h
.eq
. zero
) h
= eps
131 call fcn
(n
,x
,wa1
,iflag
)
132 if (iflag
.lt
. 0) go to 100
136 if (h
.eq
. zero
) h
= eps
139 if (i
.ge
. j
- mu
.and
. i
.le
. j
+ ml
)
140 * fjac
(i
,j
) = (wa1
(i
) - fvec
(i
))/h
148 c last card of subroutine fdjac1.