A nice little function KT
(based on Reduce
) that provides both optimal variables and corresponding Lagrange multipliers for simple and small problems can be found here
The following code takes about 15sec to evaluate on my pc:
f = (3/10)*Exp[-z2]*((9/100)*Exp[-(x + z1)] + (3/10)*Exp[-y]) +
(9/100)*Exp[-(x + z1)] + (3/10)*Exp[-x] + (3/10)*Exp[-y] + (3/10)*Exp[-z];
cons={x + y + z + z1 + z2 <= 100, x >= 0, y >= 0, z >= 0, z1 >= 0, z2 >= 0};
KT[-f, cons, {x, y, z, z1, z2}]
x == 1/3 (100 - 3 Log[2] - 3 Log[5] - Log[13] + 2 Log[139]) &&
y == 1/3 (100 + 2 Log[13] - Log[139]) &&
z == 1/3 (100 + 3 Log[2] + 3 Log[5] - Log[13] - Log[139]) &&
z1 == 0 &&
z2 == 0 &&
\[Lambda][1] == (3 1807^(1/3))/(100 E^(100/3)) &&
\[Lambda][2] == 0 &&
\[Lambda][3] == 0 &&
\[Lambda][4] == 0 &&
\[Lambda][5] == (3 13^(1/3))/(139^(2/3) E^(100/3)) &&
\[Lambda][6] == 3819/(100 1807^(2/3) E^(100/3))
The multipliers correspond to the constraints as entered in cons
, i.e., $\lambda_1$ corresponds to the sum constraint and the remaining multipliers to the non-negative constraints. Evaluating f
for the above values gives 3.65942*10^-15
.
On the other hand, using FindMinimum
may give a local minimizer depending on the initial values as the following test case shows:
FindMinimum[{f,And@cons}, {{x, 10}, {y, 10}, {z, 10}, {z1, 10}, {z2, 10}}]
{9.68425*10^-7, {x -> 13.7422, y -> 13.7422, z -> 13.7423,
z1 -> 13.1105, z2 -> 13.1105}}
FindMinimum
result you can determine which are the binding constraints, and then write down the corresponding Lagrangian equation(s) and useNSolve
orFindRoot
to solve for the multipliers. $\endgroup$