# (Custom) domain restrictions for NMaximize

I'm new to mathematica, so please be forbearing with me :D

I would like to use NMaximize together with domain restriction (where the domain is a custom domain).

I've got an example:

dom = {1, 2, 3, 4};
NMaximize[{UP[fl, a, p], UA[fl, a, p] >= resutil,
D[UAS[fl, a, p], X[a]] == D[DA[a], a], MemberQ[dom, a] == True}, {a,
p}]


I would like to maximize UP(.), subject to the given constraints (including that the result for a is a member of dom).

The maximization works fine if I set the constraint to a \[Element] Integers:

NMaximize[{UP[fl, a, p], UA[fl, a, p] >= resutil,
D[UAS[fl, a, p], X[a]] == D[DA[a], a], a \[Element] Integers}, {a,
p}]


Is there a way to include such a constraint into NMaximize?

Thank you very much for your help :)

• Can't you combine Integers with adding UP>0&&UP<5 in the curly brackets? – Feyre Jul 17 '16 at 11:10
• Thank you Feyre, maybe the example above isn't the best. Let's say the solution where a is restricted to Integers is a=4 and p=0.25; in a second step I would like to limit the possible values for a to dom={1,2,5,7,8} and find the optimal values for a and p where a \element dom – Stephan Jul 17 '16 at 11:14
• If dom is a small list in fact, what's the trouble with brute-force enumeration? – J. M. will be back soon Jul 17 '16 at 11:40
• Thank you J.M :) .. dom is not necessarily a small list. Anyhow, even if dom were a small list, p can take any value (i.e., there are a lot possible combinations of a and p) – Stephan Jul 17 '16 at 11:47

As I understand your question your are trying to use NMaximize where you want to constrain a parameter to belong to a custom domain.

One way to do it is to use Or on the individual elements of the domain list.

dom = {1, 2, 3, 4};

Or @@ Map[a == # &, dom]

(* a == 1 || a == 2 || a == 3 || a == 4 *)


Use this in NMaximize as a constraint.

NMaximize[{a^2, Or @@ Map[a == # &, dom]}, a]

(* {16., {a -> 4.}} *)

• Thank you very much for your help :) That's exactly what I was trying to do :) – Stephan Jul 17 '16 at 14:55