0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Verbeia Sep 24 '15 at 4:39
  • $\begingroup$ You won't get a min if all ms are different :) $\endgroup$ – Dr. belisarius Sep 24 '15 at 5:30
  • $\begingroup$ Why is that, belisarius? $\endgroup$ – odnerpmocon Sep 24 '15 at 12:00
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – odnerpmocon Sep 24 '15 at 11:59
1
$\begingroup$

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]

enter image description here

calculated with Mma 10.2 on Windows 10

$\endgroup$

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.