I assigned several constrained optimization problems to my calc IV students to solve with Mathematica, but this one is being stubborn.
The function to optimize is: f(x,y,z) = y Exp[x-z] with the constraints: 9x^2 + 4y^2 + 36z^2 = 36 and xy + yz =1.
This obviously requires the gradient of the functions and two Lagrange multipliers. After storing the gradients into variables, here's the system of equations needed to solve:
gradf = Grad[y E^(x - z), {x, y, z}];
gradg = Grad[9 x^2 + 4 y^2 + 36 z^2 - 36, {x, y, z}];
gradh = Grad[x y + y z - 1, {x, y, z}];
NSolve[{
gradf == L gradg + M gradh,
9 x^2 + 4 y^2 + 36 z^2 == 36,
x y + y z == 1},
{x, y, z}, Reals
]
(note, the L and M are lambda and mu)
There are four critical values Mathematica should find, but no matter the solve technique I try or options used for the various solve methods, Mathematica never stops running. Built-in commands FindMaximum
and FindMaxValues
, etc., eventually find the solutions, but the original systems still remains illusive.
Can anyone shed some light on what options to use. Unfortunately Maple wins this round with the "allvalues" command.
Thanks for the help.
Plot[Evaluate[y Exp[(x - z)] /. # & /@ Solve[9 x^2 + 4 y^2 + 36 z^2 == 36 && x y + y z == 1, {x, y, z}]], {y, -3, 3}]
$\endgroup$ – Dr. belisarius Oct 16 '14 at 23:30