# Domain restrictions for NMaximize

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.

-
Select Element and press F1 for an overview in the documentation. –  user21 Sep 4 '13 at 15:15
Thanks, rubenko! I gather that my chosen domain was invalid to use the [Element] syntax. Another option I can think of is MemberQ, which unfortunately does not work either (I updated the post accordingly). So, I am out of ideas again... –  Andreas Sep 4 '13 at 15:26
NMaximize[{x^2, 0 < x < .5, Element[x, Reals]}, {x}] something like this ? –  Rorschach Sep 4 '13 at 15:35
Unfortunately, this will not work, as I need to restrict the variable to a set of discrete options. (Obviously it would work for this example, but my real application has some 300 variables and >500 other constraints, so there is no way I could guarantee a border solution like above) –  Andreas Sep 4 '13 at 15:41

Map[(NMaximize[{x^2, #[[1]] < x < #[[2]],