next up previous contents
Next: Polar Coordinates Up: Computational Labs in Mathematica Previous: GradientsNormals, Level Curves

Extrema of Functions

Objectives

In this lab you will learn to use Mathematica to help extremize functions of several variables. In particular you will use commands to find numerical solutions which would be impossible to find by hand.

Finding Critical Points

Enter the function

       f = 5 x + 7 y - x y - x^2 - y^2
into Mathematica. Equations defining the critical points are given by

displaymath338

The right-hand-sides of these equations can determined easily in Mathematica,

       rhs1 = D[f,x] 
       rhs2 = D[f,y]
For equations which have analytic solutions, Mathematica has a solution algorithm:
       Solve[{rhs1 == 0, rhs2 == 0}, {x,y}]
The command above solves a system of equations (rhs1 =0, rhs2=0) for the two variables (x and y). The solution thus generated comes out in the form of a substitution rule. Use Plot3D in the vicinity of the solution point to determine whether the solution you have found is a max, min, or saddle point.

A More Complicated Extremization

Enter the function

displaymath340

into Mathematica as you did for the function f above. If you find the equations for the critical points of g using Mathematica,

       eqn1 = D[g,x]
       eqn2 = D[g,y]
When you see these equations it should look pretty obvious that solving the equations by hand would not be optimal. To achieve a numerical solution, try
       gsols =  NSolve[{eqn1 == 0, eqn2 == 0},{x,y}]
Use Plot3D on this function to see if you can ascertain what the different critical points correspond to in terms of maxs, mins, and other.

The Second Derivative Test

For a complicated function like g, the second derivative test is particularly noxious. However, in Mathematica it is easy. For example, we can define the second derivative test, tex2html_wrap_inline348 , using the equations for the the first derivatives of g found above:

       dtest = D[eqn1,x] D[eqn2, x] - D[eqn1,y]^2
To see what the second derivative test says for the critical points found above, we can just use the fact that the solutions come out as substitutions to jam the critical points into the test.
       dtest/.gsols
Comparing the output of this command with tex2html_wrap_inline352 evaluated at the fixed points,
       D[eqn1, x]/.gsols
tells us which are maxima, which minima, and which are saddles.

Finally

Pick a homework problem, for example

displaymath354

and use the techniques shown above to find the extrema.


next up previous contents
Next: Polar Coordinates Up: Computational Labs in Mathematica Previous: GradientsNormals, Level Curves

James Powell
Fri Feb 14 12:47:33 MST 1997