Wolfram Research

Function Repository Resource:

DirectionalDerivativePlot3D (1.0.1) current version: 1.1.0 »

Source Notebook

Visualize the directional derivative in a 3D plot

Contributed by: Dennis M Schneider

ResourceFunction["DirectionalDerivativePlot3D"][f,{x,xmin,xmax},{y,ymin,ymax},pt,v]]]

returns a plot of f along with a plot of the directional derivative vector at the point pt in the direction of the vector v. Several points and/or vectors can be given in a list.

Details and Options

ResourceFunction["DirectionalDerivativePlot3D"] has the following options in addition to those for the resource function SectionPlot3D and Plot3D:
"ArrowSize" Medium changes the arrow size
"BaseVectorPosition" Automatic determines the position of the base vector if drawn
"DrawBaseVector" False whether to draw the base vector
"DrawPlane" False whether to draw the plane determining the section
"SectionStyle" { { Red , Thickness [ Medium ] } } style for the section
"PointStyle" PointSize [ Large ] graphics directive to specify the style for the point(s)
"UseLimit" False whether to use the limit definition to calculate the directional derivative
"VectorStyle" { { Red , Thickness [ Medium ] } } graphics directive to specify the style for the vector(s)

Examples

Basic Examples (9) 

Visualize a directional derivative:

In[1]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {0, -2}, {Cos[\[Pi]/4], Sin[\[Pi]/4]}]
Out[1]=

Plot using two direction vectors:

In[2]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {0, -2}, {{Cos[\[Pi]/4], Sin[\[Pi]/4]}, {1, 4}}]
Out[2]=

Plot using two direction vectors and two points:

In[3]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {{0, -2}, {1, -1/2}}, {{Cos[\[Pi]/4], Sin[\[Pi]/4]}, {1, 4}}]
Out[3]=

If "DrawBaseVector" is set to True, then the vector determining the direction is plotted at the bottom of the plot:

In[4]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {{0, -2}, {1, 0}}, {Cos[\[Pi]/4], Sin[\[Pi]/4]}, "DrawBaseVector" -> True]
Out[4]=

Include the plane determining the section along with the base vector in the plot:

In[5]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {0, -2}, {Cos[\[Pi]/4], Sin[\[Pi]/4]}, "PointStyle" -> PointSize[Large], "DrawBaseVector" -> True, "DrawPlane" -> True]
Out[5]=

The option "BaseVectorPosition" allows the vector to be plotted in any plane:

In[6]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 9 - x^2/2 - y^2/2, {x, -2.2, 2.2}, {y, -2.2, 2.2}, {0, -2}, {Cos[\[Pi]/4], Sin[\[Pi]/4]}, "DrawBaseVector" -> True, "BaseVectorPosition" -> (9 - x^2/2 - y^2/2 /. {x -> 0, y -> -2})]
Out[6]=

Set a style for the vectors:

In[7]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 Sin[\[Pi] x y], {x, -1, 1}, {y, -1, 1}, {1/2, 1/2}, {{1, 2}, {1, 0}},
  "PointStyle" -> {{PointSize[.025], Green}}, PlotRange -> All, VectorStyle -> {Red, Green}, PlotStyle -> Opacity[.6], Mesh -> None]
Out[7]=

Add the base vectors and lower their position:

In[8]:=
ResourceFunction["DirectionalDerivativePlot3D"][
 Sin[\[Pi] x y], {x, -1, 1}, {y, -1, 1}, {1/2, 1/2}, {{1, 2}, {1, 0}},
  "PointStyle" -> {{PointSize[.025], Green}}, PlotRange -> All, VectorStyle -> {Red, Green}, PlotStyle -> Opacity[.6], Mesh -> None, "DrawBaseVector" -> True, "BaseVectorPosition" -> -3]
Out[8]=

Limits are sometimes required to find the directional derivative of the following function:

In[9]:=
Clear[f]
f[x_, y_] := 1 - (x^2 y^2)/(x^4 + y^2) + (2 x)/3
f[0, 0] := 1
GraphicsRow[{ResourceFunction["DirectionalDerivativePlot3D"][
   f[x, y], {x, -1.2, 1.2}, {y, -1.2, 1.2}, {0, 0}, {2, 1}, "UseLimit" -> True, Mesh -> None, PlotStyle -> Opacity[.5], "DrawBaseVector" -> True, "BaseVectorPosition" -> 1], ResourceFunction["DirectionalDerivativePlot3D"][
   f[x, y], {x, -2, 2}, {y, -2, 2}, {0, 0}, {2, 1}, Mesh -> None, PlotStyle -> Opacity[.5], "DrawBaseVector" -> True, "BaseVectorPosition" -> 1]}]
Out[12]=

Check that the directional derivative is not 0:

In[13]:=
(f @@ ({0, 0} + h/Sqrt[5] {2, 1}) - f[0, 0])/h // Simplify
Out[13]=
In[14]:=
Limit[(f @@ ({0, 0} + h/Sqrt[5] {2, 1}) - f[0, 0])/h, h -> 0]
Out[14]=

Version History

  • 1.1.0 – 11 July 2022
  • 1.0.1 – 15 January 2021

Related Resources

License Information