18
$\begingroup$

Bug introduced in 9.0.1 or earlier and persisting through 12.3.1 or later


The following has no solution:

FindRoot[x == 1, {x, 0.25, 0, 0.5}]

And Mathematica correctly warns us:

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

If we use Quiet, we correctly suppress the message.

The following is exactly the same system, but here we ask for a specific numerical method

FindRoot[x == 1, {x, 0, 0.5}, Method -> "Brent"]

And we receive a similar warning:

FindRoot::bbrac: Method -> Brent is only applicable to univariate real functions and requires two real starting values that bracket the root.

But this time, if we add Quiet, we still receive the same warning.

Why isn't Quiet working (is it a bug)?

$\endgroup$
10
  • 1
    $\begingroup$ I'd say it's a bug. It's possible to shut it up by using both Check and Quiet: Quiet@Check[FindRoot[x == 1, {x, 0.25, 0, 0.5}, Method -> "Brent"], foo] $\endgroup$
    – Szabolcs
    Commented Feb 24, 2013 at 13:56
  • 1
    $\begingroup$ Quiet and ; together stop the message too. Could also use Off[FindRoot::bbrac] $\endgroup$ Commented Feb 24, 2013 at 14:41
  • 3
    $\begingroup$ I'd say it's a bug. TracePrint reveals two calls to Message[FindRoot::bbrac]. $\endgroup$ Commented Feb 24, 2013 at 14:49
  • 1
    $\begingroup$ Yep, two calls to Message, and one suppressed, but only if Quiet is used. Here's a way to check: messageHandler = Print[{##}] &; InternalAddHandler["Message", messageHandler];` It'll show things like Hold[Message[FindRoot::bbrac],True] where True means not suppressed using Quiet. $\endgroup$
    – Szabolcs
    Commented Feb 24, 2013 at 14:54
  • 1
    $\begingroup$ Looks to me like this is figured out. Why not write it up as an answer and get this question off the 'unanswered questions' list? $\endgroup$ Commented Oct 1, 2013 at 8:24

1 Answer 1

8
$\begingroup$

It's a bug: there are more than one call to Message[FindRoot::bbrac], and some of them are suppressed, but only if Quiet is used. Here's a way to check suggested by Szabolcs:

messageHandler = Print[{##}] &;
Internal`AddHandler["Message", messageHandler];
Quiet@FindRoot[x == 1, {x, 0, 0.5}, Method -> "Brent"]

<...>

{Hold[Message[FindRoot::bbrac],False]}

{Hold[Message[FindRoot::bbrac],False]}

{Hold[Message[FindRoot::bbrac],True]}

{Hold[Message[FindRoot::bbrac],True]}

When the last argument is True it means that the call was not suppressed by Quiet.

The suggested workarounds follow.

As already stated in the comments by Sjoerd, Quiet and ; together stop the message:

Quiet[FindRoot[x == 1, {x, 0, 0.5}, Method -> "Brent"];]

Another solution is to swith Off this message globally:

Off[FindRoot::bbrac]

Szabolcs noticed that Check with Quiet together suppress the message too:

Quiet@Check[FindRoot[x == 1, {x, 0.25, 0, 0.5}, Method -> "Brent"], foo]
$\endgroup$

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.