The type double procedure is imsl_d_fcn_derivative.
Required Arguments
floatfcn(floatx) (Input) User-supplied function whose derivative at x will be computed.
floatx (Input) Point at which the derivative will be evaluated.
Return Value
An estimate of the first, second or third derivative of fcn at x. If no value can be computed, NaN is returned.
Synopsis with Optional Arguments
#include<imsl.h>
float imsl_f_fcn_derivative (floatfcn(), floatx,
IMSL_ORDER, intorder,
IMSL_INITIAL_STEPSIZE, floatstepize,
IMSL_RELATIVE_ERROR, floattolerance,
IMSL_FCN_W_DATA, float fcn(), void*data,
0)
Optional Arguments
IMSL_ORDER, intorder (Input) The order of the desired derivative (1, 2 or 3). Default: order = 1.
IMSL_INITIAL_STEPSIZE, floatstepsize (Input) Beginning value used to compute the size of the interval for approximating the derivative. Stepsize must be chosen small enough that fcn 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
IMSL_RELATIVE_ERROR, floattolerance (Input) 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 = where ɛ is the machine precision.
IMSL_FCN_W_DATA, floatfcn(floatx, void*data), void*data (Input) User supplied function whose derivative at x will be computed, which also accepts a pointer to data that is supplied by the user. data is a pointer to the data to be passed to the user-supplied function. See Passing Data to User-Supplied Functions in the introduction to this manual for more details.
Description
The function imsl_f_fcn_derivative 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 value 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.
#include <imsl.h>
#include <stdio.h>
#include <math.h>
int main()
{
float fcn(float);
float x;
float deriv;
x = 2.0;
deriv = imsl_f_fcn_derivative(fcn, x, 0);
printf ("f’(x) = %7.4f\n", deriv);
}
float fcn(float x)
{
return -2.0*sin(1.5*x);
}
Output
f’(x) = 2.9701
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.