2
$\begingroup$

Since I am a student of Mathematics I enjoy to apply MMA to problems that I have a solid understanding in. The following would be such a problem:

Maximize $f: \mathbb{R}^3 \to \mathbb{R}$ given by $f(x,y,z):= 8xyz$ constrained to the ellipsoid $$ E:= \left\lbrace (x,y,z) \in \mathbb{R}^3: \frac{x^2}{a^2}+ \frac{y^2}{b^2}+ \frac{z^2}{c^2}=1 \right\rbrace $$ where $a,b,c>0$

Under the realistic assumptions that $x,y,z >0$ are all positive (because else wise the cuboid vanishes) this is an easy application by hand on paper with a little help from multivariate Calculus, namely the Lagrange multipliers.

After sume juggling with the gradients one obtains the solutions of the maximum $$x_0= \frac{a}{\sqrt{3}}, \ y_0 = \frac{b}{\sqrt{3}}, \ z_0 = \frac{c}{\sqrt{3}} \implies V_\max=f(x_0,y_0,z_0)= \frac{8abc}{3\sqrt{3}} $$


In Mathematica however I struggle to implement this problem:

f[x_,y_,z_]:= 8 x y z (* a naive R^3 -> R function *)

Then indeed I use the Maximize function with the appropriate constraints:

Maximize[{f[x,y,z], (x/a)^2+(y/b)^2+(z/c)^2 ==1 && a> 0 && b >0 && c>0}, {x,y,z}]

MMA manages to find the same Maximal volume as I did by hand, but for the variables $x,y,z$ it finds very peculiar results:

MMA output for the maximization

While the volume is correct, I wonder how I get the more realistic $x,y,z$ results as I did by hand.

Addendum: More realistically I would have rather defined a function as

g[x_ /; x>0, y_ /; y>0, z_ /; z>0]:= 8 x y z

But in this case Maximize won't even execute

$\endgroup$
2
  • 2
    $\begingroup$ FullSimplify[%, a > 0 && b > 0 && c > 0], where % is your initial result. $\endgroup$
    – Michael E2
    May 8, 2015 at 18:21
  • $\begingroup$ @MichaelE2 if you want you can add this as an answer so I can upvote and accept it. It seems that MMA requires the additional computation of FullSimplify, however the result it gives me is still a bit off, namely $x= - a/ \sqrt{3}, y= -b/ \sqrt{3}, z= c/\sqrt{3}$ I am happy enough however. $\endgroup$
    – Spaced
    May 8, 2015 at 18:31

1 Answer 1

4
$\begingroup$

Simplifying complicated results sometimes takes a long time, so many Mathematica functions do not do so by default. Or they do it under a time constraint. Such is the case here, and in addition, FullSimplify is needed to simplify the nested Root objects. Note we need to add the constraints as assumptions to get the desired simplification.

res = Maximize[{f[x,y,z], (x/a)^2 + (y/b)^2 + (z/c)^2 == 1 &&
        a > 0 && b > 0 && c > 0}, {x, y, z}]
FullSimplify[res, a > 0 && b > 0 && c > 0]
(*
  {(a b c)/(3 Sqrt[3]), {x -> -(a/Sqrt[3]), y -> -(b/Sqrt[3]), z -> c/Sqrt[3]}}
*)

P.S. There are four equivalent answers. If you want x, y, and x to be all positive, add more constraints. (Mathematica probably found the "first" one in the code above, and since negatives are sorted before positives, we got the solution that starts with two minuses.)

res = Maximize[{f[x y z], (x/a)^2 + (y/b)^2 + (z/c)^2 == 1 &&
        a > 0 && b > 0 && c > 0 && x > 0 && y > 0 && z > 0}, {x, y, z}];
$\endgroup$
2
  • 1
    $\begingroup$ Thank you, especially the first sentence makes indeed a lot of sense. $\endgroup$
    – Spaced
    May 8, 2015 at 18:37
  • 1
    $\begingroup$ @Spaced You're welcome. I added something, in case you wanted positive coordinates. It's a bit annoying, but that's because we're human, I suspect. M probably finds the "first" one, and since negatives are sorted before positives, we get the solution will all minuses. $\endgroup$
    – Michael E2
    May 8, 2015 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.