MA 211, Maple Lab #2

FUNCTIONS of SEVERAL VARIABLES

Limits, Partial Differentiation, and Tangent Planes

> restart;

Begin by defining the following function of 2 variables:

> f:=(x,y)->2*x*y/(x^2+y^2);

Now, we can evaluate this function at any point in its domain, for example

> f(a,b);z0:=f(-1,2);

To find the limit of this function (if it exists) at (1,2), type

> limit(f(x,y),{x=-1,y=2});

Next, let's try to find the limit at (0,0):

> limit(f(x,y),{x=0,y=0});

Maple echoes the command since it's unable to determine whether or not the limit exists. This leads us to wonder if perhaps the limit does not exist. Since it isn't possible to simplify f(x,y), the next step is to try approaching (0,0) along some different paths to see if different paths lead to different limits (which will tell us that the limit of f(x,y) as (x,y) goes to (0,0) does not exist).

First try approaching along the x-axis, by setting y=0 and taking the limit of the result as x goes to 0:

> limit(f(x,0), x=0);

Now try along the y-axis:

> limit(f(0,y), y=0);

How about along the line y=x:

> limit(f(x,x), x=0);

Since the limit along the line y=x does not equal the limits along the two axes, the limit of f(x,y) as (x,y) goes to (0,0) does not exist.

Exercise 2.1 a. Why does the first limit equal f(-1,2)?

b. Where is f(x,y) continuous?

c. Define g(x,y)=x^3*y/(x^6+y^2). Use Maple to investigate the limits of g at (-1,2) and (0,0).

To plot the graph of z=f(x,y), type

> plot3d(f(x,y),x=-10..10,y=-10..10);

Similar to Lab 1 when we plotted spacecurves, there are a variety of options for viewing 3-dimensional graphs using the lower tool bar which appears after you click on the graph. Experiment with a few of these options, such as rotating the graph, including axes, etc.

To find the partial derivatives of f with respect to x and y, use the diff command:

> fx:=simplify(diff(f(x,y),x));

> fy:=simplify(diff(f(x,y),y));

where the simplify command simplifies the resulting expressions. Maple can compute higher partials as well, such as the fifth partial fxxyyx (this calculation would be very tedious to attempt by hand!)

> fxxyyx:=normal(diff(f(x,y),x$2,y$2,x));

The gradient of f can now be computed after loading Maple's Linear Algebra package.

> with(linalg):

> gradf:=grad(f(x,y),[x,y]);

To find the value of gradf at the point (-1,2),

> n1:=subs(x=-1,y=2,evalm(gradf));

The evalm command tells Maple to view gradf as a matrix before making the substitution. To find the directional derivative of f in the direction of v=3i-4j, we must find a unit vector u along v.

> v:=[3,-4];

> u:=v/norm(v,2);

Here, the norm command computes the length of v and acts like the mag function defined in Lab 1. The "2" in the command tells Maple to compute the norm we want (there is more than one norm available). Now, to find the directional derivative of f in the direction u, the dot product of gradf and u can be calculated and simplified:

> dirder:=simplify(dotprod(gradf,u));

Then, to find the directional derivative of f at (-1,2) along the vector v,

> subs(x=-1,y=2,dirder);

The equation of the tangent plane to f at (-1,2,z0), where z0 is f(-1,2) from above, is given by z=z0+fx(-1,2)(x+1)+fy(-1,2)(y-2) or z=z0+dotprod([(i)(x+1)+j(y-2)],gradf(-1,2)). The resulting surface can then be plotted along with f:

> tanplane:=z0+dotprod(vector([x+1,y-2]),n1);

> plot3d({tanplane,f(x,y)},x=-5..5,y=-5..5);

This isn't a very useful picture. The following shows how to get f as just a smooth surface, the tangent plane in black, and a little dot at the point (-1,2,-4/5). As usual it takes a little fiddling around to get the right orientation and ranges.

> with(plots):

> a:=plot3d ( f(x,y) , x=-3..1, y=1..4,style=patchnogrid, shading=zhue, lightmodel=none, axes=frame, orientation=[54,75]):

> b:=plot3d (tanplane, x=-2..0, y=1..3, style=contour, contours=40, color=black):

> c:=plot3d(-4/5, x=-1.1..-0.9, y=1.9..2.1, color=magenta, style=patchnogrid):

> display({a,b,c});

Exercise 2.2 Define h(x,y)=2x^2y/(x^4+y^2).

a. Determine the sixth partial hxxyyyx of h at (-1,2).

b. Find the directional derivative of h at (-1,2) along the vector v1=2i + 5j.

Exercise 2.3 Find the equation of the tangent plane to h at (-1,2) and check your result by plotting this plane with h near (-1,2).

Local and Absolute Extrema

Define the following function:

> j:=(x,y)->(x-2)^2*y+y^2-y;

The next task is to find the absolute extrema of j on a bounded region R of the plane. We have learned that extrema occur either at critical points (where all partials are 0 or, equivalently, the gradient is 0) or on the boundary of R. First, find the critical points of j.

> jx:=simplify(diff(j(x,y),x)); jy:=simplify(diff(j(x,y),y));

Then find the values of x and y that make both jx and jy equal to zero.

> solve({jx=0,jy=0},{x,y});

Now, we can apply the Second Derivative Test to determine if these critical points are local extrema for j:

> jxx:=diff(j(x,y),x$2);jyy:=diff(j(x,y),y$2);jxy:=diff(j(x,y),x,y);

> D2:=jxx*jyy-jxy^2;

At the critical point (2, 1/2) we get

> subs(x=2,y=1/2,D2);subs(x=2,y=0.5,jxx);

Since both the determinant D2 and jxx are positive, this critical point is a local minimum for j.

Exercise 2.4 a. Determine any other local extrema and/or saddle points for j. State your conclusion in each case.

b. Determine all local extrema and saddle points for p(x,y)=xy^2-x^2y+2*xy+5. State your conclusion in each case.

Now, going back to the function j, let R be the triangle having vertices (0,0),((4,0), and (0,4). We already know the local extrema in R since we've looked at the only critical point in the interior of R. Now, we must check the boundary:

A.) For the segment on the x-axis, y=0 and therefore j is 0 on this segment of the boundary.

B.) For the segment on the y-axis, set j2(y)=j(0,y) and find the extrema of j2 on the interval [0,4]:

> j2:=j(0,y);

> j2prime:=diff(j2,y);

> solve(j2prime=0,y);

Since the critical point of j2 isn't in the interval, then j2 has a min at y=0 and a max at y=4 (you can check this by hand).

C.) The segment from (0,4) to (4,0) can be parametrized by x(t)=t, y(t)=4 - t, for t in [0,4].

> j3:=j(t,4-t);

> j3prime:=simplify(diff(j3,t));

> solve(j3prime=0,t);

The (one-dimensional) second derivative test fails to say whether this critical point is a local max/min for j3:

> subs(t=3,diff(j3prime,t));

In fact, there is neither a max nor a min for j3 when t=3, as its graph shows:

> plot(j3,t=0..4);

Therefore, j can only have its extrema on R either on the triangles vertices or at the local min (2,0.5).

> j(0,0),j(0,4),j(4,0),j(2,0.5);

Based on these computations, we see that its absolute min occurs at (2,0.5) and its absolute max occurs at (0,4).

Let's look at a picture of this and see if our answers make sense. The blue dots are are the absolute max and min, the green is the triangle region in the x-y plane, and the red lines are the surface above the triangle. Look at this picture from several different angles until you can see what is going on.

> a:=plot3d(j(x,y), x=-.5..4.5, y=-.5..4.5, style=wireframe, shading=z,axes=frame, orientation=[-13,74]):

> b:=plot3d(-0.25, x=1.7..2.3, y=.2..0.8, style=patchnogrid, color=blue):

> c:=plot3d(28, x=-.3..0.3, y=3.7..4.3, style=patchnogrid, color=blue):

> d:=plot3d(0, x=0..4, y=-.15..0.15, style=patchnogrid, color=red):

> e:=plot3d(j2(y), x=-.15..0.15, y=0..4, style=patchnogrid, color=red):

> f:=plot3d(j3, t=0..4, y= (3.85-t)..(4.15-t), style=patchnogrid, color=red):

> t1:=plot3d(0, x=0..4, y=-.15..0.15, style=patchnogrid, color=green):

> t2:=plot3d(0, x=-.15..0.15, y=0..4, style=patchnogrid, color=green):

> t3:=plot3d(0, t=0..4, y= (3.85-t)..(4.15-t), style=patchnogrid, color=green):

> display({a,b,c,d,e,f,t1,t2,t3});

As a final example, let's find the absolute extrema of j on the disk given by x^2+y^2<=1. From our work above, the interior of this unit disk contains no critical points; we therefore must look on the boundary for the extrema. We can parametrize this circle by x(t)=cos(t),y(t)=sin(t) for t in [0,2*Pi].

> J:=j(cos(t),sin(t));

> plot(J,t=0..2*Pi);

This plot gives a good idea of the location of the extrema of j on the circle. We can use fsolve to find the exact locations in terms of t, which can then be converted into x and y coordinates.

> t1:=fsolve(diff(J,t)=0,t,0..3);

> t2:=fsolve(diff(J,t)=0,t,3..5);

> x1:=cos(t1);y1:=sin(t1);x2:=cos(t2);y2:=sin(t2);

The function values at these points are:

> j(x1,y1); j(x2,y2);

So the maximum value of j on on the disk given by x^2+y^2<=1 is 5.299733172, and the minimum is -4.000000002.

Again, let's look at a picture of this and see if our answers make sense. The blue dots are are the absolute max and min, the brown is the circular region in the x-y plane, and the red curve is on the surface above (or below) the circle. Look at this picture from several different angles until you can see what is going on.

> a:=plot3d(j(x,y), x=-1.25..1.25, y=-1.25..1.25, style=wireframe,axes=frame, shading=zhue, orientation=[-17,84]):

> b:=plot3d(j(x1,y1), x=(x1-0.15)..(x1+0.15), y=(y1-0.15)..(y1+0.15), style=patchnogrid, color=blue):

> c:=plot3d(j(x2,y2), x=(x2-0.15)..(x2+0.15), y=(y2-0.15)..(y2+0.15), style=patchnogrid, color=blue):

> s:=spacecurve([cos(t), sin(t), j(cos(t),sin(t))], t=0..2*Pi, thickness=3, color=red):

> g:=spacecurve([cos(t), sin(t), 0], t=0..2*Pi, thickness=3, color=brown):

> display({a,b,c,s,g});

Exercise 2.5 a. Make print outs of good views of the two pictures above.

b. Determine the absolute max/min points and values for p from Exercise 2.4 on the square with vertices (0,0), (3,0), (3, -3), and (0, -3). Bonus points for making pictures similar to the two above for p from Exercise 2.4 on the square with vertices (0,0), (3,0), (3, -3), and (0, -3).

Exercise 2.6 Do exercise 33 in 12.7. Plot little dots at the local max's so you can see where they are.