Function Repository Resource:

DirectionalDerivativePlot3D

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

Setting "SectionStyle"Tube[0] will suppress drawing the section.
Setting "DrawGraph"False will suppress the plot and return the directional derivative.
ResourceFunction["DirectionalDerivativePlot3D"] has the following options in addition to those for the resource function SectionPlot3D and Plot3D:
"ArrowSize"Mediumsize of the arrowhead
"BaseVectorPosition"Automaticdetermines the position of the base vector if drawn
"DrawBaseVector"Falsewhether to draw the base vector
"DrawGraph"Truewhether to include the plot of the surface
"DrawPlane"Falsewhether to include the plane determining the section
"PointStyle"PointSize[Large]graphics directive to specify the style for the point(s)
"PrintDisplay"Falsewhether to print the value of the directional derivative
"SectionStyle"{{Tube[0.01],Black}}style for the section determined by the direction vector
"UseLimit"Falsewhether to use the limit definition to calculate the directional derivative
"VectorStyle"{{Thickness[Medium],Red}}graphics directive to specify the style for the vector(s)

Examples

Basic Examples (1) 

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]=

Scope (13) 

Suppress drawing the section curve:

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]}, "SectionStyle" -> Tube[0]]
Out[2]=

Plot using two direction vectors:

In[3]:=
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, 0}}]
Out[3]=

Include a print of the values of the directional derivatives:

In[4]:=
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, 0}}, "PrintDisplay" -> True]
Out[4]=

Return just a print of the points and the directional derivatives:

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]}, {1, 0}}, "DrawGraph" -> False]
Out[5]=

Plot using two direction vectors and two points:

In[6]:=
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, 0}}]
Out[6]=

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

In[7]:=
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[7]=

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

In[8]:=
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[8]=

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

In[9]:=
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[9]=

Set a style for the vectors:

In[10]:=
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 -> {{Thickness[Large], Red}, Green}, PlotStyle -> Opacity[.6], Mesh -> None]
Out[10]=

Add the base vectors and lower their position:

In[11]:=
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[11]=

A function requiring both "UseLimit” and ResourceFunction["UseRealRoots"]:

In[12]:=
ResourceFunction["DirectionalDerivativePlot3D"][(x y^2)^(
  1/3), {x, -1.2, 1.2}, {y, -1.2, 1.2}, {0, 0}, {-1, -1}, "UseLimit" -> True, Mesh -> None, PlotStyle -> Opacity[.5], "DrawBaseVector" -> True, "PrintDisplay" -> True] // ResourceFunction["UseRealRoots"]
Out[12]=

Without using ResourceFunction["UseRealRoots"]:

In[13]:=
Quiet[ResourceFunction["DirectionalDerivativePlot3D"][(x y^2)^(
  1/3), {x, -1.2, 1.2}, {y, -1.2, 1.2}, {0, 0}, {-1, -1}, Mesh -> None, PlotStyle -> Opacity[.5], "DrawBaseVector" -> True, "PrintDisplay" -> True]]
Out[13]=

Without using the option "UseLimit":

In[14]:=
Quiet[ResourceFunction["DirectionalDerivativePlot3D"][(x y^2)^(
   1/3), {x, -1.2, 1.2}, {y, -1.2, 1.2}, {0, 0}, {-1, -1}, Mesh -> None, PlotStyle -> Opacity[.5], "DrawBaseVector" -> True, "PrintDisplay" -> True] // ResourceFunction["UseRealRoots"]]
Out[14]=

Another function requiring the option "UseLimit” and ResourceFunction["UseRealRoots"]:

In[15]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/8e7b4e59-2d68-4788-a2f0-e4d00c6c8936"]
Out[16]=

Publisher

Dennis M Schneider

Version History

  • 1.1.0 – 11 July 2022
  • 1.0.1 – 15 January 2021
  • 1.0.0 – 16 September 2020

Related Resources

License Information