1
$\begingroup$

I was playing with ArgMin but I'm not sure how to use it for constrained optimization.

For example,

ArgMin[x^2, x]

returns 0 as expected, but,

ArgMin[x^2, x ∈ Interval[{1, 2}]]

gives the error

ArgMin::objfs: The objective function {Subscript[x, 1]^2} should be scalar-valued.

I know it works using,

ArgMin[{x^2, x <= 2, x >= 1}, x]

but what's the point of intervals if you can't use them as sets/domains? Even more puzzling, it seems that it does not handle finite sets,

P = {-2, -1, 1, 2};
ArgMin[x, x ∈ P]

gives the error

ArgMin::ivar: x ∈ {-2, -1, 1, 2} is not a valid variable.

Anyone has an idea why ArgMin does not seem to handle those simple cases?

$\endgroup$
1
  • $\begingroup$ As already noted, a list of numbers is not a valid domain that can be fed to Element[]. Nevertheless, try this: With[{P = {-2, -1, 1, 2}}, ArgMin[{x, AnyTrue[P, EqualTo[x]]}, x]]. $\endgroup$ Dec 2, 2019 at 21:18

1 Answer 1

6
$\begingroup$
Clear["Global`*"]

ArgMin[x^2, x ∈ Interval[{1, 2}]]

(* ArgMin::objfs: The objective function {Subscript[x, 1]^2} should be scalar-valued.

ArgMin[x^2, x ∈ Interval[{1, 2}]] *)

The subscript in the error message indicates that it was expecting a vector. Use

ArgMin[x^2, {x} ∈ Interval[{1, 2}]]

(* 1 *)

For the second example,

P = {-2, -1, 1, 2};

RegionQ[P]

(* False *)

P is not a region. Define a region

reg = ImplicitRegion[Or @@ Thread[var == P], var];

Then

ArgMin[x, {x} ∈ reg]

(* -2 *)
$\endgroup$
6
  • $\begingroup$ Nice all this works! I get the set {x} instead of x, but could you explain a little the definition of a region you wrote? This seemed very esoteric to me, especially to just use a set as a region, it should be more straightforward, shouldn't it? $\endgroup$
    – Cryme
    Dec 1, 2019 at 21:38
  • 1
    $\begingroup$ Read the documentation for ImplicitRegion $\endgroup$
    – Bob Hanlon
    Dec 1, 2019 at 21:53
  • $\begingroup$ Sure, also the documentation of Thread and @@. I understand the construction now, but shouldn't there be a more straightforward way than using an implicit region with writing out explicitly var==-2 || var==-1... ? For example, I feel this should have worked but it does not: reg = ImplicitRegion[MemberQ[P, var], var] $\endgroup$
    – Cryme
    Dec 1, 2019 at 22:04
  • $\begingroup$ @OlivierMassicot - Issues on how it should work you'll have to take up with Wolfram $\endgroup$
    – Bob Hanlon
    Dec 1, 2019 at 22:11
  • 1
    $\begingroup$ It does not work because ImplicitRegion[MemberQ[P, var], var] evaluates to EmptyRegion[1] since MemberQ[{-2, -1, 1, 2}, var] evaluates to False, i.e., it cannot have a symbolic value. The logical expressions can return symbolic expressions. $\endgroup$
    – Bob Hanlon
    Dec 1, 2019 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.