Example

Find the local maxima and minima of f(x, y)  =  (x^2) y  -  2 x y  +  
          2  (y^2) - 15  y.

Solution.

f[x_, y_]  =  (x^2) y  -  2 x y  +  2  (y^2) - 
          15  y;

The first and second partial derivatives are:

D[f[x, y], x]

D[f[x, y], y]

D[f[x, y], {x, 2}]

D[f[x, y], {y, 2}]

D[f[x, y], x, y]

The crititcal points are:

cps  =  
      Solve[{D[f[x, y], x]  ==  0,  
          D[f[x, y], y] == 0}]

Next we apply the Second Derivative Test at the criticial points.

d[x_, y_]  =  
      D[f[x, y], {x, 2}] D[f[x, y], {y, 2}] - D[f[x, y], x, y]^2

Plug the critical points into d:

d[x, y]  /.  cps

D[f[x, y], {x, 2}]  /.  cps

f[x, y]  /.  cps

Since d(-3, 0)  = -64  <  0and d(5, 0)  = -64 <  0, the graph of f curves in different directions at each of these points and thus f has saddle points at (-3, 0) and (5, 0).
Since d(1, 4) =  32 > 0and (Subscript[f, xx])(1, 4)  =  8  >  0, the graph of f is curved up in all d irections at (1, 4) and therefore has a local mininum there, f(1, 4)  =  -32.

Plot3D[f[x, y], {x, -5, 7}, {y, -5, 10},  
      BoxRatios -> {1, 1, 2}]

Example

Find the local maxima and minima of f(x, y)  =  (x^3) -  6  (x^2) - 3  (y^2).

Solution.

f[x_, y_]  = (x^3) -  6  (x^2) - 3  (y^2);

The first and second partial derivatives are:

D[f[x, y], x]

D[f[x, y], y]

D[f[x, y], {x, 2}]

D[f[x, y], {y, 2}]

D[f[x, y], x, y]

The crititcal points are:

cps  =  
      Solve[{D[f[x, y], x]  ==  0,  
          D[f[x, y], y] == 0}]

Next we apply the Second Derivative Test at the criticial points.

d[x_, y_]  =  
      D[f[x, y], {x, 2}] D[f[x, y], {y, 2}] - D[f[x, y], x, y]^2

Plug the critical points into d:

d[x, y]  /.  cps

D[f[x, y], {x, 2}]  /.  cps

f[x, y]  /.  cps

Since d(0, 0)  = 72  >  0, and (Subscript[f, xx])(0, 0)  = - 12  <  0, the graph of f curves down in all directions at this point and thus f has a local maximum at (0, 0).
Since d(4, 0) =  -72 < 0, the graph of f curves in different directions at this point and f has a saddle point at (4, 0).

Plot3D[f[x, y], {x, -3, 7}, {y, -5, 5},  
      BoxRatios -> {1, 1, 2}]

Example

Find the local maxima and minima of f(x, y)  =  (x^2) -  2 x y  +  (y^2).

Solution.

f[x_, y_]  =  (x^2) -  2 x y  +  (y^2);

The first and second partial derivatives are:

D[f[x, y], x]

D[f[x, y], y]

D[f[x, y], {x, 2}]

D[f[x, y], {y, 2}]

D[f[x, y], x, y]

The crititcal points are:

cps  =  
      Solve[{D[f[x, y], x]  ==  0,  
          D[f[x, y], y] == 0}]

d[x_, y_]  =  
      D[f[x, y], {x, 2}] D[f[x, y], {y, 2}] - D[f[x, y], x, y]^2

f[x, y]  /.  cps

The Second Derivative Test is inconclusive since d is always 0. There is a whole line of critical points, y  =  x, where the function has the value 0. In fact, the function is a perfect square, f(x, y)  =  (((x  -  y))^2) ≥ 
          0, and thus has an absolute minumum of 0 along the line y  =  x.

Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5},  
      BoxRatios -> {1, 1, 2}]

Example

Find the local maxima and minima of g(u, v)  =  3 - | 
          u - 2 | + |v + 1|.

Solution.

g[u_, v_]  =  3  -  Abs[u - 2]  +  Abs[v + 1];

The first and second  partial derivatives do not exist along the lines u  =  2 and v = -1. (The first partial derivates are non-zero constants and the second partial derivatives are 0 away from these lines. ) The critical points are therefore the points on these lines, i.e., points of the form (2, v) or (u, -1).

The graph reveals that there are no local maxima or minima.

Plot3D[g[u, v], {u, 0, 4}, {v, -3, 1},  
      BoxRatios -> {1, 1, 1}]

Example

Find the absolute maximum and minimum of f(x, y)  =  
        (x^2) + 4  x y  +  (y^2) -  2  x in the region D  =  {(x, y)  |  -2  ≤  
              x  ≤  2,  -1  ≤  
            y  ≤ 1 }.

Solution.

f[x_, y_]  =  (x^2) + 4  x y  +  (y^2) -  2  x;

The first partial derivatives are:

D[f[x, y], x]

D[f[x, y], y]

The crititcal points are:

cps  =  
      Solve[{D[f[x, y], x]  ==  0,  
          D[f[x, y], y] == 0}]

This points lies inside the region, so we check the function value there:

f[x, y]  /.  cps

Now we need to find the extreme values of fon the boundary of D which has four parts, x  =  -2, x  =  2, y  =  -1, and y  =  1. We consider each case separaetly.

x  =  -2:

g[y_]  =  f[-2, y]

g'[y]

Since g' (y)  <  0 for -1  ≤  y  ≤  1, g is decreasing on this interval and the extreme values are at the endpoints:

g[-1]

g[1]

x  =  2:

g[y_]  =  f[2, y]

g'[y]

g' (y)  =  0 for y  =  -4 which is out of range. Thus, the extreme values are again at the endpoints:

g[-1]

g[1]

y  =  -1:

g[x_]  =  f[x, -1]

g'[x]

g' (x)  =  0 for x  =  3 which is out of range. Thus, the extreme values are again at the endpoints (which we already computed above):

g[-2]

g[2]

y  =  1:

g[x_]  =  f[x, 1]

g'[x]

g' (x)  =  0 for x  =  -1 which is in range. Thus, the extreme values of g are at the endpoints (which we already computed above) or at this critical point:

g[-2]

g[2]

g[-1]

Considering all the critical points found in the above steps, the maximum of f(-2, -1)  =  17 is 17 and the minimum is  f(2, -1) = -7.

Plot3D[f[x, y], {x, -2, 2}, {y, -1, 1},  
      BoxRatios -> {1, 1, 2}]