complexstep: Complex Step Derivatives In pracma: Practical Numerical Math Functions

Description

Complex step derivatives of real-valued functions, including gradients, Jacobians, and Hessians.

Usage

 1 2 3 4 5 6 complexstep(f, x0, h = 1e-20, ...) grad_csd(f, x0, h = 1e-20, ...) jacobian_csd(f, x0, h = 1e-20, ...) hessian_csd(f, x0, h = 1e-20, ...) laplacian_csd(f, x0, h = 1e-20, ...)

Arguments

 f Function that is to be differentiated. x0 Point at which to differentiate the function. h Step size to be applied; shall be very small. ... Additional variables to be passed to f.

Details

Complex step derivation is a fast and highly exact way of numerically differentiating a function. If the following conditions are satisfied, there will be no loss of accuracy between computing a function value and computing the derivative at a certain point.

• f must have an analytical (i.e., complex differentiable) continuation into an open neighborhood of x0.

• x0 and f(x0) must be real.

• h is real and very small: 0 < h << 1.

complexstep handles differentiation of univariate functions, while grad_csd and jacobian_csd compute gradients and Jacobians by applying the complex step approach iteratively. Please understand that these functions are not vectorized, but complexstep is.

As complex step cannot be applied twice (the first derivative does not fullfil the conditions), hessian_csd works differently. For the first derivation, complex step is used, to the one time derived function Richardson's method is applied. The same applies to lapalacian_csd.

Value

complexstep(f, x0) returns the derivative f'(x_0) of f at x_0. The function is vectorized in x0.

Note

This surprising approach can be easily deduced from the complex-analytic Taylor formula.

References

Martins, J. R. R. A., P. Sturdza, and J. J. Alonso (2003). The Complex-step Derivative Approximation. ACM Transactions on Mathematical Software, Vol. 29, No. 3, pp. 245–262.