I need to find the minimum of a function $mj_1^2+mj_2^2$ where my $mj$ are constrained.

I wrote this expression:

  {mj1^2 + mj2^2, mj1 == (M1 + 1)*p1, p1 ∈ Integers, 
   mj2 == (M2 + 1)*p2, p2 ∈ Integers, 
   MemberQ[{mj1, mj2} , couplesm]}, {mj1, mj2}]

Indeed, my mj's must be multiples of Mj + 1, and they musn't be part of a list given by couplesm.

When I evaluate it, I get the following message;

ArgMin::infeas: There are no values of {mj1, mj2} for which the constraints False are satisfied and the objective function mj1^2 + mj2^2 is real valued.

I even added p1 and p2 to the variables of minimization, but it still didn't work.

How can I find the minimum of: $mj_1^2+mj_2^2$, where $mj_i$ is a multiple of $M_i+1$ and where the pairs $(mj_1,mj_2)$ can't be inside of the list couplesm?


I wrote the following and the code still doesn't work.

couplesm = {{0, 0}}

{{0, 0}}

  {mj1^2 + mj2^2, 
   IntegerQ[mj1/(M1 + 1)], IntegerQ[mj2/(M1 + 1)], 
   mj1 ∈ Integers, mj2 ∈ Integers, 
   Sequence @@ Table[{mj1, mj2} != couplesm[[i]], {i, 1, Length[couplesm]}]}, 
  {mj1, mj2}]

ArgMin::infeas: There are no values of {mj1,mj2} for which the constraints False are satisfied and the objective function mj1^2+mj2^2 is real valued.

{Indeterminate, Indeterminate}

  • $\begingroup$ What are the definitions of p1, p2 and couples? $\endgroup$ – m_goldberg Jun 28 '17 at 17:35
  • $\begingroup$ $p_1$ and $p_2$ are just positive integers. They are here to symbolise the fact that I want $mji$ to be a multiple of $Mi+1$. couplesm is a list of couples like this : {{a,b},{c,d},{e,f}}. I don't want (mj1,mj2) to be an element of this list. To take an example you can take couplesm={{0,0}} to start with $\endgroup$ – StarBucK Jun 28 '17 at 17:38
  • 1
    $\begingroup$ The arguments of ArgMin are evaluated first. Evaluate MemberQ[{mj1, mj2} , couplesm] to see where the False in the error message comes from. $\endgroup$ – Michael E2 Jun 28 '17 at 17:38
  • $\begingroup$ I don't understand. I can't evaluate it first as mj1 and mj2 are changed by Argmin. They don't have a value outside of this function ? $\endgroup$ – StarBucK Jun 28 '17 at 17:39
  • 1
    $\begingroup$ "I can't evaluate it first as mj1 and mj2 are changed by Argmin." -- Actually, Mathematica evaluates it first, before passing the result False to ArgMin[]. Therefore ArgMin[] never has a chance to change mj1 or mj2 or see whether the pair of values are a member of couplesm. You need a function like memQ[x1_Integer, x2_Integer] := MemberQ[{x1, x2}, couplesm]., and then replace MemberQ[{mj1, mj2} , couplesm] with memQ[{mj1, mj2}]. $\endgroup$ – Michael E2 Jun 28 '17 at 19:34

Maybe this?

couplesm = {{0, 0}, {3, 0}};

Block[{M1 = 2, mj1 = (M1 + 1) m1, mj2 = (M1 + 1) m2},
  {mj1^2 + mj2^2,
   AllTrue[couplesm, {mj1, mj2} != # &]},
  {m1, m2},
(*  {-1, 0}  *)

In general, avoid functions that end in Q, such as IntegerQ and MemberQ, in constructing equations and constraints for solvers. Almost all of them evaluate to True or False immediately, that is, before values are substituted for the variables. If, for some reason, you need to use one, you need to construct a wrapper function that will evaluate the Q function only after the variables have been given numeric values (using ?NumericQ).

  • $\begingroup$ Are the m1 ∈ Integers and m2 ∈ Integers necessary when you're setting the domain to be Integers? $\endgroup$ – aardvark2012 Jun 29 '17 at 6:08
  • $\begingroup$ @aardvark2012 No, I meant to get rid of them. Thanks for pointing it out. $\endgroup$ – Michael E2 Jun 29 '17 at 14:03

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.