I have a nested list with each element containing FindRoot like this:

{FindRoot[a,b], FindRoot[c,d], FindRoot[e,f],...}

Depending on the parameters a,b,..., the output looks like


Let's say the second invocation of FindRoot throws a message e.g. The line search decreased the step size ..., i.e. the result {0,-1.57} is incorrect and should not make it to the output - how can I do that?

DeleteCases[{FindRoot[a,b], FindRoot[c,d], FindRoot[e,f]},Except[{{_Real,_Real}...}]]

returns with an empty list, even when there is no error message.

  • 6
    $\begingroup$ Check[FindRoot[a, b], Nothing]? $\endgroup$
    – Carl Woll
    Commented May 5, 2022 at 22:26
  • $\begingroup$ @Carl: In your example, if FindRoot returns with an error message, Check returns with the string Nothing, which is what I would like to avoid altogther. Is there a way to not return anything (literally) in this case? $\endgroup$ Commented May 5, 2022 at 22:36
  • $\begingroup$ Nevermind. The docs say "Nothing represents an element of a list that will automatically be removed." $\endgroup$ Commented May 5, 2022 at 22:45


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.