# cdirectional

Directional derivative of a multivariate, scalar-valued function using the central difference approximation.

## Syntax

Dv = cdirectional(f,x0,v)
Dv = cdirectional(f,x0,v,h)


## Description

Dv = cdirectional(f,x0,v) numerically evaluates the directional derivative of with respect to at in the direction of using the central difference approximation with a default relative step size of , where is the machine zero.

Dv = cdirectional(f,x0,v,h) numerically evaluates the directional derivative of with respect to at in the direction of using the central difference approximation with a user-specified relative step size .

## Input/Output Parameters

 Variable Symbol Description Format Input f $\inline&space;f(\mathbf{x})$ multivariate, scalar-valued function ($\inline&space;f:\mathbb{R}^{n}\rightarrow\mathbb{R}$) 1×1function_handle x0 $\inline&space;\mathbf{x}_{0}$ evaluation point n×1double v $\inline&space;\mathbf{v}$ vector defining direction of differentiation n×1double h $\inline&space;h$ (OPTIONAL) relative step size 1×1double Output Dv $\inline&space;\nabla_{\mathbf{v}}f(\mathbf{x}_{0})=\nabla f(\mathbf{x}_{0})^{T}\mathbf{v}$ directional derivative of $\inline&space;f$ with respect to $\inline&space;\mathbf{x}$ in the direction of $\inline&space;\mathbf{v}$, evaluated at $\inline&space;\mathbf{x}=\mathbf{x}_{0}$ 1×1double

## Note

• This function requires evaluations of .
• This implementation does not assume that is a unit vector.

## Example

Approximate the directional derivative of at in the direction of using the cdirectional function, and compare the result to the true result of .

Approximating the directional derivative,

f = @(x) x(1)^5+sin(x(2))^3;
x0 = [5;8];
v = [10;20];
Dv = cdirectional(f,x0,v)

Dv =

3.1241e+04



Calculating the error,

error = Dv-(31250+60*sin(8)^2*cos(8))

error =

9.1068e-06