How can I determine which element of Min[] is being selected in a NMaximize[{Min[...], constraints},{vars}] problem? For example,

NMaximize[{Min[x, 1/(x - 1)], x >= 0, x <= 2}, {x}]
{1.61803, {x -> 1.61803}}

which is true for both elements. This is a very contrived example, though. In reality the space of elements is highly non-convex so I can't just use the answer and find the element using Select[], Position[], etc. for example. Somehow returning the position in Min[] in situ (and not post hoc) is something I was hoping for.

Addendum: I've tried using Monitor[] and Trace[] to gain some insight to what is going on but to no luck.

  • $\begingroup$ What about giving the different functions different units like Meter and Hour. Should be given back together with the numerical result. Can't test it now. $\endgroup$
    – Akku14
    Apr 28 at 17:44
  • $\begingroup$ @Akku14 clever! Unfortunately mathematica complains about incompatible units. I really like that suggestion though of a way to tag the elements. $\endgroup$ Apr 28 at 17:49

1 Answer 1

funcs = {x, 1/(x - 1)};

{max, arg} = NMaximize[{Min @@ funcs, x >= 0, x <= 2}, {x}]

{* {1.61803, {x -> 1.61803}} *)

Select[funcs, max == (# /. arg) &][[1]]

(* x *)

EDIT: Using NMaximize only one function is returned due to precision issues. To identify both, Maximize must be used

{max, arg} = Maximize[{Min @@ funcs, x >= 0, x <= 2}, {x}]

(* {1/2 (1 + Sqrt[5]), {x -> 1/2 (1 + Sqrt[5])}} *)

Select[funcs, max == (# /. arg) &]

(* {x, 1/(-1 + x)} *)
  • $\begingroup$ Thanks, unfortunately this does not work for my problem. I tried to clarify my question. I don't think any post hoc command like Select[] or Position[] will work for my case. $\endgroup$ Apr 28 at 16:50
  • $\begingroup$ Please provide an example that more accurately represents the problem. $\endgroup$
    – Bob Hanlon
    Apr 28 at 16:52
  • $\begingroup$ OK I will try but as stated in the question if there is a method that does this in situ instead of having to use the provided answer first the question will be solved. $\endgroup$ Apr 28 at 16:55

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.