# Constraints thread over lists, for NMinimize

I have the following code

fc[x_] := a + b*x^c + d*x^e

listNumber = {1,2,3,4,5}

list = {a,b, c,.. , e}

answF = NMinimize[{Abs[fitFl],
fc[listNumber[[1]] ] <= 1 &&  fc[listNumber[[2]] ]  <= 1 && fc[listNumber[[3]] ] <= 1
&& fc[listNumber[[4]] ] <= 1 && fc[listNumber[[5]] ] <= 1,
list[[1]] > 5, list [[2]] >5} , {a, b, c, d,  e, qB, qT}]


I want to apply a constraint over every element in a list. I've hard coded above , how could I thread across the whole list. Similarly for the function, how could I thread across the whole list (listNumber).

Hard coding works for a small list, but if the size of the list increases, this becomes an issue.

• Why not And @@ Thread[fc[listNumber] <= 1]? – J. M. will be back soon Nov 14 '17 at 11:22
• J.M. I could not get that to work for the function, I suspect I'm missing some code. My "list" array is larger. Do you have any method for a list with no function. thks – SPIL Nov 14 '17 at 15:14

The code provided has undefined functions and constants. However, to generate a list of constraints could be done as:

fc[x_] := a + b*x^c + d*x^e;
listNumber = {1, 2, 3, 4, 5};
list = {a, b, c, d,e};
answF = NMinimize[Flatten@{Abs[fitFl], (fc[#] <= 1) & /@ listNumber, (# > 5) & /@list}, {a, b, c, d, e, qB, qT}]

• Jose, thanks that seems to work. Could I add a single constraint such as fc[6] in between the commas like this: NMinimize[Flatten@{Abs[fitFl], fc[6] ==1, (fc[#] <= 1) .......etc – SPIL Nov 15 '17 at 11:29
• Yes, as the new contraint does not fulfill the others. – José Antonio Díaz Navas Nov 15 '17 at 11:33