IMSL_FCN_DERIV

Syntax | Return Value | Arguments | Keywords | Discussion | Examples | Version History

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

Note
This routine requires an IDL Advanced Math and Stats license. For more information, contact your ITT Visual Information Solutions sales or technical support representative.

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

Set this keyword to perform computations using double precision.

ORDER

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

STEPSIZE

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: STEPSIZE = 0.01

TOLERANCE

Set this keyword equal to the relative error desired in the derivative estimate. Convergence is assumed when (2/3) |d2 – d1| < TOLERANCE, for two successive derivative estimates, d1 and d2. Default: TOLERANCE = IMSL_FCN_DERIV-49.jpg where ε is machine epsilon.

Discussion

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 

Version History

6.4

Introduced