I am applying a function (NMinimize) to each element of a list. The function converges for some parameters (elements of the list) but not for others. However, the function always gives me a solution even if it does not converge. I get some error messages when the function doesn’t converge, but they don’t tell me which elements of the list failed. See the sample code below:
f[{a_, b_, c_}] := Quiet[Check[NMinimize[a x^2 + b x + c, x], NMinimize::cvdiv]]
l = {{1, 2, 3}, {-1, 2, 3}};
r = f /@ l
which now returns
{{2., {x -> -1.}}, NMinimize::cvdiv}
So you can simply discard all theNMinimize::cvdiv entries. You can also use your own error message
f[{a_, b_, c_}] := Quiet[Check[NMinimize[a x^2 + b x + c, x], "opps", NMinimize::cvdiv]]
returns
{{2., {x -> -1.}}, "opps"}
Now Cases[] can be used to select the good results if needed. The position of each the “opps” or NMinimize::cvdiv is the same as the data position. This way you can also know which data failed entry failed. You can use `Position` to determine this.