Review of the Uses of
Partial Derivatives for 
Functions of Two Variables

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Special Functions Used in This NtBk

Vector Functions

We told you not to look.  This horrible stuff sets various defaults and defines some functions needed to draw the geometric side of the lexicon.  Ignore the details here and go on to the lesson.

Off[General::spell];
Off[General::spell1];
Off[ParametricPlot3D::ppcom]
Needs["Graphics`Colors`"]

SetOptions[Graphics,Axes->False,AxesOrigin->{0,0},AspectRatio->Automatic];
SetOptions[Graphics3D,ViewPoint->{5,2,1},Boxed->False,AspectRatio->Automatic];
SetOptions[ParametricPlot3D,ViewPoint->{5,2,1},AspectRatio->Automatic];
SetOptions[Plot3D,ViewPoint->{5,2,1},BoxRatios->{1,1,1}];
SetOptions[ParametricPlot,AspectRatio->Automatic];
SetOptions[Plot,AspectRatio->Automatic];

colorQ[a_]:=(Head[a]===RGBColor);
grayQ[a_]:=(Head[a]===GrayLevel);
thickQ[a_]:=(Head[a]===Thickness);
absthickQ[a_]:=(Head[a]===AbsoluteThickness);
notruleQ[u_] := !(Head[u]===Rule);
ruleQ[u_] := (Head[u]===Rule);

Norm::usage = "Norm[expr] returns the Euclidean length of the
		vector, 'expr'.";

Norm[a_?VectorQ] := Sqrt[a.a];

Angle[a_?VectorQ,b_?VectorQ] := ArcCos[(a.b)/(Norm[a] Norm[b])]

Proj[a_?VectorQ,b_?VectorQ] := ((a.b)/(b.b))b

tol = .5*10^-6;

OrthUp[a_?VectorQ] :=
	Module[{b,c,d,f},
		d = N[a/Norm[a]];
		If[Chop[d[[3]]^2 - 1,tol] == 0, b={1,0,0} ,
		b = {0,0,1} - d[[3]] d; b = b/Norm[b];];
	Return[b]];
	
OrthSet[a_?VectorQ] :=
	Module[{b,c,d},
		d = N[a/Norm[a]];
		If[Chop[d[[1]],tol]==0,b={1,0,0},
			 If[Chop[d[[2]],tol]==0,b={0,1,0},
			  b={-d[[2]],d[[1]],0}]];
			b=b/Norm[b];c = Cross[d,b];
	Return[{b,c/Norm[c],d}]];

				
Rotate[a_?VectorQ,theta_] :=
	Module[{u,v,r},
		u = OrthSet[a];
		v = Transpose[u];
		r = N[{{Cos[theta],-Sin[theta],0},{Sin[theta],Cos[theta],0},{0,0,1}}];
	Return[v.r.u]];

Vector2D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics[Point[{0,0}]]];
	,						
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (.075 Norm[ntip-ntail]/Norm[ntip-ntail]) (ntip-ntail) ;
	up = 0.15 {-Punit[[2]],Punit[[1]]};
	arrow = Line[{ntail,ntip,ntip-Punit+up,ntip,ntip-Punit-up}];
	]];
Return[Graphics[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

Vector3D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,u2,u3,u4,rotmat,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics3D[Point[{0,0,0}]]];					
	,		
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics3D[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (ntip-ntail);
	rotmat = Rotate[Punit,N[Pi/2]];
	up = OrthUp[Punit];
	Punit = .075 Punit;
	up = .15 Norm[Punit] up;
	u2 = rotmat.up;
	u3 = rotmat.u2;
	u4 = rotmat.u3;
	arrow = Line[{ntail,ntip,
				ntip - Punit + up,ntip,
				ntip - Punit + u2,ntip,
				ntip - Punit + u3,ntip,
				ntip - Punit + u4}];
	]];
Return[Graphics3D[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

aRCtAN[y_,x_] := Module[{v},
	If[ Chop[N[x],tol] == 0 ,If[ N[y] < 0, v = -N[Pi/2], v = N[Pi/2]],
		v = N[ArcTan[y/x]];
		If[ x < 0 && y < 0, v = N[Pi -  v],v]];
	Return[v]];

Arc2D[X_,Y_,opts___] := Graphics[{opts,
		Disk[{0,0},1,{Min[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]
						,
					Max[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]}
				]}
				];
Arc3D[X_,Y_] := 
	Module[{t,U,V},
		U[V_]:= N[(1/Sqrt[V.V]) V];
		Return[Graphics3D[
		Polygon[Append[Table[U[t X + (1-t) Y],{t,0,1,0.1}],{0,0,0}]]
				]
		]
	];

(*Zero Arrow causes trouble. Put in Vector?*)

Vector[tail_,tip_,opts___]:=
	If[Length[N[tail]]==2,Return[Vector2D[tail,tip,opts]],
		Return[Vector3D[tail,tip,opts]]];
		
Arrow[vec_,opts___]:= 
	Module[{a,b},
				If[Length[N[vec]]==2,
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0}};
				Return[Vector2D[a,a+vec,opts]],
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0,0}};
				Return[Vector3D[a,a+vec,opts]]]
				];

Frame2D[delta_] := 
      Graphics[{
            {Green,Line[{{-delta/4,0},{delta,0}}]},
                    Text["x",{1.01 delta,0}],
            {Green,Line[{{0,-delta/4},{0,delta}}]},
                    Text["y",{0, 1.01 delta}]}];

Frame3D[delta_] := 
      Graphics3D[{
            {Green,Line[{{-delta/4,0,0},{delta,0,0}}]},
                    Text["x",{1.01 delta,0,0}],
            {Green,Line[{{0,-delta/4,0},{0,delta,0}}]},
                    Text["y",{0, 1.01 delta,0}],
            {Green,Line[{{0,0,-delta/4},{0,0,delta}}]},
                    Text["z",{0,0,1.01 delta}]}];

View2D[stuff_] := Show[stuff,Frame2D[1]];
View3D[stuff_] := Show[stuff,Frame3D[1]];

The FlyBy Function

FlyBy[
	theGraphic_, 
	thePath_List:{pathVariable, -0.5, 1.5},
	pathRange_List:{pathVariable, -3, 3, 0.5}]:= 
	Do[
		Show[theGraphic, ViewPoint->thePath]
	,pathRange]

Review of the Theory

Use this NoteBook to review Chapter 18.

Partial derivatives are used several ways by giving:

(T) the total differential, which is the explicit equation of the tangent plane in local coordinates:

z = f[x,y]  =>  dz = ∂(f/∂)x[x, y] dx + ∂(f/∂)y[x, y] dy

(A) a (dx,dy)-linear approximation to a change in the function, with (x,y) fixed:

f[x+dx,y+dy] - f[x,y] ≈ ∂(f/∂)x[x, y] dx + ∂(f/∂)y[x, y] dy

(G) the gradient vector, which is the direction of fastest ascent on the contour plot, and also,

(C) the normal to the level curves on the contour plot:

G = ∇f[x,y] = (({{∂(f/∂)x[x, y]}, {∂(f/∂)y[x, y]}}))

(N) the normal vector to the tangent plane or explicit surface plot:

N = (({{-∂(f/∂)x[x, y]}, {-∂(f/∂)y[x, y]
	+1}}))

Of course there is a lot of in common, but these are different and you need to keep them separate.  They all work because of a single approximation:

f[x+dx,y+dy] - f[x,y] = ∂(f/∂)x[x, y]· dx + ∂(f/∂)y[x, y]· dy + ϵ · |(dx,dy)|

with  ϵ ≈ 0  when  dx ≈ 0 and  dy ≈ 0, wherever the partials can be computed by rules resulting in defined formulas.

One way to help keep them separate is to remember the general principle that the differential of an equation is the same sort of linear equation in local coordinates.  In other words, if you start with an explicit surface, you get an explicit plane from the differential, if you start with an implicit curve, you get an implicit line, and if you start with an implicit surface, you get an implicit plane.

Review of Procedures for Using Partial Derivatives:

The explicit surface  z = f[x,y]  has explicit tangent  dz = a dx + b dy

Use this procedure for finding the explicit tangent plane:

(0)  Begin with an explicit function  z = f[x,y].

(1)  Compute the symbolic partial derivatives  ∂(f/∂)x[x, y] & ∂(f/∂)y[x, y]

(2)  Evaluate the specific numbers  a = ∂(f/∂)x[x, y]  and  b = ∂(f/∂)y[x, y]  at the point of tangency (x,y) = (x1,y1).

(3)  In local (dx,dy,dz)- coordinates, the equation of the tangent plane is:

dz = a dx + b dy

Notice that this is an explicit linear function in (dx,dy,dz)-coordinates.

(4)  If desired, change coordinates back to (x,y,z) by replacing  dx -> (x - x1), dy -> (y - y1)  and  dz -> (z - f[x1,y1]), the tangent plane is:

z - z1 =  a (x - x1) + b (y - y1)
or
	z = f[x1,y1] + ∂(f/∂)x[x1,y1] (x - x1) + ∂(f/∂)y[x1,y1] (y - y1)

The important IDEA behind this procedure is that the calculations result in the "BEST LOCAL FIT" to the surface that is possible by a plane.  A geometrically simpler, and mathematically equivalent way to say that this formula is the tangent is to say that when you magnify a small portion of the graph, it looks more and more like the tangent plane.  The point of calculus is that we can predict in advance what the magnified surface will look like.

The tangent approximation:
 f[x+dx,y+dy] - f[x,y] = a dx + b dy + |{dx,dy}| ϵ,  
with  ϵ ≈ 0 when |{dx,dy}| ≈ 0.

Use this procedure to approximate a small change in a function:

(0)  Begin with an explicit function  z = f[x,y] that can be computed at (x1,y1),  z1 = f[x1,y1].

(1)  Compute the symbolic partial derivatives  ∂(f/∂)x[x, y] and ∂(f/∂)y[x, y]

(2)  Evaluate the specific numbers  a = ∂(f/∂)x[x, y]  and  b = ∂(f/∂)y[x, y]  at the known point (x,y) = (x1,y1).

(3)  In local (dx,dy,dz)- coordinates, the approximation FOR CHANGE is:

dz = a dx + b dy

Notice that this is an explicit linear function in (dx,dy,dz)-coordinates.

(4)  The CHANGE in f is approximately dz,

f[x1+dx,y1+dy] - f[x1,y1] = f[x+dx,y+dy] - f[x,y] = a dx + b dy + |{dx,dy}| ϵ,

with  ϵ ≈ 0 when |(dx,dy)| ≈ 0, so

f[x1+dx,y1+dy] ≈ z1 + a dx + b dy

with error  |{dx,dy}| ϵ.

Geometrically, this formula is the tangent which approximates the graph when you magnify a small portion of the graph.  Notice how similar this procedure is to the computation of the explicit tangent plane.

The gradient   grad f = {a,b}  is the direction of fastest ascent at (x1,y1)

Suppose we know the value of a function at {x1,y1},  z1 = f[x1,y1], and want to move in the  x-y-plane in the direction that will increase  f[x,y]  at the fastest rate.  The tangent approximation of the (above) says that for any small vector  {dx,dy},

f[x+dx,y+dy] - f[x,y] ≈ a dx + b dy = {a,b}.{dx,dy}

The dot product

{a,b}.{dx,dy} = |{a,b}| * |{dx,dy}| * Cos[ Angle[{a,b},{dx,dy}] ]

so the largest value of this expression is when the cosine of the angle is +1, the smallest is when the cosine of the angle is -1 and there is no INSTANTANEOUS change if {a,b} and {dx,dy} are perpendicular. In other words:

(1)  if you move {dx,dy} in the direction of {a,b} = Grad f[x1,y1], the norm,

|Grad f[x1,y1]| = the fastest rate of increase of  f[x,y]  at  (x1,y1)

(2)  if you move in the direction of -{a,b} = -Grad f[x1,y1], f decreases at the fastest rate,

-|Grad f[x1,y1]| = the fastest rate of decrease of  f[x,y]  at  (x1,y1)

(3)  if you move {dx,dy} perpendicular to {a,b} = Grad f[x1,y1], f only changes by the error,  |{dx,dy}| · ϵ, in other words, it changes by "zero to first order."

The gradient is perpendicular to the level curve.

The implicit CURVE: f[x,y] = z1 has implicit tangent LINE: a dx + b dy = 0

Use this procedure for finding the implicit tangent LINE:

(0)  Begin with an implicit equation   f[x,y] = z1,  with  z1 a constant,
        and a point {x1,y1} satisfying the equation  f[x1,y1] = z1.

(1)  Compute the symbolic partial derivatives  df/dx and df/dy.

(2)  Evaluate the specific numbers  a = df/dx  and  b = df/dy  at the point  (x1,y1).

(3)  In local (dx,dy,dz)- coordinates, the equation of the tangent line is:

a dx + b dy = 0

Notice that this is an implicit linear function in (dx,dy)-coordinates.

(4)  The implicit function theorem says that if you can solve this linear equation for one of the d-variables, say,  dy = -(a/b) dx, in case  b is not zero, then there is a nonlinear function  y = y[x] defined for at least a small domain of x-values satisfying  f[x,y[x] ] = z1,  or,

y = y[x]

is an explicit representation of a small piece of the curve and its total differential is

dy = -(a/b) dx

The implicit surface  z - f[x,y] = 0  has implicit tangent  dz - a dx - b dy = 0, or normal vector n = {-a,-b,1}.

Use this procedure for finding the implicit tangent plane:

(0)  Begin with an implicit equation   F[x,y,z] = w1,  with  w1 a constant, and a point {x1,y1,z1} satisfying the equation  F[x1,y1,z1] = w1.  
(In this case we take F[x,y,z] = z - f[x,y] and w1 = 0.)

(1)  Compute the symbolic partial derivatives  ∂F/∂x, ∂F/∂y  and  ∂F/∂z.
(In this particular case, ∂F/∂x = -∂f/∂x, ∂F/∂y = -∂f/∂y and ∂F/∂Z = +1.)

(2)  Evaluate the specific numbers  A = ∂F/∂x,  B = ∂F/∂y,  C = ∂F/∂z  at the point  (x1,y1,z1).  (In this particular case,  A = -a = -∂f/∂x[x1,y1]  and  B = -b = -∂f/∂y[x1,y1] and C = +1.)

(3)  In local (dx,dy,dz)- coordinates, the equation of the tangent plane is:

A dx + B dy + C dz = 0

Notice that this is an implicit linear function in (dx,dy,dz)-coordinates.

(4)  The implicit function theorem says that if you can solve this linear equation for one of the d-variables, say,  dz = -(A/C) dx - (B/C) dy, in case  C is not zero, then there is a nonlinear function  z = z[x,y] defined for at least a small domain of x-y-values satisfying  f[x,y,z[x,y] ] = w1,  or,

z = z[x,y]

is an explicit representation of a small piece of the surface and its total differential is

dz = -(A/C) dx - (B/C) dy

This is trivial in our case, because C = 1, dz = a dx + b dy and z = z[x.y] = f[x,y] is our original function.

A Step-by-step Example of an Explicit Tangent Plane

Compute each step of this example in order, first doing the computations by hand yourself.

Step (0): The Function

For step (0), sketch a plot of the surface  z =1 - (((x^2)/2) + ((y^2)/3)) by hand and then compare your sketch to Mathematica's drawing.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] := 1 - (((x^2)/2) + ((y^2)/3)); x1 = 1; y1 = -2; d = 5; z1 = f[x1, y1]; surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        AxesLabel -> {"x", "y", "z"}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30, 
        DisplayFunction -> Identity]; Show[surface, Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}], 
      DisplayFunction -> $DisplayFunction];

Step (1): The Partials,Gradient, and Total Derivative

Calculate the partial derivatives of this function by hand, write out the total derivative and then <enter> the Mathematica computation of them and compare:

\(pfpx[x_, \ y_]\  := \ Evaluate[D[f[x, \ y], \ x]]; \ 

    pfpy[x_, \ y_]\  := \ Evaluate[D[f[x, \ y], \ y]]; \ 

    Print["Partial ∂f/∂x = ", pfpx[x, y]]; 

    Print[" "]; 

    Print["Partial ∂f/∂y = ", pfpy[x, y]]; 

    Print["dz = ", pfpx[x, y], " dx + ", pfpy[x, y], " dy"]; \)

Step (2): Evaluating the Specific Slopes

In your hand computation, set  x1 = 1,  y1 = -2  and evaluate the partial derivatives, then write the specific differential  dz = a dx + b dy and <enter> the Mathematica version below.  Compare results.

dz[dx_, dy_] := pfpx[x1, y1] dx + pfpy[x1, y1] dy{x1, y1}dz[dx, dy]

Step (3): The Tangent Plane in Local Coordinates

Plot the specific differential  dz = a dx + b dy and <enter> the Mathematica version below.  Compare results.

Plot3D[dz[dx, dy], {dx, -d, d}, {dy, -d, d}, 
      PlotRange -> {-d, d}, PlotPoints -> 3, 
      AxesLabel -> {"dx", "dy", "dz"}];

Step (4): Both Graphs in (x,y,z) - Coordinates

Replace dx by (x - x1), dy by (y - y1) and dz by (z - f[x1,y1]) by hand and write out the specific equation z = z1 + a (x - x1) + b (y - y1).  Sketch both graphs together.  Compare results.

Clear[x, y]; Print["Tangent equation, z = ", dz[x - x1, y - y1] + z1]; plane = 
      Plot3D[dz[x - x1, y - y1] + z1, {x, x1 - (d/2), x1 + (d/2)}, {y, 
          y1 - (d/2), y1 + (d/2)}, PlotRange -> {z1 - d, z1 + d}, 
        PlotPoints -> 3, DisplayFunction -> Identity]; surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30, 
        DisplayFunction -> Identity]; Show[plane, surface, 
      Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}], 
      DisplayFunction -> $DisplayFunction];

Step (5): Zooming to Tangency

Now we magnify the graph more and more at the point (x1,y1,z1):

d = 4; Do[
      plane = Plot3D[
          dz[x - x1, y - y1] + z1, {x, x1 - (d/2), x1 + (d/2)}, {y, y1 - (d/2), 
            y1 + (d/2)}, PlotRange -> {z1 - d, z1 + d}, 
          Axes -> None, PlotPoints -> 3, 
          DisplayFunction -> Identity]; 
      surface = 
        Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
          PlotRange -> {z1 - d, z1 + d}, Axes -> None, 
          PlotPoints -> 30, DisplayFunction -> Identity]; 
      Show[plane, surface, 
        Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}], 
        DisplayFunction -> $DisplayFunction]; d = (d/2), {n, 1, 6}];

Practice Exercises

Partial Derivatives

Use Mathematica to compute the symbolic partial derivatives df/dx and df/dy of the function

z = f[x,y] = Exp[-((x^2) + (y^2))] = (e^(-((x^2) + (y^2))))

Verify your compuutations by hand.

Slopes

Compute the numerical values of the partial derivatives ∂f/∂x and ∂f/∂y of the function

z = f[x,y] = Exp[-((x^2) + (y^2)))]

when x = 1 and y = -2.

Total Differential

Compute the numerical value of the partial derivatives ∂f/∂x and ∂f/∂y of the function

z = f[x,y] = Exp[-((x^2) + (y^2))]

when x = 1 and y = 2 and use that to give the (dx,dy,dz)-equation of the tangent plane.  Graph this function with Mathematica using the dx,dy,dz variables.

A Combined Explicit Tangent Example

The explicit surface  z = f[x,y]  has explicit tangent  dz = a dx + b dy

Use the procedure in the NoteBook Overview section above for finding the explicit tangent plane:

The following commands  combine steps 0-4:

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; \(f[x_, y_] := 5\ \((x\^2 + y\^2)\)\ Exp[\(-\((x\^2\/2 + y\^2\/3)\)\)]; 

    
pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 


    Print["Partial ∂f/∂x = ", pfpx[x, y]]; 

    Print[" "]; 

    Print["Partial ∂f/∂y = ", pfpy[x, y]]; 

    Print["Total differential: "]; 

    Print["dz = ", pfpx[x, y], " dx + ", pfpy[x, y], " dy"]; 

    x1 = 1\/4; 
y1 = \(-2\); 
d = 5; 
z1 = f[x1, y1]; 

    dz[dx_, dy_] := pfpx[x1, y1]\ dx + pfpy[x1, y1]\ dy; 

    Print["At x = ", x1, "and  y = ", y1]; 

    Print["The differential  dz = ", dz[dx, dy]]; 
Print[" "]; 

    Print["The approx. differential  dz = ", N[dz[dx, dy]]]; 

    plane = Plot3D[
        dz[x - x1, y - y1] + z1, {x, x1 - d\/2, x1 + d\/2}, {y, y1 - d\/2, 
          y1 + d\/2}, PlotRange -> {z1 - d, z1 + d}, 
        PlotPoints -> 3, Axes -> None, Boxed -> False, 
        DisplayFunction -> Identity]; 

    surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 40, 
        Axes -> None, Boxed -> False, 
        DisplayFunction -> Identity]; 

    combine = 
      Show[{plane, surface, 
          Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}]}, 
        DisplayFunction -> $DisplayFunction]; \)

Examine The Tangent

FlyBy[combine, {10 Cos[u],10 Sin[u],1},{u,-Pi,Pi,Pi/3}]

Zooming to Tangency

Now we magnify the graph more and more at the point (x1,y1,z1):

d = 4;
Do[plane = Plot3D[dz[x-x1,y-y1]+z1,
	{x,x1-d/2,x1+d/2},{y,y1-d/2,y1+d/2},PlotPoints->3,
	PlotRange->{z1-d,z1+d},Axes->None,
	DisplayFunction -> Identity];
surface = Plot3D[f[x,y],
	{x,x1-d,x1+d},{y,y1-d,y1+d},
	PlotRange->{z1-d,z1+d},Axes->None,PlotPoints->30,
	DisplayFunction -> Identity];
	Show[plane,surface, DisplayFunction->$DisplayFunction];
	d = d/2
	,{n,1,8}];

A Step-by-step Example of the Gradient

Compute each step of this example in order, first doing the computations by hand yourself.

Step (0): The Function & Graphs

For step (0), sketch a plot of the surface  z =1 - (((x^2)/2) + ((y^2)/3)) by hand and then compare your sketch to Mathematica's drawing.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] := 1 - (((x^2)/2) + ((y^2)/3)); x1 = 1; y1 = 2; d = 5; z1 = f[x1, y1]; SetOptions[Plot3D, ViewPoint -> {1.325, -2.997, 0.845}]; 
    surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        AxesLabel -> {"x", "y", "z"}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30, 
        DisplayFunction -> Identity]; Show[surface, Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}], 
      DisplayFunction -> $DisplayFunction]; ContourPlot[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
      PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30];

Step (1): The Partials,Gradient, and Total Derivative

Calculate the partial derivatives of this function by hand, write out the total derivative and then <enter> the Mathematica computation of them and compare:

\(pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 

    gradf[x_, y_] := {pfpx[x, y], pfpy[x, y]}; 

    \(Print["Partial ∂f/∂x = ", pfpx[x, y]]; \)\)Print[" "]; Print["Partial ∂f/∂y = ", pfpy[x, y]]; Print["Grad f = ", gradf[x, y]]; Print[" "]; Print["dz = ", pfpx[x, y], " dx + ", pfpy[x, y], " dy"];

Step (2): Evaluating the Specific Slopes

In your hand computation, set  x1 = 1,  y1 = 2  and evaluate the gradient, then  <enter> the Mathematica version below.  Compare results.

dz[dx_,dy_] := pfpx[x1,y1] dx + pfpy[x1,y1] dy
{x1,y1}
gradf[x1,y1]
dz[dx,dy]

Step (3): The Tangent Line in Local Coordinates

Plot the specific differential  dz = a dx + b dy and <enter> the Mathematica version below.  Compare results.

Plot3D[dz[dx,dy],{dx,-d,d},{dy,-d,d},PlotRange->{-d,d},
		PlotPoints->3, AxesLabel->{"dx","dy","dz"}];
loccontour = ContourPlot[dz[dx,dy],{dx,-d,d},{dy,-d,d},PlotRange->{-d,d},
Contours->{0},DisplayFunction->Identity];
Show[{loccontour,Arrow[gradf[x1,y1],Red]},
Frame2D[1],DisplayFunction->$DisplayFunction];

Step (4): The Gradient in (x,y) - Coordinates

Replace dx by (x - x1), dy by (y - y1) and dz by (z - f[x1,y1]) by hand and write out the specific equation z = z1 + a (x - x1) + b (y - y1).  Sketch both graphs together.  Compare results.

Clear[x,y];
Print["Grad f = ",gradf[x1,y1]];

Plot3D[f[x,y],{x,x1-d,x1+d},{y,y1-d,y1+d},
 	PlotRange->{z1-d,z1+d},PlotPoints->30,ViewPoint->{1.325, -2.997, 0.845}];
contour = ContourPlot[f[x,y],{x,x1-d,x1+d},{y,y1-d,y1+d},
 		PlotPoints->30,DisplayFunction->Identity];

Show[{contour,Arrow[gradf[x1,y1],Tail->{x1,y1},Red],Frame2D[1]}, 
	DisplayFunction->$DisplayFunction];

Step (5): Zooming to Tangency

Now we magnify the graph more and more at the point (x1,y1,z1):

d = 2;
Do[
contour = ContourPlot[f[x,y],{x,x1-d,x1+d},{y,y1-d,y1+d},
 		PlotPoints->30,DisplayFunction->Identity];

Show[{contour,Arrow[(d/2)*gradf[x1,y1],Tail->{x1,y1},Red]}, 
	DisplayFunction->$DisplayFunction];
	d = d/2
	,{n,1,6}];

Practice Exercises

The Symbolic Gradient

Use Mathematica to compute the general symbolic gradient of the function

z = f[x,y] = Sin[π x] Cos[π y]

The Numerical Gradient

Use Mathematica to compute the numerical vlaue of the gradient of the function

z = f[x,y] = Sin[π x] Cos[π y]

when  x = 1/4  and  y = 1/3.

The Tangent Contour Line

Use Mathematica to draw the line given by  the dot product

Grad f . {dx,dy} = 0   <=>  a dx + b dy = 0

of the function

z = f[x,y] = Sin[π x] Cos[π y]

when  x = 1/4  and  y = 1/3.  Make your plot using the variables  dx  and  dy  and use ContourPlot[..., Contours->{0}];

A Combined Gradient Example

The gradient   grad f = {a,b}  is the direction of fastest ascent at (x1,y1)

See the procedure above for the explanation of why the gradient points in the direction of steepest ascent.

The implicit CURVE: f[x,y] = z1 has implicit tangent LINE: a dx + b dy = 0

See the procedure above for finding the implicit tangent equation for an implicitly given curve.

The next computation combines all the steps described for the gradient.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; \(f[x_, y_] := 5\ \((x\^2 + y\^2)\)\ Exp[\(-\((x\^2\/2 + y\^2\/3)\)\)]; 

    
pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 


    gradf[x_, y_] := {pfpx[x, y], pfpy[x, y]}; 

    Print["Partial ∂f/∂x = ", pfpx[x, y]]; 

    Print[" "]; 

    Print["Partial ∂f/∂y = ", pfpy[x, y]]; 

    Print[" "]; 
Print["Grad f = ", gradf[x1, y1]]; 

    Print[" "]; 
x1 = 1\/4; 
y1 = \(-2\); 
d = 5; 
z1 = f[x1, y1]; 

    Print["At x = ", x1, "and  y = ", y1]; 
Print[" "]; 

    Print["The approx. gradient  Grad f = ", N[gradf[x1, y1]]]; 

    surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30, 
        ViewPoint -> {1.325, \(-2.997\), 0.845}, 
        AxesLabel -> {"x", "y", "z"}, 
        DisplayFunction -> Identity]; 

    Show[surface, Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}], 
      DisplayFunction -> $DisplayFunction]; 

    line = ContourPlot[
        gradf[x1, y1] . {x - x1, y - y1}, {x, x1 - d, x1 + d}, {y, y1 - d, 
          y1 + d}, Contours -> {0}, ContourShading -> False, 
        DisplayFunction -> Identity]; 

    contour = 
      ContourPlot[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotPoints -> 30, DisplayFunction -> Identity]; 

    Show[{contour, Arrow[gradf[x1, y1], Tail -> {x1, y1}, Red], 
        Frame2D[1], line}, DisplayFunction -> $DisplayFunction]; \)

Zooming to Tangency

Now we magnify the graph more and more at the point (x1,y1,z1):

d = 2;
Do[
contour = ContourPlot[f[x,y],{x,x1-d,x1+d},{y,y1-d,y1+d},
 		PlotPoints->30,DisplayFunction->Identity];

Show[{contour,Arrow[(d/2)*gradf[x1,y1],Tail->{x1,y1},Red]}, 
	DisplayFunction->$DisplayFunction];
	d = d/2
	,{n,1,6}];

Lots of Gradients

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; \(f[x_, y_] := 5\ \((x\^2 + y\^2)\)\ Exp[\(-\((x\^2\/2 + y\^2\/3)\)\)]; 

    
pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 


    gradf[x_, y_] := {pfpx[x, y], pfpy[x, y]}; 

    \(Print["Grad f = ", gradf[x, y]]; \)\)x1 = 0; y1 = 0; d = 4; contour = 
      ContourPlot[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotPoints -> 30, DisplayFunction -> Identity]; arrows = 
      Table[Arrow[(1/6) gradf[x, y], Tail -> {x, y}, 
          AbsoluteThickness[4]], {x, x1 - d, x1 + d, (d/4)}, {y, y1 - d, 
          y1 + d, (d/4)}]; Show[{contour, arrows}, DisplayFunction -> $DisplayFunction];

A Surface Normal

The implicit surface  z - f[x,y] = 0  has implicit tangent  dz - a dx - b dy = 0, 
or normal vector n = {-a,-b,1}.

Use the procedure for finding the implicit tangent plane and normal to an implicitly given surface.  In this case we apply that procedure to the function  F[x,y,z] = z - f[x,y], so that

∂(F/∂)x =  
        -∂(f/∂)x,  ∂(F/∂)y =  
        -∂(f/∂)y,  ∂(F/∂)z =  +1

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; \(f[x_, y_] := 5\ \((x\^2 + y\^2)\)\ Exp[\(-\((x\^2\/2 + y\^2\/3)\)\)]; 

    
pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 

x1 = 1\/4; 

    \(y1 = \(-2\); \)\)z1 = f[x1, y1]; p = {x1, y1, z1}; d = 5; v = {-pfpx[x1, y1], -pfpy[x1, y1], 1}; Print["Normal vector v = ", N[v]]; Print[" at point  p =", N[p]]surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 40, 
        Axes -> None, Boxed -> False, 
        DisplayFunction -> Identity]; combine = 
      Show[{Arrow[v, Tail -> p, Red], surface, 
          Graphics3D[{PointSize[0.02], Point[{x1, y1, z1}]}]}, 
        DisplayFunction -> $DisplayFunction];

Practice Exercises

A Normal Vector

Find a vector normal to the explicit surface

z = f[x,y]= x (y^2) Log[(x^2) + (y^2)]

at the point (x,y) = (3,-4).

Lots of Normals

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; \(f[x_, y_] := 5\ \((x\^2 + y\^2)\)\ Exp[\(-\((x\^2\/2 + y\^2\/3)\)\)]; 

    pfpx[x_, y_] := \ Evaluate[D[f[x, y], x]]; 

    pfpy[x_, y_] := \ Evaluate[D[f[x, y], y]]; 


    v[x_, y_] := {\(-pfpx[x, y]\), \(-pfpy[x, y]\), 1}; 

    \(p[x_, y_] := {x, y, f[x, y]}; \)\)x1 = 0; y1 = 0; d = 4; surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 40, 
        Axes -> None, Boxed -> False, 
        DisplayFunction -> Identity]; points = 
      Table[Graphics3D[{PointSize[0.02], Point[p[x, y]]}], {x, x1 - d, 
          x1 + d, (d/4)}, {y, y1 - d, y1 + d, (d/4)}]; arrows = 
      Table[Arrow[v[x, y], Tail -> p[x, y]], {x, x1 - d, x1 + d, (d/4)}, {
          y, y1 - d, y1 + d, (d/4)}]; Show[arrows, surface, points, 
      DisplayFunction -> $DisplayFunction];

Exercises

Exercise on explicit tangent planes

The explicit surface  z = f[x,y]  has explicit tangent  dz = a dx + b dy

See the step-by-step procedure above to solve the following exercise:

Exercise 18.7.1

Draw the explicit surface   z = (x^2) + (y^3)   together with its tangent plane attached at the point  (x,y) = (1,1) by hand, following the steps in the text version of the problem.  Verify your drawing by modifying one of the computations above and working this example with Mathematica  so you can zoom in to the point and see the graph approach the tangent plane.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] :=

Exercise: Computer Only

Draw the explicit surface   z  =  25 Sin[x y] Exp[-((x^2) + (y^2))]  together with its tangent plane attached at the point  x = 1/3  and  y = -2.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] :=

Exercises on local approximation

The approximation 

f[x+dx,y+dy] - f[x,y] = a dx + b dy + |{dx,dy}| ϵ

with  ϵ ≈ 0 when |{dx,dy}| ≈ 0.

Use the procedure above to approximate a small change in a function.

Exercise 18.7.5: (e^π) ≈  (2.71828^3.14159)?

Use the differential approximation to compare the computation of  E^Pi  with its approximation  2.71828 ^ 3.14159.  What does the differential estimate as the error?  (HINT: Let  x + dx = E,  y + dy = Pi, x = 2.71828 & y = 3.14159.)  Use high precision Mathematica computation to compare your approximation to the exact value.

N[E,55]
N[Pi,55]
N[E^Pi,55]

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] :=

Exercise 18.3.1 & Problem 18.1

The exercises in Section 18.3 use the differential to approximate small changes in a function.

Exercises on fastest ascent

The gradient   grad f = {a,b}  is the direction of fastest ascent at (x1,y1)

Use the procedure above to find the direction of fastest ascent.

Exercise 18.5.1 & 2

Draw the contour graph of   z = (x^2) + (y^2)/3   together with its tangent line at the points (x,y) =

(0,0), (1,1), (-1,0)

Which direction should you move at each of these points in order to increase at the fastest rate?  At what rate will you increase?  What happens if you move in the opposite direction?  Which directions could you move in order to not change at all?

Exercise: Computer Only

Compute the symbolic gradient of the function  f[x,y] = Cos[π x] Sin[π y].  Give its numerical value at the point  x = 1/4,  y = 1/3.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] :=

Exercises on implicit curves

The implicit CURVE: f[x,y] = z1 has implicit tangent LINE: a dx + b dy = 0

Use the procedure for finding the implicit tangent LINE to an implicit curve.

Exercise on Implicit Curves 18.7.3

1)  Sketch the ellipse

((((x/3)))^2) + ((((y/4)))^2) = 1

using Mathematica's ContourPlot on the function  f[x,y] = (x/3)^2 + (y/4)^2  with the Option

Contours->{1}

2)  Use Mathematica to compute the gradient of f[x,y].

3)  Fix the specific point  x = 3/2,  y = -2/Sqrt[2]  and compute the specific equation of the tangent line.

4)  Plot the tangent line using your equation and Show both the curve and the line on the same plot.

Exercise: Computer Only

Draw the contour graph of   z = (x^2) + (y^3)   together with its tangent line at the point  (x,y) = (1,1).  Zoom in to the point and see the graph approach the tangent line.

Clear[x,y,z,f,dx,dy,dz,p,v,pfpx,pfpy,gradf];
f[x_,y_] :=

Exercise: Computer Only

Draw the level line on the contour plot of the function  f[x,y] = Cos[π x] Sin[π y]  that passes thru the point  x = 1/4,  y = 1/3.  Show the gradient vector of the function at this point.

Clear[x,y,z,f,dx,dy,dz,p,v,pfpx,pfpy,gradf];
f[x_,y_] :=

Exercises on normal vectors to a surface

The implicit surface  z - f[x,y] = 0  has normal vector n = {-a,-b,1}.

Use the procedure above for finding the implicit tangent plane to the surface  F[x,y,z] = z - f[x,y] = 0.

Exercise 18.7.4

Sketch the explicit surface z = (x^3) - (y^2) in a neighborhoor of the point (1,1,0).

1)  What 2-D vector  G  is perpendicular to the level curve of  z  at this point?

2)  What 3-D vector  n  is normal to the surface and has an upward z component?  Show the surface with this normal in Red.

3)  A force  f = {1,2,3}  is acting on the surface at the point  Q={1,1,0}.  Show the surface, n and f on one plot with different colors.  Put the tail of the vectors at  Q = {1,1,0}.

4)  What is the vector projection  t = (Subscript[f, n])  of  f  in the direction of  n?  Describe how the vector  t = f - n  acts on the surface and show it another color.

Exercise: Computer Only

Draw the explicit graph z = ((x^4) + 3 (y^4)) Exp[-((x^2) + (y^2))] and show a normal vector on the surface at the point  x = 1,  y = -1.

Clear[x,y,z,f,dx,dy,dz,p,v,pfpx,pfpy,gradf];
f[x_,y_] :=

The Mother of All Review Exercises

Review on Partial and Total Derivatives, the Gradient and Normal

The next cell contains a computation to review the various uses of partial derivatives. The computation:

(1)  Finds the symbolic partial derivatives of  f[x,y]  with respect to  x  and  y.

(2)  Computes these derivatives at a particular point (x1,y1) = (9/4,7/4).

(3)  Uses these particular partials in the total derivative and gradient to draw a tangent plane with its normal vector and draw the tangent line to the contour level through (x1,y1) with its normal.

You need to have a clear idea of the meanings of these various quantities in order to use them for max-min theory.   <Enter> the computation and then answer the questions after the output.

Clear[x, y, z, f, dx, dy, dz, p, v, pfpx, pfpy, gradf]; f[x_, y_] := 5 x y Exp[-(((x^2)/2) + ((y^2)/3))];
pfpx[x_, y_] :=  Evaluate[D[f[x, y], x]];
pfpy[x_, y_] :=  Evaluate[D[f[x, y], y]];

gradf[x_, y_] := {pfpx[x, y], pfpy[x, y]};
x1 = 2.25; 
      y1 = 1.75; d = 5; z1 = f[x1, y1]; dz[dx_, dy_] := pfpx[x1, y1] dx + pfpy[x1, y1] dy; p = {x1, y1, z1}; v = {-pfpx[x1, y1], -pfpy[x1, y1], 1}; Print["The approx. differential  dz = ", N[dz[dx, dy]]]; Print["The approx. gradient  Grad f = ", N[gradf[x1, y1]]]; Print["Normal vector v = ", N[v]]; Print[" at point  p =", N[p]]; plane = 
      Plot3D[dz[x - x1, y - y1] + z1, {x, x1 - (d/2), x1 + (d/2)}, {y, 
          y1 - (d/2), y1 + (d/2)}, PlotRange -> {z1 - d, z1 + d}, 
        ViewPoint -> {0.839, -3.200, 0.713}, 
        PlotPoints -> {2, 2}, Axes -> False, 
        DisplayFunction -> Identity]; surface = 
      Plot3D[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotRange -> {z1 - d, z1 + d}, PlotPoints -> 30, 
        ViewPoint -> {0.839, -3.200, 0.713}, 
        AxesLabel -> {"x", "y", "z"}, 
        DisplayFunction -> Identity]; combine = 
      Show[{plane, surface, Graphics3D[{PointSize[0.02], Point[p]}], 
          Arrow[v, Tail -> p]}, 
        DisplayFunction -> $DisplayFunction]; line = ContourPlot[
        gradf[x1, y1] . {x - x1, y - y1}, {x, x1 - d, x1 + d}, {y, y1 - d, 
          y1 + d}, Contours -> {0}, ContourShading -> False, 
        DisplayFunction -> Identity]; contour = 
      ContourPlot[f[x, y], {x, x1 - d, x1 + d}, {y, y1 - d, y1 + d}, 
        PlotPoints -> 30, DisplayFunction -> Identity]; Show[{contour, Arrow[gradf[x1, y1], Tail -> {x1, y1}, Red], 
        Frame2D[1], line}, DisplayFunction -> $DisplayFunction];

Questions on the review example:

The input point (x1,y1) = (9/4,7/4) ~ (2.25,1.75) shown above on the surface and contour plots is not a maximum point nor a minimum point.  Our basic question is: "Why not?"

QUESTION 1: What is the symbolic formula for the gradient in terms of partial derivatives?

ANSWER 1:

QUESTION 2:  What is the numerical value of the gradient vector at the point (x1,y1) = (2.25,1.75)? (HINT: Read the print-out.)

ANSWER 2:

QUESTION 3: Which vector in the figures above is the gradient at (x1,y1)?

ANSWER 3:

QUESTION 4: The tangent plane to the surface above (x1,y1) has explicit equation in (dx,dy,dz)-coordinates:

ANSWER 4:

QUESTION 5: A normal vector to the tangent plane above (x1,y1) with +1  z-component is:

ANSWER 5:

QUESTION 6: What is the connection between the answers to 3, 4, and 5, that is, what is the connection between the gradient, a normal vector to a tangent plane and the explicit equation of the tangent plane?

ANSWER 6:

QUESTION 7: The tangent plane at (x1,y1) "slopes" upward fastest in the direction of the (x,y)- vector:

ANSWER 7:  Most sloping direction:

QUESTION 8: The "slope of the tangent plane" could be defined as the rate of increase of  z  in the direction of fastest increase.  What is this slope at (x,y) = (2.25,1.75)?

ANSWER 8: Amount of maximal slope:

QUESTION 9: The five points (x,y) = (0,0),
(-1,(Sqrt[(3/2)])),
(-1,-(Sqrt[(3/2)])),
(1,(Sqrt[(3/2)])),
(1,-(Sqrt[(3/2)]))
lie below points on the surface where the tangent plane is horizontal.  What is the value of a normal vector to the tangent plane at these points?  What is the value of the gradient?

ANSWER 9:

QUESTION 10: Which point(s) are the maximum? Which are the minimum? and Why can't (x1,y1) = (2.25,1.75) be either one?

ANSWER 10: