The Normal Vector to An Explicit Surface
z = f[x,y]
and its Explicit Tangent Plane
dz = m dx + n dy

by
K. D.  Stroyan
University of Iowa

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

Special Mathematica Functions used in this NoteBook

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},AspectRatio->Automatic];
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]];

Notebook Overview

This NoteBook shows and explicit surface along with its tangent plane and the vector perpendicular to both the plane and the surface.

The Normal to the Plane  dz = m dx + n dy

An explicit plane might be given by the equation  z = m x + n y, for specific numbers  m  and  n.  However, we want to use different variables, because change variables arise in calculus.  Consider the explicit plane in (dx,dy,dz)-coordinates,

dz = m dx + n dy

for specific numbers  m  and  n.  We can sketch the plane by drawing lines in the planes parallel to the (dx,dz)-plane of slope  m  and lines in planes parallel to the (dy,dz)-plane of slope  n.  In other words, the line with dy = 0,  dz = m dx has slope m and the line with dx = 0,  dz = n dy  has slope  n.  This does NOT give us the normal vector directly.

The implicit equation

a dx + b dy + c dz = 0

for constants  a, b, c, describes a plane and in this form we can "see" the normal by a dot product,

a dx + b dy + c dz = 0
	{a,b,c}.{dx,dy,dz} = 0

dX = {dx,dy,dz}  is perpendicular to  V = {a,b,c}.

To find the normal to  dz = m dx + n dy, simply do some algebra:

dz = m dx + n dy
	-m dx - n dy + dz = 0
	{-m,-n,+1}.{dx,dy,dz} = 0

The normal vector to  dz = m dx + n dy  is  V = {-m,-n,+1}.

Practice Exercise

1)  Sketch the plane   dz = (-1/2) dx -(1/3) dy  by hand and show that the vector  {3,2,6} is perpendicular to the plane.

2)  Sketch the plane through the origin perpendicular to the vector V = {1,2,3}  simply by sketching the vector and drawing the perpendicular plane.

The Normal to z = f[x,y]

The surface  z = f[x,y]  has tangent given by  dz = m dx + n dy  where  m = the partial derivative of f with respect to x and n = the partial derivative of f with respect to y both evaluated at the (x,y)-point of tangency.  If we view the equation  dz = m dx + n dy simply as expressed in a new coordinate system parallel to (x,y,z), but passing through the fixed point of tangency, (x,y,f[x,y]), then the normal vector is given in the previous section by

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

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 vector

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

is the "normal" to this plane, that is, it is perpendicular to the plane and surface.

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.

Local Coordinates or Original Coordinates?

The local coordinates (dx,dy,dz) parallel to the original (x,y,z)-coordinates through the point of tangency make plotting the tangent  dz = m dx + n dy easy.  In order to show both the tangent and function on the same plot, we need to plot f[.,.] in the same coordinates.  This can be done by plotting the change in f:

f[x+dx,y+dy] - f[x,y]

for  x  and  y  fixed at the point of tangency and  dx and  dy  varying.

Original coordinates

Sometimes it is not convenient to use local coordiantes.  It is easy to plot  z = f[x,y] in the original system, and if we fix the point of tangency ar  (x1,y1,z1=f[x1,y1]), compute the specific slopes in  dz = m dx + n dy, then we can replace  dx by (x-x1), dy by (y-y1) and  dz by (z-z1) and plot the tangent as

dz = m dx + n dy
	(z-z1) = m(x-x1) + n(y-y1)
	z = z1 + m(x-x1) + n(y-y1)

References to the Text

This NoteBook goes with Section 18.4 of the text.

Plotting in Local Coordinates

Here are the steps:

(1) Define z = f[x,y]

(2) Compute the symbolic total differential (including both partial derivatives)

(3) Compute z = f[x,y] and the specific  dz = m dx + n dy at the specific point (x,y)

(4) Plot the surface and tangent

(5) Show the combined plot with the Arrow  {-∂(f/∂)x[x,y],-∂(f/∂)y[x,y],+1}

Clear[x, y, dx, dy, f, fX, fY]; \(f[x_, y_] := 9 - x\^2 - y\^2; 


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

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


    dz[dx_, dy_] := fX[x, y]\ dx + fY[x, y]\ dy; 

    \(Print["The function  z = f[x,y] = ", f[x, y]]; \)\)Print["has symbolic total differential"]; Print["dz = ", dz[dx, dy]]; x = 1.0; y = -1.0; z = f[x, y]; Print["At (x,y,f[x,y]) =", {x, y, z}, " the differential"]; 
    Print["dz = ", dz[dx, dy]]; scale = 3; surface = 
      Plot3D[f[x + dx, y + dy] - z, {dx, -scale, scale}, {dy, -scale, 
          scale}, PlotRange -> {-scale, scale}, 
        BoxRatios -> Automatic, 
        AxesLabel -> {"dx", "dy", "dz"}, 
        Ticks -> {{-1, 1}, {-1, 1}, {-1, 1}}, 
        DisplayFunction -> Identity]; tangent = 
      Plot3D[dz[dx, dy], {dx, -(scale/3), (scale/3)}, {dy, 
          -(scale/3), (scale/3)}, 
        PlotRange -> {-scale, scale}, BoxRatios -> Automatic, 
        PlotPoints -> 6, DisplayFunction -> Identity]; combinedPlot = 
      Show[{surface, tangent, Arrow[{-fX[x, y], -fY[x, y], 1}, Red]}, 
        DisplayFunction -> $DisplayFunction]; Print[
      "The normal vector V =", {-fX[x, y], -fY[x, y], 1}];

Plotting in Original Coordinates

Here are the steps:
(1) Define z = f[x,y]

(2) Compute the symbolic total differential (including both partial derivatives)

(3) Fix the point of tangency, (x1,y1), and compute z1 = f[x1,y1]

(4) Compute the specific  m  and  n  in  dz = m dx + n dy

(5) Replace  dx, dy, dz by differences,  z = z1 + m(x-x1) + n(y-y1)

(4) Plot the surface and tangent

(5) Show the plot with the Arrow  {-fX[x1,y1],-fY[x1,y1],+1} with its tail at {x1,y1,z1}

Clear[x, y, dx, dy, f, fX, fY]; \(f[x_, y_] := 3\ \((x\^2 + y\^2)\)\ Exp[\(-\(x\^2\/3\)\) - y\^2\/5]; 

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

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


    dz[dx_, dy_] := fX[x, y]\ dx + fY[x, y]\ dy; 
\(x1 = 0.5; \)\)y1 = -2.5; z1 = f[x1, y1]; scale = 3; surface = 
      Plot3D[f[x, y], {x, x1 - scale, x1 + scale}, {y, y1 - scale, 
          y1 + scale}, PlotRange -> {z1 - scale, z1 + scale}, 
        BoxRatios -> Automatic, 
        AxesLabel -> {"x", "y", "z"}, 
        Ticks -> {{x1 - 1, x1 + 1}, {y1 - 1, y1 + 1}, {z1 - 1, z1 + 1}}, 
        DisplayFunction -> Identity]; tangent = 
      Plot3D[z1 + fX[x1, y1] (x - x1) + fY[x1, y1] (y - y1), {x, 
          x1 - (scale/3), x1 + (scale/3)}, {y, y1 - (scale/3), y1 + (scale/3)}, 
        PlotRange -> {z1 - scale, z1 + scale}, 
        BoxRatios -> Automatic, PlotPoints -> 6, 
        DisplayFunction -> Identity]; combinedPlot = 
      Show[{surface, tangent, 
          Arrow[{-fX[x1, y1], -fY[x1, y1], 1}, 
            Tail -> {x1, y1, z1}, Red]}, 
        DisplayFunction -> $DisplayFunction]; Print[
      "The normal vector V =", {-fX[x1, y1], -fY[x1, y1], 1}]; 
    Print[
      "The general normal V =", {-fX[x, y], -fY[x, y], 1}];

Exercises

Exercise 18.4.1

Plot the surface  z = (x^2) + ((y^2)/3)  with its tangent plane at the points:

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

Exercise 18.4.2

Exercises like 18.4.1 where the surface is easy to plot by hand need to be somewhat contrived.  Use the computer and the same ideas to plot tangent planes to more interesting surfaces like:

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

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.

Exercise 18.4.3

1)  Plot the surface  z = 9 - (x^2) - (y^2)

2)  Find the normal vector to the surface z = 9 - (x^2) - (y^2)  at the point  (x,y) = (1, -2).

3)  Plot this vector with its tail at the point of the surface above (x,y) = (1,-2).

4)  Plot the surface, normal vector and plane perpendicular to your normal vector.

5)  Give the equation of the tangent plane in (x,y,z)-coordinates.

Exercise 18.4.4

1)  What is wrong with the following computation of the tangent plane?

z = (x^2) + (y^3)
	dz = 2 x dx + 3 (y^2) dy
	z - z1 = 2 x (x - x1) + 3 (y^2) (y - y1)
	z = z1 + 2 x (x - x1) + 3 (y^2) (y - y1)

2)  How does the computer  computation above avoid this problem?

Exercise 18.2.1, 2, 3

Find and draw the equation of the tangent to the surfaces of the text Exercise 18.2.1.  Choose appropriate points of tangency, perhaps including points where the tangent plane is horizontal.  See examples 18.1-5.

a)  z  = x (y^2) + (x^3) y

b)  z = Sin[x]^3 + Cos[y]^4

c)  z = Sin[x*y]*Cos[x*y]

d)  z = (Sqrt[1 - (x^2) - (y^2)]) Cos[2 π x y]

e)  z = (Sqrt[(x^2) + Sin[(y^2)]])

f) z = (1/(Sqrt[(x^2) + (y^2)]))

g)  z = (2 (x^2) + 3 (y^2)) Exp[-((x^2) + (y^2))]
	or  z = (2 (x^2) + 3 (y^2)) (e^(-((x^2) + (y^2))))

h)  z = 2 x y Exp[-(((x^2)/2) + ((y^2)/8))]

    or z = 2 x y (e^(-(((x^2)/2) + ((y^2)/8))))

i)  z = ArcTan[(x^2) (y^3)]

j)  z = Log[(x^2) + (y^4)]

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.