Function Repository Resource:

# DirectionalDerivative

Compute the directional derivative of a function at a point

Contributed by: Dennis M Schneider
 ResourceFunction["DirectionalDerivative"][f,vars,pt,v] computes the directional derivative of the function f of the variables vars at the point pt in the direction of the normalized vector v.

## Details and Options

When the function is differentiable at a point (a1,a2,), then the directional derivative at (a1,a2,) in a direction can be calculated using the formula where is a unit vector.
The formula for the directional derivative at a point (a1,a2,) requires that the function be differentiable at the point (a1,a2,). Setting the option "UseLimit" to true allows the computation of the directional derivative for non-differentiable functions.
If the formula is applied to a function whose gradient at a point is 0, then it will return 0 independent of the specified direction.

## Examples

### Basic Examples (2)

The directional derivative of a function of two variables at the point (1,-2) in the direction of the unit vector :

 In[1]:=
 Out[1]=

The directional derivative of the same function at a general point (a,b) in a general direction (cos(α),sin(α)):

 In[2]:=
 Out[2]=

### Scope (6)

Find the directional derivative of a function of four variables:

 In[3]:=
 Out[3]=

Since the following function is not differentiable at (0,0), it is necessary to use the limit definition to correctly calculate the directional derivative:

 In[4]:=
 Out[5]=

Calculate the gradient of this function at the origin:

 In[6]:=
 Out[7]=

 In[8]:=
 Out[8]=

Since the gradient of this function at (0,0) is (0,0), without setting "UseLimit"->True, the formula returns 0 no matter the direction :

 In[9]:=
 Out[10]=

A function that does not have a directional derivative except in the x and y directions:

 In[11]:=
 Out[12]=

A function requiring both "UseLimit" and "UseRealRoots":

 In[13]:=
 Out[3]=

Without using "UseRealRoots":

 In[14]:=
 Out[14]=

Without using Limit:

 In[15]:=
 Out[15]=

## Publisher

Dennis M Schneider

## Version History

• 1.0.0 – 20 July 2022