cderivative
Derivative of a univariate, vector-valued function using the central difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
df = cderivative(f,x0) df = cderivative(f,x0,h)
Description
df = cderivative(f,x0) numerically evaluates the derivative of with respect to
at
using the central difference approximation with a default relative step size of
, where
is the machine zero.
df = cderivative(f,x0,h) numerically evaluates the derivative of with respect to
at
using the central difference approximation with a user-specified relative step size
.
Input/Output Parameters
Variable | Symbol | Description | Format | |
Input | f | univariate, vector-valued function ( |
1×1 function_handle |
|
x0 | evaluation point | 1×1 double |
||
h | (OPTIONAL) relative step size (defaults to $h=\varepsilon^{1/3}$) | 1×1 double |
||
Output | df | derivative of |
m×1 double |
Note
- This function requires 2 evaluations of
.
Example #1: Derivative of a scalar-valued function.
Approximate the derivative of at
using the cderivative function, and compare the result to the true result of
.
Approximating the derivative,
f = @(x) x^3; df = cderivative(f,2)
df = 12.0000
Calculating the error,
error = df-12
error = 3.3153e-10
Example #2: Derivative of a vector-valued function.
Approximate the derivative of
at using the cderivative function, and compare the result to the true result of
Approximating the derivative,
f = @(t) [sin(t);cos(t)]; df = cderivative(f,1)
df = 0.5403 -0.8415
Calculating the error,
error = df-[cos(1);-sin(1)]
error = 1.0e-10 * -0.1420 0.1959