# Symbolic Constrained Optimization

I have a question regarding evaluating constrained optimization problems in symbolic terms. I would like to perform How can I implement the method of Lagrange multipliers to find constrained extrema? without specifying the objective function.

As a simple example, suppose I have a constrained utility maximization problem:

$\max\limits_{x,y} U(x,y)$

$s.t.\ p_xx+p_yy=I$

where $U_x,U_y>0$, the Hessian matrix of the second-order derivatives is negative definite, and $p_x$ and $p_y$ are unspecified coefficients.

Using Lagrangian multipliers, the first-order conditions are:

$U_x-\lambda$$p_x=0 U_y-\lambda$$p_y=0$
$I-p_xx-p_yy=0$

Of course, the model that I want to use is a little bit more complicated than this (otherwise it would be no problem doing it by hand). Thus, given an unspecified objective function $U(x,y)$ and budget constraint(s) with unspecified coefficients, I was wondering if it was possible in Mathematica to:
1) produce the first-order conditions, and
2) given the system of equations in (1), produce symbolic rather than numerical solutions, which are functions of $U_x$, $U_y$, $p_x$, $p_y$, etc.

Again, this differs from How can I implement the method of Lagrange multipliers to find constrained extrema? because: that question specified that the objective function $f(x,y,z)=xy+yz$, the coefficients of the constraints are implicitly equal to 1, and thus, it produces numerical solutions for the constrained extrema.

You can adapt the answer to the question, How can I implement the method of Lagrange multipliers to find constrained extrema?, to obtain the first-order system.

Clear[U, px, py, x, y];
f[x_, y_] := U[x, y];
g1[x_, y_] := budget - {px, py}.{x, y}

h[x_, y_, λ_] := f[x, y] - λ g1[x, y]

D[h[x, y, λ], {{x, y, λ}}] == {0, 0, 0}
]
(*
{px*λ + Derivative[1, 0][U][x, y] == 0,
py*λ + Derivative[0, 1][U][x, y] == 0,
-budget + px*x + py*y == 0}
*)


About the best I can do with an unspecified utility function U[x, y] is to eliminate λ:

Eliminate[
{px*λ + Derivative[1, 0][U][x, y] == 0,
py*λ + Derivative[0, 1][U][x, y] == 0,
-budget + px*x + py*y == 0},
λ
]
(*
budget == px*x + py*y &&
px*Derivative[0, 1][U][x, y] == py*Derivative[1, 0][U][x, y]
*)

• Thank you. I was able to execute this for my model for a utility function with two arguments without any issues. However, when I added included a third argument, I ran into a problem, and I think I want someone to look at my code. Should I start an entirely new question? Feb 13, 2014 at 21:59
• @Traci If I add a z and a pz in all the right places, I can still eliminate λ. The resulting system might look overdetermined, but it's not due to a nontrivial null space (in the equations involving the derivatives of U). If that's not the issue, then I'm guessing that you have a typo or some other mistake in your code. Or there more to what you did than just adding a z component. Feb 13, 2014 at 22:27
• thanks, though I probably should've been more specific. The problem actually isn't in eliminating λ. For some reason the arguments of U as I define it in the code are different from the arguments of U' in the output following the Thread command. Would this warrant a whole new question? I'm new to Stack Exchange, and I'm still figuring out the rules. Feb 14, 2014 at 5:07
• Clarifying a question is encouraged, but changing it is not. I can't tell for sure from what you've said whether it's closer to a clarification or it's really a separate issue. Your call. Feb 14, 2014 at 5:33
• okay, I think I'll start a new question. How do you copy and paste the code from Mathematica while retaining the symbols like you did? When I copy and paste, I get \[Lambda] instead of λ. Feb 14, 2014 at 15:57