The intersection of a surface and a plane

Here is a surface that we wish to find the tangent plane to at the point (1,1,1):

f[x_,y_] = 4 - x^2-2y^2

surface = Plot3D[f[x,y],{x,-1.5,1.5},{y,-1.5,1.5},AxesLabel->{"x","y","z"},ColorFunction->"AvocadoColors"]

First Plane Intersection, and tangent line to surface

Here is the plot of the plane y=1:

plane1 = ParametricPlot3D[{x,1,z},{x,-2,2},{z,0,3},AxesLabel->{"x","y","z"},ColorFunction->"RustTones"]

We can overlay the two plots and see the intersection.

Show[plane1,surface]

The intersection of the surfaces is a parabola. Remember that this is a surface in the y=1 plane, so it is in terms of x and z.

curve1 = z ==f[x,1]

Parameterizing this curve we get:

rcurve1[t_] = {t,1,2-t^2}

The tangent line to the curve at the point (1,1,1) will be given by the point-slope form of a line z -z0 = m(x-x0), where the slope is given by the partial derivative of f with respect to x:

m[x_,y_] = D[f[x,y],x]

z-1 == m[1,1] (x-1)

which we can parameterize as:

rtan1[t_] = {t,1,3-2t}

curve1 = ParametricPlot3D[Evaluate[rcurve1[t]],{t,-2,2},PlotStyle->{Red,Thick}]

tangent1 = ParametricPlot3D[Evaluate[rtan1[t]],{t,-1,3},PlotStyle->{Blue,Thick}]

Show[curve1,tangent1]

Show[surface,curve1,tangent1]

Second Plane Intersection, and tangent line to surface

Here is the plot of the plane x=1:

plane2 = ParametricPlot3D[{1,y,z},{y,-2,2},{z,0,3},AxesLabel->{"x","y","z"},ColorFunction->"RustTones"]

Show[plane2,surface]

The intersection of the surfaces is a parabola. Remember that this is a surface in the x=1 plane, so it is in terms of y and z.

curve2 = z ==f[1,y]

Parameterizing this curve we get:

rcurve2[t_] = {1,t,3-2t^2}

The tangent line to the curve at the point (1,1,1) will be given by the point-slope form of a line z -z0 = m(y-y0), where the slope is given by the partial derivative of f with respect to y:

m[x_,y_] = D[f[x,y],y]

z-1 == m[1,1] (y-1)

which we can parameterize as:

rtan2[t_] = {1,t,5-4t}

curve2 = ParametricPlot3D[Evaluate[rcurve2[t]],{t,-2,2},PlotStyle->{Red,Thick}]

tangent2 = ParametricPlot3D[Evaluate[rtan2[t]],{t,0,2},PlotStyle->{Blue,Thick}]

Show[curve2,tangent2]

Show[surface,curve2,tangent2]

The Tangent Plane

Show[surface,tangent1,tangent2]

These two lines define the tangent plane. The equation for the tangent plane is:

f[x,y]
slopex[x_,y_] = (∂_x)f[x,y]
slopey[x_,y_] = (∂_y)f[x,y]
z[x0_,y0_] = f[x0,y0] + slopex[x0,y0] (x-x0) + slopey[x0,y0] (y-y0)

So for the above example, we have

z[1,1]

tanplane = ParametricPlot3D[{x,y,z[1,1]},{x,0,2},{y,0,2},ColorFunction->"RustTones"];
Show[surface,tanplane]

Here's a picture of the tangent plane at (0.1,0.1):

tanplane = ParametricPlot3D[{x,y,z[0.1,0.1]},{x,-2,2},{y,-2,2},ColorFunction->"RustTones"];
Show[surface,tanplane]

Another Example

So in general, here is how to calculate the tangent plane to a function:

f[x_,y_] = 2x^2+y^2
slopex[x_,y_] = (∂_x)f[x,y]
slopey[x_,y_] = (∂_y)f[x,y]
z[x0_,y0_] = f[x0,y0] + slopex[x0,y0] (x-x0) + slopey[x0,y0] (y-y0)

surface = Plot3D[f[x,y],{x,-1.5,1.5},{y,-1.5,1.5},ColorFunction->"AvocadoColors"];
tanplane = ParametricPlot3D[{x,y,z[0.1,0.1]},{x,-2,2},{y,-2,2},ColorFunction->"RustTones"];
Show[tanplane,surface]

Animation of a tangent plane

So in general, here is how to calculate the tangent plane to a function:

Clear[tanplane]
f[x_,y_] = 2x^2+y^2
slopex[x_,y_] = (∂_x)f[x,y]
slopey[x_,y_] = (∂_y)f[x,y]
z[x0_,y0_] = f[x0,y0] + slopex[x0,y0] (x-x0) + slopey[x0,y0] (y-y0)

surface = Plot3D[f[x,y],{x,-2,2},{y,-3,3},ColorFunction->"AvocadoColors"];
tanplane[x0_,y0_]:= ParametricPlot3D[{x,y,z[x0,y0]},{x,-2,2},{y,-2,2},ColorFunction->"RustTones",Mesh->None];

Manipulate[Show[tanplane[x0,y0],surface,PlotRange->{{-2,2},{-3,3},{-1,6}},AxesLabel->{"x","y","z"}],{x0,-2,2},{y0,-2,2}]