# Constrained optimization with three variables

A standard optimization problem in economics is choosing a consumption bundle subject to prices and a budget constraint:

$$\max_{x,y} \sqrt{x} + \sqrt{y} \hspace{1cm} \text{s.t. } p_x \cdot x + p_y \cdot y \leq w$$ With the two goods, x and y, these solve easily in Mathematica:

assumptions = x >= 0 && y >= 0 && px > 0 && py > 0 && w > 0;
FullSimplify[ArgMax[{Sqrt[x] + Sqrt[y], px*x + py*y <= w && assumptions},
{x,y}], assumptions]


As it should, this yields: $$x^*=\frac{w p_y}{p_x (p_x+p_y)}, \hspace{2cm} y^*=\frac{w p_x}{p_y(p_x+p_y)}$$

The problem with three goods is:

$$\max_{x,y,z} \sqrt{x} + \sqrt{y} + \sqrt{z} \hspace{1cm} \text{s.t. } p_x \cdot x + p_y \cdot y + p_z \cdot z \leq w$$

Solving it analogously for some reason does not work for me:

assumptions = x >= 0 && y >= 0 && z >= 0 && px > 0 && py > 0 && pz > 0 && w > 0;
FullSimplify[ArgMax[{Sqrt[x] + Sqrt[y] + Sqrt[z], px*x + py*y + pz*z <= w && assumptions},
{x, y, z}], assumptions]


Mathematica accepts it and runs indefinitely without giving an answer. The problem is really only slightly more difficult than the two-variable case. You just get the optimality conditions from the Lagrangian and then solve as a system of four equations (instead of 3 as above) and get: $$x^*=\frac{w p_y p_z}{p_x (p_xp_y+p_xp_z+p_yp_z)}, \hspace{1cm} y^*=\frac{w p_x p_z}{p_y (p_xp_y+p_xp_z+p_yp_z)}$$ $$z^*=\frac{w p_x p_y}{p_z (p_xp_y+p_xp_z+p_yp_z)}$$

Why is Mathematica unable to work that out when it can handle the two-variable case almost instantaneously?

• The three variable case devours all available memory on my PC and then starts storing material on disk, which accounts for the slow-down. But, why it requires so much memory is not obvious to me. – bbgodfrey Mar 24 '16 at 23:11

As I noted in a comment above, the three-variable case devours all available memory in my 8 GB PC, at which point it slows greatly. Why it needs so much memory is unclear to me. However, here is a work-around. Replace the three variables by their squares to eliminate the Sqrt, and then square the result.
#^2 & /@ FullSimplify[ArgMax[{x + y + z, px*x^2 + py*y^2 + pz*z^2 <= w

• @Shane Thank you. I agree that the Sqrts probably are the source of the difficulty. – bbgodfrey Mar 24 '16 at 23:39
• If it is the Sqrts, it's particularly odd that the problem surfaces in the 3-variable case but not the 2-variable case. Or perhaps the 2-variable case also sucks up a ridiculous amount of memory but just not quite too much so that it hits the slowdown? – Shane Mar 24 '16 at 23:45