Chapter 14, Section 6
Directional Derivatives and the Gradient
Andy Long
Spring, 2016

f[x_,y_]= x^2+ x y + 3y^2;
PlotA=ContourPlot[f[x,y],{x,0,2},{y,0,2}];
PlotB=VectorPlot[Evaluate[D[f[x,y],{{x,y}}]],{x,0,2},{y,0,2}];
Show[{PlotA,PlotB}]

#5, p. 967

f[x_,y_]=  y E^(-x);
gradf[x_,y_]=D[f[x,y],{{x,y}}]
th=2Pi/3
InnerProduct=Dot[gradf[0,4],{Cos[th],Sin[th]}]
N[%]

The following piece of code starts with parameters appropriate for the given function. The center of the graphic is (xp,yp), and the width and height parameters give the limits of the window to examine.

f[x_,y_]=  y E^(-x);
gradf[x_,y_]=D[f[x,y],{{x,y}}]
xp=0;
yp=4;
width=2;
height=2;
Manipulate[
(* directional derivative in the direction of theta: *)
g=Dot[gradf[xp,yp],{Cos[th],Sin[th]}];
(* The components of the unit vector: *)
cos=ToString[Cos[th]];
sin=ToString[Sin[th]];
(* the graph window *)
xmin=xp-width*c;
xmax=xp+width*c;
ymin=yp-height*c;
ymax=yp+height*c;
(* Some more labels *)
label=StringJoin["Directional Derivative = ",ToString[g],"; angle = ",ToString[N[th]]];
Plota=ContourPlot[f[x,y]
,{x,xmin,xmax},{y,ymin,ymax}
,PlotLabel->label
,FrameLabel->{StringJoin["Cos[th] = ",cos],StringJoin["Sin[th] = ",sin]}];
Plotb=VectorPlot[gradf[x,y],{x,xmin,xmax},{y,ymin,ymax}];
Plotc=Graphics[Arrow[{{xp,yp},{xp+Cos[th],yp+Sin[th]}}]];
Show[Plota,Plotb,Plotc]
,{{c,1,"scale"},0.01,1}
,{{th,Pi/2,"angle"},0,2Pi}
]

#7, p. 967

f[x_,y_]= Sin[2x+3y];
gradf[x_,y_]=D[f[x,y],{{x,y}}]
xp=-6;
yp=4;
u={Sqrt[3],-1}/2
uhat=u/Norm[u]
a=uhat[[1]]
b=uhat[[2]]
gradf[a,b]
InnerProduct=Dot[gradf[a,b],{a,b}]
N[%]
width=2;
height=2;
Manipulate[
(* directional derivative in the direction of theta: *)
g=Dot[gradf[xp,yp],{Cos[th],Sin[th]}];
(* The components of the unit vector: *)
cos=ToString[Cos[th]];
sin=ToString[Sin[th]];
(* the graph window *)
xmin=xp-width*c;
xmax=xp+width*c;
ymin=yp-height*c;
ymax=yp+height*c;
(* Some more labels *)
label=StringJoin["Directional Derivative = ",ToString[g],"; angle = ",ToString[N[th]]];
Plota=ContourPlot[f[x,y]
,{x,xmin,xmax},{y,ymin,ymax}
,PlotLabel->label
,FrameLabel->{StringJoin["Cos[th] = ",cos],StringJoin["Sin[th] = ",sin]}];
Plotb=VectorPlot[gradf[x,y],{x,xmin,xmax},{y,ymin,ymax}];
Plotc=Graphics[Arrow[{{xp,yp},{xp+Cos[th],yp+Sin[th]}}]];
Show[Plota,Plotb,Plotc]
,{{c,1,"scale"},0.01,1}
,{{th,Pi/2,"angle"},0,2Pi}
]