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.
Enter the function
f = 5 x + 7 y - x y - x^2 - y^2into Mathematica. Equations defining the critical points are given by
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.
Enter the function
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.
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,
, using the equations for the the first derivatives of g found
above:
dtest = D[eqn1,x] D[eqn2, x] - D[eqn1,y]^2To 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/.gsolsComparing the output of this command with
D[eqn1, x]/.gsolstells us which are maxima, which minima, and which are saddles.
Pick a homework problem, for example
and use the techniques shown above to find the extrema.