FDGRD
Approximates the gradient using forward differences.
Required Arguments
FCN — User-supplied subroutine to evaluate the function to be minimized. The usage is CALL FCN (NXF), where
N – Length of X. (Input)
X – The point at which the function is evaluated. (Input)
X should not be changed by FCN.
F – The computed function value at the point X. (Output)
FCN must be declared EXTERNAL in the calling program.
XC — Vector of length N containing the point at which the gradient is to be estimated. (Input)
FC — Scalar containing the value of the function at XC. (Input)
GC — Vector of length N containing the estimated gradient at XC. (Output)
Optional Arguments
N — Dimension of the problem. (Input)
Default: N = SIZE (XC,1).
XSCALE — Vector of length N containing the diagonal scaling matrix for the variables. (Input)
In the absence of other information, set all entries to 1.0.
Default: XSCALE = 1.0.
EPSFCN — Estimate of the relative noise in the function. (Input)
EPSFCN must be less than or equal to 0.1. In the absence of other information, set EPSFCN to 0.0.
Default: EPSFCN = 0.0.
FORTRAN 90 Interface
Generic: CALL FDGRD (FCN, XC, FC, GC [])
Specific: The specific interface names are S_FDGRD and D_FDGRD.
FORTRAN 77 Interface
Single: CALL FDGRD (FCN, N, XC, XSCALE, FC, EPSFCN GC)
Double: The double precision name is DFDGRD.
Description
The routine FDGRD uses the following finite-difference formula to estimate the gradient of a function of n variables at x:
where hi = ɛ1/2  max{xi, 1/si} sign(xi), ɛ is the machine epsilon, ei is the i-th unit vector, and si is the scaling factor of the i-th variable. For more details, see Dennis and Schnabel (1983).
Since the finite-difference method has truncation error, cancellation error, and rounding error, users should be aware of possible poor performance. When possible, high precision arithmetic is recommended. When accuracy of the gradient is important, IMSL routine CDGRD should be used.
Comments
This is Description A5.6.3, Dennis and Schnabel, 1983, page 322.
Example
In this example, the gradient of f(x) = x1  x1 x2  2 is estimated by the finite-difference method at the point (1.0, 1.0).
 
USE FDGRD_INT
USE UMACH_INT
 
IMPLICIT NONE
INTEGER I, N, NOUT
PARAMETER (N=2)
REAL EPSFCN, FC, GC(N), XC(N)
EXTERNAL FCN
! Initialization.
DATA XC/2*1.0E0/
! Set function noise.
EPSFCN = 0.01
! Get function value at current
! point.
CALL FCN (N, XC, FC)
!
CALL FDGRD (FCN, XC, FC, GC, EPSFCN=EPSFCN)
!
CALL UMACH (2, NOUT)
WRITE (NOUT,99999) (GC(I),I=1,N)
99999 FORMAT (’ The gradient is’, 2F8.2, /)
!
END
!
SUBROUTINE FCN (N, X, F)
INTEGER N
REAL X(N), F
!
F = X(1) - X(1)*X(2) - 2.0E0
!
RETURN
END
Output
 
The gradient is 0.00 -1.00