I am trying to solve a maximization problem, where my variable can only take a limited number of values. (Probably) the easiest example would be
dom = {0, 1/2}; NMaximize[{x^2, Element[x, dom]}, {x}]
While the Element[x,dom]
syntax works just fine for dom = Integers
, I keep getting error messages for any other domain. (edit: this seems to be because my chosen domain is invalid to use with ∈)
edit: I also tried the MemberQ
syntax as stated below:
dom = {0, 1/2}; NMaximize[{x^2, MemberQ[dom, x]}, {x}]
This seems to be an acceptable constraint, but for some reason Mathematica seems unable to find a value that meets the constraint, as I get the following message:
NMaximize::nsol: There are no points that satisfy the constraints {False}.
Any other ideas?
edit: just to clarify. I need to restrict the variable(s) to a finite set of real numbers, hence I cannot use ">=/<=" constraints to get the job done. The above is just the simplest application I could think of.
Element
and press F1 for an overview in the documentation. $\endgroup$ – user21 Sep 4 '13 at 15:15NMaximize[{x^2, 0 < x < .5, Element[x, Reals]}, {x}]
something like this ? $\endgroup$ – Sejwal Sep 4 '13 at 15:35