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,

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, 

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

Thank you very much for your help :)

  • $\begingroup$ Can't you combine Integers with adding UP>0&&UP<5 in the curly brackets? $\endgroup$ – Feyre Jul 17 '16 at 11:10
  • $\begingroup$ 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 $\endgroup$ – Stephan Jul 17 '16 at 11:14
  • $\begingroup$ If dom is a small list in fact, what's the trouble with brute-force enumeration? $\endgroup$ – J. M. is away Jul 17 '16 at 11:40
  • $\begingroup$ 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) $\endgroup$ – 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.}} *)
  • $\begingroup$ Thank you very much for your help :) That's exactly what I was trying to do :) $\endgroup$ – Stephan Jul 17 '16 at 14: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.