share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / minpack / fortran / fdjac2.f
blob218ab94c179e7517e034b7d3861c8ee4002203d8
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)
5 c **********
7 c subroutine fdjac2
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)
17 c where
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)
25 c integer m,n,iflag
26 c double precision x(n),fvec(m)
27 c ----------
28 c calculate the functions at x and
29 c return this vector in fvec.
30 c ----------
31 c return
32 c end
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
39 c of functions.
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
64 c precision.
66 c wa is a work array of length m.
68 c subprograms called
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
79 c **********
80 integer i,j
81 double precision eps,epsmch,h,temp,zero
82 double precision dpmpar
83 data zero /0.0d0/
85 c epsmch is the machine precision.
87 epsmch = dpmpar(1)
89 eps = dsqrt(dmax1(epsfcn,epsmch))
90 do 20 j = 1, n
91 temp = x(j)
92 h = eps*dabs(temp)
93 if (h .eq. zero) h = eps
94 x(j) = temp + h
95 call fcn(m,n,x,wa,iflag)
96 if (iflag .lt. 0) go to 30
97 x(j) = temp
98 do 10 i = 1, m
99 fjac(i,j) = (wa(i) - fvec(i))/h
100 10 continue
101 20 continue
102 30 continue
103 return
105 c last card of subroutine fdjac2.