# Lagrange multipliers code runs forever

I am writing a code for a Lagrange multipliers problem with three variables. My code looks like this:

 f[x_, y_, z_] := (m1 x + m2 y + m3 z)/Sqrt[m1^2 x + m2^2 y + m3^2 z]
g[x_, y_, z_] := x + y + z - 1
Minimize[{f[x, y, z], g[x, y, z] == 0,
m1 > 0, m2 > 0, m3 > 0, x > 0, y > 0, z > 0}, {x, y, z}]


But it keeps running with no answer, why is that?

• Given the equality constraint g, why don't you simplify the problem to a two-variable one, Minimize[{f[x, y, 1 - x - y], x + y < 1, m1 > 0, m2 > 0, m3 > 0, x > 0, y > 0}, {x, y}], and furthermore solve for the first-order conditions instead of using brute-force minimisation? Sep 24, 2015 at 4:39
• You won't get a min if all ms are different :) Sep 24, 2015 at 5:30
• Why is that, belisarius? Sep 24, 2015 at 12:00

I would first note that the problem you are posing can be reduced to a two-variable one by substituting in your inequality constraint, to eliminate z. I note that your constraint g implies x + y < 1.

Minimize[{f[x, y, 1 - x - y], x + y < 1, m1 > 0, m2 > 0, m3 > 0,
x > 0, y > 0}, {x, y}]


I then tried solving the unconstrained problem by differentiating the value function to get the first-order conditions and Solveing for them:

Solve[{D[f[x, y, 1 - x - y], x] == 0,
D[f[x, y, 1 - x - y], y] == 0}, {x, y}]


This yields an empty set {}.

Traditionally, when solving the Lagrangian, you include the constraint in the equations to be solved, like this:

Solve[{D[f[x, y, 1 - x - y] + lambda (1 - x - y), x] == 0,
D[f[x, y, 1 - x - y] + lambda (1 - x - y), y] == 0}, {x, y}]


This gives a (complicated) answer almost immediately. I would note that setting lambda (the Lagrangian multiplier) to zero in the solution generates a division by zero, confirming that lambda is non-zero and the required constraint g is an equality.

• Here is what I get: Solve::nsmet: This system cannot be solved with the methods available to Solve. >> Solve[{D[f[x, y, 1 - x - y] + lambda (1 - x - y), x] == 0, D[f[x, y, 1 - x - y] + lambda (1 - x - y), y] == 0}, {x, y}] Can you help me interpret this? Sep 24, 2015 at 11:59

To confirm @belisarius comment:

f[x_, y_, z_] := (m1 x + m2 y + m3 z)/Sqrt[m1^2 x + m2^2 y + m3^2 z]
g[x_, y_, z_] := x + y + z - 1

L = f[x, y, z] + λ g[x, y, z];
Solve[{Grad[L, {x, y, z}] == 0, g[x, y, z] == 0, m1 > 0, m2 > 0,
m3 > 0, x > 0, y > 0, z > 0}, {x, y, z, λ}]
{}

Simplify[Reduce[{Grad[L, {x, y, z}] == 0, g[x, y, z] == 0, m1 > 0,
m2 > 0, m3 > 0, x > 0, y > 0, z > 0}, {x, y, z, λ}],
m1 > 0 && m2 > 0 && m3 > 0] calculated with Mma 10.2 on Windows 10