4
$\begingroup$

I have plugged in the following problem

Minimize[{x^z, z >= 1, z <= 10, x >= 1}, {x, z}]

Can anyone explain please why the software does not provide the analytical solution? Clearly NMinimize is possible to use, but I am interested in the analytical solution which is $x=1$ and $1 \leq z\leq10$.

$\endgroup$
  • $\begingroup$ But z is bounded by 1 and i am interested in the theoretical solution $\endgroup$ – Y.L Jun 18 at 21:33
  • $\begingroup$ The software has a problem with the power argument and I am wondering why $\endgroup$ – Y.L Jun 18 at 21:34
  • $\begingroup$ Minimize[{z*Log[x], z >= 1 && z <= 10 && x >= 1}, {z, x}] does not work too. I think the extrema located at the boundary make a problem. $\endgroup$ – user64494 Jun 19 at 17:50
2
$\begingroup$

Solving the Karush-Kuhn-Tucker equations with Reduce, to do symbolic optimization code from here we get:

KTEqs[obj_ (*objective function*), cons_List (*constraints*), 
vars_List (*variables*)] := 
Module[{consconvrule = {GreaterEqual[x_, y_] -> LessEqual[y - x, 0], 
Equal[x_, y_] -> Equal[x - y, 0], 
LessEqual[x_, y_] -> LessEqual[x - y, 0], 
LessEqual[lb_, x_, ub_] -> LessEqual[(x - lb) (x - ub), 0], 
GreaterEqual[ub_, x_, lb_] -> LessEqual[(x - lb) (x - ub), 0]}, 
x, y, lb, ub, stdcons, eqcons, ineqcons, lambdas, mus, lagrangian, 
eqs1, eqs2, eqs3, alleqns, 
allvars},(*Change constraints to Equal and LessEqual form with \
zero on the right-hand side*)stdcons = cons /. consconvrule;
(*Separate the equality constraints and the inequality constraints*)
eqcons = Cases[stdcons, Equal[_, 0]][[All, 1]];
ineqcons = Cases[stdcons, LessEqual[_, 0]][[All, 1]];
(*Define the Lagrange multipliers for the equality and inequality \
constraints*)lambdas = Array[\[Lambda], Length[eqcons]];
mus = Array[\[Mu], Length[ineqcons]];
(*Define the Lagrangian*)
lagrangian = obj + lambdas.eqcons + mus.ineqcons;
(*The derivatives of the Lagrangian are equal to zero*)
eqs1 = Thread[D[lagrangian, {vars}] == 0];
(*Lagrange multipliers for inequality constraints \
are\[GreaterEqual]0 to get minima*)eqs2 = Thread[mus >= 0];
(*Lagrange multipliers for inequality constraints are 0 unless the \
constraint value is 0*)eqs3 = Thread[mus*ineqcons == 0];
(*Collect the equations*)alleqns = Join[eqs1, eqs2, eqs3, cons];
(*Collect the variables*)allvars = Join[vars, lambdas, mus];
(*Return the equations and the variables*){alleqns, allvars}]; 
torules[res_] := 
If[Head[res] === And, ToRules[res], List @@ (ToRules /@ res)]; 
KKTReduce[obj_(*objective function*), cons_List (*constraints*), 
vars_List (*variables*)] := 
Block[{kkteqs, kktvars, red, rls, objs, allres, minobj, sel, ret, 
minred, minredrls},(*Construct the equations and the \
variables*){kkteqs, kktvars} = KTEqs[obj, cons, vars];
(*Reduce the equations*)
red = LogicalExpand@
Reduce[kkteqs, kktvars, Reals, Backsubstitution -> True];
(*Convert the Reduce results to rules (if possible)*)
rls = torules[red];
(*If the conversion to rules was complete*)
If[Length[Position[rls, _ToRules]] == 
0,(*Calculate the values of the objective function*)
objs = obj /. rls;
(*Combine the objective function values with the rules*)
allres = Thread[{objs, rls}];
(*Find the minimum objective value*)minobj = Min[objs];
(*Select the results with the minimum objective value*)
sel = Select[allres, #[[1]] == minobj &];
(*Return the minimum objective value with the corresponding rules*)
ret = {minobj, 
sel[[All, 2]]},(*Else if the results were not completely converted to \
rules*)(*Use MinValue to find the smallest objective function value*)
minobj = MinValue[{obj, red}, kktvars];
(*Use Reduce to find the corresponding results*)
minred = 
Reduce[obj == minobj && red, kktvars, Reals, 
Backsubstitution -> True];
(*Convert results to rules,if possible*)minredrls = torules[minred];
ret = If[
Length[Position[minredrls, _ToRules]] == 0, {minobj, 
minredrls}, {minobj, minred}];];
(*Remove excess nesting from result*)
If[Length[ret[[2]]] == 1 && Depth[ret[[2]]] > 1, {ret[[1]], 
ret[[2, 1]]}, ret]];

KKTReduce[x^z, {z >= 1, z <= 10, x >= 1}, {x, z}]

(* {1, (x == 1 && z == 1 && μ[1] == 0 && μ[2] == 0 && μ[3] == 
1) || (x == 1 && z == 10 && μ[1] == 0 && μ[2] == 0 && μ[3] == 
10) || (x == 1 && 1 <= z <= 10 && μ[1] == 0 && μ[2] == 0 && μ[3] == z)} *)
$\endgroup$
  • $\begingroup$ Thanks @Mariusz Iwaniuk, I tried to apply the code but it doesn't seem to work. Can you please show how you do it? $\endgroup$ – Y.L Jul 22 at 16:07
  • $\begingroup$ @Y.L.I edited answer. $\endgroup$ – Mariusz Iwaniuk Jul 22 at 17:33
1
$\begingroup$

Usually with situations like this, it's because your solution may end up having a complex solution, if you don't add boundries, to say Reals, or Integers..However, after modifying your code some to:

Minimize[{x^z, Element[x | z, Reals], z >= 1, z <= 10, x >= 1}, {x, z}]

I also could not get it to evaluate a solution.

I suspect this just is too much for Minimize to handle.

Thankfully, NMinimize is here to save the day.

NMinimize[{x^z, z >= 1, z <= 10, x >= 1}, {x, z}]

or

NMinimize[{x^z,Element[x | z, Reals], z >= 1, z <= 10, x >= 1}, {x, z}]

{*{1., {x -> 1., z -> 10.}}*}

Which gives you a solution, minimized with respect to x, in your conditions.

$\endgroup$
1
$\begingroup$

In theory Minimize[] should return a single point from your optimum line x==1. Not sure the internal algorithm it uses, or why it stumbles on this, but it is not designed to return a range anyway.

When you put in a constraint on x==1 then the function seems to always return a value halfway between lower and upper bounds on z, for example...

Minimize[{x^z, 1 <= z <= 100, x == 1}, {x, z}]

(* {1, {x -> 1, z -> 50}} *)
$\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.