fdirectional
Directional derivative of a multivariate, scalarvalued function using the forward difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
Dv = fdirectional(f,x0,v) Dv = fdirectional(f,x0,v,h)
Description
Dv = fdirectional(f,x0,v) numerically evaluates the directional derivative of with respect to at in the direction of using the forward difference approximation with a default relative step size of , where is the machine zero.
Dv = fdirectional(f,x0,v,h) numerically evaluates the directional derivative of with respect to at in the direction of using the forward difference approximation with a userspecified relative step size .
Input/Output Parameters
Variable  Symbol  Description  Format  
Input  f  multivariate, scalarvalued function ()  1×1 function_handle 

x0  evaluation point  n×1 double 

v  vector defining direction of differentiation  n×1 double 

h  (OPTIONAL) relative step size  1×1 double 

Output  Dv  directional derivative of with respect to in the direction of , evaluated at  1×1 double 
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 fdirectional 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 = fdirectional(f,x0,v)
Dv = 3.1241e+04
Calculating the error,
error = Dv(31250+60*sin(8)^2*cos(8))
error = 0.0019