dfdjc3.f 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. *DECK DFDJC3
  2. SUBROUTINE DFDJC3 (FCN, M, N, X, FVEC, FJAC, LDFJAC, IFLAG,
  3. + EPSFCN, WA)
  4. C***BEGIN PROLOGUE DFDJC3
  5. C***SUBSIDIARY
  6. C***PURPOSE Subsidiary to DNLS1 and DNLS1E
  7. C***LIBRARY SLATEC
  8. C***TYPE DOUBLE PRECISION (FDJAC3-S, DFDJC3-D)
  9. C***AUTHOR (UNKNOWN)
  10. C***DESCRIPTION
  11. C
  12. C **** Double Precision version of FDJAC3 ****
  13. C
  14. C This subroutine computes a forward-difference approximation
  15. C to the M by N Jacobian matrix associated with a specified
  16. C problem of M functions in N variables.
  17. C
  18. C The subroutine statement is
  19. C
  20. C SUBROUTINE DFDJC3(FCN,M,N,X,FVEC,FJAC,LDFJAC,IFLAG,EPSFCN,WA)
  21. C
  22. C where
  23. C
  24. C FCN is the name of the user-supplied subroutine which
  25. C calculates the functions. FCN must be declared
  26. C in an external statement in the user calling
  27. C program, and should be written as follows.
  28. C
  29. C SUBROUTINE FCN(IFLAG,M,N,X,FVEC,FJAC,LDFJAC)
  30. C INTEGER LDFJAC,M,N,IFLAG
  31. C DOUBLE PRECISION X(N),FVEC(M),FJAC(LDFJAC,N)
  32. C ----------
  33. C When IFLAG.EQ.1 calculate the functions at X and
  34. C return this vector in FVEC.
  35. C ----------
  36. C RETURN
  37. C END
  38. C
  39. C The value of IFLAG should not be changed by FCN unless
  40. C the user wants to terminate execution of DFDJC3.
  41. C In this case set IFLAG to a negative integer.
  42. C
  43. C M is a positive integer input variable set to the number
  44. C of functions.
  45. C
  46. C N is a positive integer input variable set to the number
  47. C of variables. N must not exceed M.
  48. C
  49. C X is an input array of length N.
  50. C
  51. C FVEC is an input array of length M which must contain the
  52. C functions evaluated at X.
  53. C
  54. C FJAC is an output M by N array which contains the
  55. C approximation to the Jacobian matrix evaluated at X.
  56. C
  57. C LDFJAC is a positive integer input variable not less than M
  58. C which specifies the leading dimension of the array FJAC.
  59. C
  60. C IFLAG is an integer variable which can be used to terminate
  61. C THE EXECUTION OF DFDJC3. See description of FCN.
  62. C
  63. C EPSFCN is an input variable used in determining a suitable
  64. C step length for the forward-difference approximation. This
  65. C approximation assumes that the relative errors in the
  66. C functions are of the order of EPSFCN. If EPSFCN is less
  67. C than the machine precision, it is assumed that the relative
  68. C errors in the functions are of the order of the machine
  69. C precision.
  70. C
  71. C WA is a work array of length M.
  72. C
  73. C***SEE ALSO DNLS1, DNLS1E
  74. C***ROUTINES CALLED D1MACH
  75. C***REVISION HISTORY (YYMMDD)
  76. C 800301 DATE WRITTEN
  77. C 890531 Changed all specific intrinsics to generic. (WRB)
  78. C 890831 Modified array declarations. (WRB)
  79. C 891214 Prologue converted to Version 4.0 format. (BAB)
  80. C 900326 Removed duplicate information from DESCRIPTION section.
  81. C (WRB)
  82. C 900328 Added TYPE section. (WRB)
  83. C***END PROLOGUE DFDJC3
  84. INTEGER M,N,LDFJAC,IFLAG
  85. DOUBLE PRECISION EPSFCN
  86. DOUBLE PRECISION X(*),FVEC(*),FJAC(LDFJAC,*),WA(*)
  87. INTEGER I,J
  88. DOUBLE PRECISION EPS,EPSMCH,H,TEMP,ZERO
  89. DOUBLE PRECISION D1MACH
  90. SAVE ZERO
  91. DATA ZERO /0.0D0/
  92. C***FIRST EXECUTABLE STATEMENT DFDJC3
  93. EPSMCH = D1MACH(4)
  94. C
  95. EPS = SQRT(MAX(EPSFCN,EPSMCH))
  96. C SET IFLAG=1 TO INDICATE THAT FUNCTION VALUES
  97. C ARE TO BE RETURNED BY FCN.
  98. IFLAG = 1
  99. DO 20 J = 1, N
  100. TEMP = X(J)
  101. H = EPS*ABS(TEMP)
  102. IF (H .EQ. ZERO) H = EPS
  103. X(J) = TEMP + H
  104. CALL FCN(IFLAG,M,N,X,WA,FJAC,LDFJAC)
  105. IF (IFLAG .LT. 0) GO TO 30
  106. X(J) = TEMP
  107. DO 10 I = 1, M
  108. FJAC(I,J) = (WA(I) - FVEC(I))/H
  109. 10 CONTINUE
  110. 20 CONTINUE
  111. 30 CONTINUE
  112. RETURN
  113. C
  114. C LAST CARD OF SUBROUTINE DFDJC3.
  115. C
  116. END