The IMSL_FCN_DERIV function computes the first, second, or third derivative of a user-supplied function.

The IMSL_FCN_DERIV function produces an estimate to the first, second, or third derivative of a function. The estimate originates from first computing a spline interpolant to the input function using values within the interval (x – 4.0*STEPSIZE, x + 4.0*STEPSIZE), then differentiating the spline at x.

## Examples

### Example 1

This example obtains the approximate first derivative of the function

`f(x) = –2sin(3x/2) at the point x = 2.`
`  FUNCTION fcn, x`
`  f	= -2*SIN(1.5*x) RETURN,	f`
`END`
` `
`deriv1 = IMSL_FCN_DERIV('fcn', 2.0)`
`PRINT, "f'(x)	= ", deriv1`
`f'(x)	=	2.97008`

### Example 2

This example obtains the approximate first, second, and third derivative of the function f(x) = –2sin(3x/2) at the point x = 2.

`FUNCTION fcn,	x`
`f	=	-2*SIN(1.5*x)`
`RETURN,	f`
`END`
` `
`deriv1 = IMSL_FCN_DERIV('fcn', 2.0, /Double)`
`deriv2 = IMSL_FCN_DERIV('fcn', 2.0, ORDER = 2, /Double)`
`deriv3 = IMSL_FCN_DERIV('fcn', 2.0, ORDER = 3, /Double)`
`PRINT, "f'(x)   = ", deriv1, ',  error =', \$`
`  ABS(deriv1 + 3.0*COS(1.5*2.0))`
`f'(x)  =        2.9699775,  error =  1.1094893e-07`
`PRINT, "f''(x)	= ", deriv2, ',	error =', \$`
`  ABS(deriv2 - 4.5*SIN(1.5*2.0))`
`f''(x) =       0.63504004,  error =  5.1086361e-08`
`PRINT, "f'''(x) = ", deriv3, ',	error =', \$`
`  ABS(deriv3 - 6.75*COS(1.5*2.0))`
`f'''(x) =       -6.6824494,  error =  1.1606068e-08`

## Syntax

Result = IMSL_FCN_DERIV(F, X [, /DOUBLE] [, ORDER=value] [, STEPSIZE=value] [, TOLERANCE=value])

## Return Value

An estimate of the first, second or third derivative of f at x. If no value can be computed, NaN is returned.

## Arguments

### F

A scalar string specifying a user-supplied function whose derivative at X will be computed.

### X

The point at which the derivative will be evaluated.

## Keywords

### DOUBLE (optional)

If present and nonzero, then double precision is used.

### ORDER (optional)

Set this keyword equal to the order of the desired derivative (1, 2 or 3). Default: 1

### STEPSIZE (optional)

Set this keyword equal to the beginning value used to compute the size of the interval for approximating the derivative. STEPSIZE must be chosen small enough that f is defined and reasonably smooth in the interval (x – 4.0*STEPSIZE, x + 4.0*STEPSIZE), yet large enough to avoid roundoff problems. Default: 0.01

### TOLERANCE (optional)

Set this keyword equal to the relative error desired in the derivative estimate. Convergence is assumed when (2/3) |d2d1| < TOLERANCE, for two successive derivative estimates, d1 and d2. The default is , where ε is machine epsilon.

## Version History

 6.4 Introduced