Contents Previous Next Subchapters Current Chapters-> interp interp1 lagrange polyfit smospl cubespl cubeval interp2 mlmode_interp2 snewton brent linlsq linlsqb nlsq dnlsq nlsqbox dnlsqb conjdir neldermead conjgrad minline lemke Qpos Qbox Qpro sqp relative fordiff cendiff autodiff testder testgrad testhess Parent Chapters-> Omatrix6 fit cendiff Search Tools-> contents reference index search

Central Difference Derivative Approximation
 Syntax `cendiff(function `f`, `x`, `h`)` See Also fordiff

Description
Returns the central difference approximation for the Jacobian of f at x. The real or double-precision vector x specifies the point at which to approximate the Jacobian. The real or double-precision vector h specifies the step size for approximating the partials of f, and h has the same length as x. If `h(j)` is 0, partials with respect to `x(j)` are not approximated and 0 is returned in the corresponding column of the Jacobian. ``` ```A matrix function `J(x)` is the Jacobian of a column vector function `f(x)` if the `(i,j)` element of `J(x)` is the partial of the `i`th element of `f(x)` with respect to the `j`th element of `x`. ``` ```Given a real or double precision vector with the same dimension as x, the function f returns a real, double-precision, or complex column vector. The return value of `cendiff` has the type that results from coercion between the type of x, h and `f(x)`. It has the same number of rows as `f(x)` and its column dimension is equal to the length of x. ``` ```The functions `cendiff` and fordiff can be used to approximate derivatives for an optimization or zero-finding algorithm. The `cendiff` function is more accurate, but it requires more function evaluations.

Example ```      function f(x) begin           return x^2      end      x = 1.      h = .1      cendiff(function f, x, h) ``` returns ```      2 ```