fderivative

Derivative of a univariate, vector-valued function using the forward difference approximation.

Back to Numerical Differentiation Toolbox Contents.

Contents

Syntax

df = fderivative(f,x0)
df = fderivative(f,x0,h)

Description

df = fderivative(f,x0) numerically evaluates the derivative of $\mathbf{f}$ with respect to $x$ at $x=x_{0}$ using the forward difference approximation with a default relative step size of $h=\sqrt{\varepsilon}$, where $\varepsilon$ is the machine zero.

df = fderivative(f,x0,h) numerically evaluates the derivative of $\mathbf{f}$ with respect to $x$ at $x=x_{0}$ using the forward difference approximation with a user-specified relative step size $h$.

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 ) 1×1
double
Output df derivative of with respect to , evaluated at m×1
double

Note

Example #1: Derivative of a scalar-valued function.

Approximate the derivative of $f(x)=x^{3}$ at $x=2$ using the fderivative function, and compare the result to the true result of $f'(2)=12$.

Approximating the derivative,

f = @(x) x^3;
df = fderivative(f,2)
df =

   12.0000

Calculating the error,

error = df-12
error =

   2.7816e-07

Example #2: Derivative of a vector-valued function.

Approximate the derivative of

$$\mathbf{f}(t)=\pmatrix{\sin{t}\cr\cos{t}}$$

at $t=1$ using the fderivative function, and compare the result to the true result of

$$\left.\frac{d\mathbf{f}}{dt}\right|_{t=1}=\pmatrix{\cos{(1)}\cr-\sin{(1)}}$$

Approximating the derivative,

f = @(t) [sin(t);cos(t)];
df = fderivative(f,1)
df =

    0.5403
   -0.8415

Calculating the error,

error = df-[cos(1);-sin(1)]
error =

   1.0e-07 *

   -0.1436
   -0.0925

See also

cderivative | iderivative