**Mth 243/1**

**Optimization of Functions of Several Variables**

**Introduction**

In this Maple session we give a computerized method for finding maximum, minimum, and saddle points of a function.

Define f(x,y) = . Note that this function, being a polynomial, is continuous on all of .

`> `
**f:=(x,y)->x^4-3*x^2-2*y^3+3*y+0.5*x*y;**

**Finding Critical Points**

You must find all points that make both first partial derivatives equal to zero. These points are called the critical points.

`> `
**criticalpt:=[fsolve({diff(f(x,y),x)=0,diff(f(x,y),y)=0},{x,y},maxsols=8)];**

**Second Derivatives Test**

The following table summarizes how to apply the second derivative test to each critical point.

Set: A =

and dis =

If dis < 0 at the critical point, then this point is a saddle point for the function f.

If dis > 0 at the critical point, then this point is a minimum (resp. maximum) point for the function f if A > 0 (resp. A < 0).

If dis = 0 at the critical point, then this test is inconclusive.

**Second Derivatives Test Applied to an Example**

Let us continue with our example:

`> `
**dis:= diff(f(x,y),x,x)*diff(f(x,y),y,y)-diff(f(x,y),x,y)^2;**

`> `
**subs(criticalpt[1],[dis,diff(f(x,y),x,x)]);**

**Visualizing the Results**

There are many ways that
*Maple*
can visualize the results. The easiest way to sketch the surface in 3-D is to use
**plot3d**
function.

You input an expression that gives the height of a surface above the xy-plane, in terms of independent variables x and y. You must also specify

bounds for the x- and y-variables. Here is an example:

`> `
**plot3d(f(x,y), x=-3..3, y=-3..3);**

`> `

In
*Maple*
, the level curves of a function f(x,y) are plotted with the
*contourplot*
function that is defined in the plots library. Here is an example:

`> `
**with(plots);**

**contourplot(f(x,y), x=-3..3, y=-3..3);**

To get more detailed and colorful graphs you can use some of the options as follows:

`> `
**contourplot(f(x,y), x=-3..3, y=-3..3, contours=30,filled=true,coloring=[green,yellow]);**

**Putting Everything Together**

The above step-by-step procedure can be executed in a single step as follows:

`> `

`> `
**f:=(x,y)->x^4-3*x^2-2*y^3+3*y+0.5*x*y;**

`> `

`> `
**criticalpt:=[fsolve({diff(f(x,y),x)=0,diff(f(x,y),y)=0},{x,y},maxsols=8)];**

`> `

`> `
**dis:= diff(f(x,y),x,x)*diff(f(x,y),y,y)-diff(f(x,y),x,y)^2;**

`> `

`> `
**subs(criticalpt[1],[dis,diff(f(x,y),x,x)]);**

`> `

`> `
**plot3d(f(x,y), x=-3..3, y=-3..3);**

`> `
**contourplot(f(x,y), x=-3..3, y=-3..3, contours=30,filled=true,coloring=[green,yellow]);**

**Second Example**

**Our second example is the function **

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

`> `
**criticalpt:=[fsolve({diff(f(x,y),x)=0,diff(f(x,y),y)=0},{x,y},maxsols=8)];**

`> `
**dis:= diff(f(x,y),x,x)*diff(f(x,y),y,y)-diff(f(x,y),x,y)^2;**

`> `
**subs(criticalpt[1],[dis,diff(f(x,y),x,x)]);**

`> `
**plot3d(f(x,y), x=-6..6, y=-6..6);**

`> `
**contourplot(f(x,y), x=-6..6, y=-6..6, contours=30,filled=true,coloring=[green,red]);**

**Exercises**

Apply the above procedure to the following functions

**1. **

**2. **
** **

Created by
*M.R.S. Kulenovic,*
Spring 1999