7
$\begingroup$

I want FindRoot to do NOTHING if it doesn't find a solution within a domain. Consider the simple example:

FindRoot[x + 3 == 4, {x, 5, 5, 6}]

FindRoot returns the following:

FindRoot::reged: The point {5.} is at the edge of the search region {5.,6.} in coordinate 1 and the computed search direction points outside the region.

{x -> 5.}

How can i force FindRoot to do nothing if there is no solution within a domain?

Thanks

$\endgroup$

1 Answer 1

6
$\begingroup$

One possible way

 Quiet[Check[FindRoot[x + 3 == 4, {x, 5, 5, 6}], {}, FindRoot::reged]]

Mathematica graphics

Or

 Quiet[Check[FindRoot[x + 3 == 4, {x, 5, 5, 6}],, FindRoot::reged]]

Which return nothing.

 Quiet[Check[FindRoot[Sin[x] + Exp[x], {x, 0}], {}, FindRoot::reged]]
 (*{x -> -0.588533}*)
$\endgroup$
1
  • 2
    $\begingroup$ One might want to include FindRoot::lstol, FindRoot::jsing, maybe FindRoot::cvmit (others?). (+1) $\endgroup$
    – Michael E2
    Commented Nov 26, 2017 at 18:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.