Plotting Tangent Planes to a Surface in Mathematica

Copyright © 2001 by James F. Hurley, University of Connecticut, Department of Mathematics, Unit 3009, Storrs CT 06269-3009.  All rights reserved.

    Consider the function f(x, y) = x/y. Mathematica's built-in command Plot3D can plot the graph if you avoid the xz-plane on which f is discontinuous. As usual, generate the plot by placing the cursor at the end of the code and hitting the Enter key.

(* Mathematica Routine to plot graph of a surface z = f ( x , y ) * ) F [ x_ , y_ ] := x / y ; Plot3D [ F [ x , y ] , { x , 1 / 4 , 3 } , { y , 1 / 4 , 3 } , AxesLabel -> { x , y , z } ]

    
     To plot the tangent plane to this surface at a point such as P(2, 1, 2), the first step is to calculate the partial derivatives f /∂x and f /y at P. That is easy for this function:
   
                   
f x = 1 y   = 1 at (2, 1, 2)  and    f y = - x y 2 = -  2 at (2, 1, 2).
   
   So the equation of the tangent plane to the graph of
f at P is z - 2 = (x - 2) - 2(y - 1).  The next routine plots that plane in yellow, and then redraws it with the Cartesian coordinate axes.

(* Mathematica Routine to plot graph of a surface z = f ( x , y ) , with coordinate axes and tangent plane *) a := - 1 ; b := 2 ; c := - 1 ; d := 2 ; e := - 1 ; f := 5 ; T [ x_ , y_ ] := 2 + ( x - 2 ) - 2 * ( y - 1 ) planeplot = Graphics3D [ Plot3D [ { T [ x , y ] , RGBColor [ 1 , 1 , 0 ] } , { x , 1 , 3 } , { y , 0 , 2 } , AxesLabel -> { x , y , z } ] ] ; coordaxes = Graphics3D [ { { RGBColor [ 1 , 0 , 1 ] , Line [ { { a , 0 , 0 } , { b , 0 , 0 } } ] , Text [ x , { b + .25 , 0 , 0 } ] } , { RGBColor [ 1 , 0 , 1 ] , Line [ { { 0 , c , 0 } , { 0 , d , 0 } } ] , Text [ y , { 0 , d + .25 , 0 } ] } , { RGBColor [ 1 , 0 , 1 ] , Line [ { { 0 , 0 , e } , { 0 , 0 , f } } ] , Text [ z , { 0 , 0 , f + 1 } ] } } ] ; Show [ planeplot , coordaxes , ViewPoint -> { 2 , 1 , 1 } ]


Plotting a surface and its tangent plane at a point. To combine two earlier Mathematica plots, ask Mathematica to Show them to you. The following command does so, and also asks Mathematica to redraws the first plot. Notice that even with an increased number of points plotted, the abruptness of the surface makes the tangent plane appear to cut through the surface.

surfplot = Graphics3D[
             Plot3D[ {F[x, y], Hue[(x^2 + y^2)/30]},
             {x, 1/4, 3}, {y, 1/4, 3},
             PlotPoints -> 50,
             AxesLabel -> {"x", "y", "z"} ] ];
Show[surfplot, planeplot, coordaxes, ViewPoint -> {2, .5, 1}, Lighting -> False]

   

A tamer example. Consider the function g with formula g(x, y) = 9 - x 2 - y 2 . The graph of g is a paraboloid (of revolution about the z-axis), for which the following Mathematica routine generates a good picture.

g [ x_ , y_ ] := 9 - x ^ 2 - y ^ 2 ;

Plot3D [ g [ x , y ] , { x , - 3 , 3 } , { y , - 3 , 3 } , AxesLabel -> { x , y , z } ]

Let's generate a plot of the tangent plane to this surface at the point (2, 1, 4). The partial derivatives there are
        
                            
f x = - 2x = - 4     and       x y = - 2y = - 2.
   
The equation of the tangent plane at (2, 1, 4) is therefore
   
                                         
z - 4 = - 4(x - 2) - 2(y - 1).  
   
The following routine plots that plane, and then replots it with the addition of red coordinate axes. (The initial settings of the parameters
a, b, ..., f reflect some experimentation with the figure the results from executing the routine.)

a := - 3 ;

b := 4 ;

c := - 3 ;

d := 4 ;

e := - 9 ;

f := 12 ;

T [ x_ , y_ ] := 4 - 4 ( x - 2 ) - 2 ( y - 1 )

planeplot = Graphics3D [ Plot3D [ { T [ x , y ] , RGBColor [ 0 , 1 , 0 ] } , { x , 1 , 3 } , { y , 0 , 2 } , AxesLabel -> { x , y , z } ] ] ;

coordaxes = Graphics3D [ { { RGBColor [ 1 , 0 , 0 ] , Line [ { { a , 0 , 0 } , { b , 0 , 0 } } ] , Text [ x , { 1.1 b , 0 , 0 } ] } , { RGBColor [ 1 , 0 , 0 ] , Line [ { { 0 , c , 0 } , { 0 , d , 0 } } ] , Text [ y , { 0 , d + 1 , 0 } ] } , { RGBColor [ 1 , 0 , 0 ] , Line [ { { 0 , 0 , e } , { 0 , 0 , 2.5 f } } ] , Text [ z , { 0 , 0 , 1.6 f } ] } } ] ;

Show [ planeplot , coordaxes ]

The following command draws the preceding two separate plots together (after redrawing the first one). Try it!

surfplot = Graphics3D [ Plot3D [ { g [ x , y ] , Hue [ ( x ^ 2 + y ^ 2 ) / 80 ] } , { x , - 3 , 3 } , { y , - 3 , 3 } , AxesLabel -> { x , y , z } ] ]

Show [ surfplot , planeplot , coordaxes , Lighting -> False , ViewPoint -> { 2 , 1 , .75 } ]

Graphics3D TagBox[RowBox[List["\[SkeletonIndicator]", "Graphics3D", "\[SkeletonIndicator]"]], False, Rule[Editable, False]]

[Graphics:HTMLFiles/TanPlanes_1.gif]

Graphics3D TagBox[RowBox[List["\[SkeletonIndicator]", "Graphics3D", "\[SkeletonIndicator]"]], False, Rule[Editable, False]]


Converted by Mathematica  (June 10, 2003)