3
$\begingroup$

Is it possible to generate a set of constraints in the form "$\forall$". For example:

\begin{align} \min\ & f\left(\sum x_i\right)\\ s.t.\ & \\ & x_i\geq 17 && \forall i=1,...,n. \end{align} What would be the best way to create this set of constraints in the code? Possibly when using FindMin or NMinimize.

$\endgroup$
3
  • 3
    $\begingroup$ n=5; vars=Array[x,n]; NMinimize[{f[Total[vars]], And @@ (# >= 17 & /@ vars)}, vars] $\endgroup$
    – flinty
    Jul 26 '20 at 2:30
  • 2
    $\begingroup$ ForAll is for different things in Mathematica's Logic & Boolean Algebra features when used with Resolve,Reduce, and FindInstance and not relevant to numerical minimization here. $\endgroup$
    – flinty
    Jul 26 '20 at 2:42
  • $\begingroup$ NMinimize[Join[{f[Total[vars]]}, Thread[vars >= 17]], vars] should also do... When the first argument of NMinimize is a list, the first entry is interpreted as objective function and the remaining ones are interpreted as constraints. $\endgroup$ Jul 26 '20 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.