18

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)?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
P. Fonseca
  • 6,665
  • 2
  • 28
  • 60
  • 1
    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] – Szabolcs Feb 24 '13 at 13:56
  • @Szabolcs I'll use Check to solve my problem, and I'll wait some more comments/answers before posting it to support. Thank you. – P. Fonseca Feb 24 '13 at 13:59
  • I remember another question about Quiet not suppressing certain messages. Does anyone recall which it is? EDIT: No, it was the converse syndrome: (14140) – Mr.Wizard Feb 24 '13 at 14:05
  • 1
    Quiet and ; together stop the message too. Could also use Off[FindRoot::bbrac] – Sjoerd C. de Vries Feb 24 '13 at 14:41
  • 3
    I'd say it's a bug. TracePrint reveals two calls to Message[FindRoot::bbrac]. – Sjoerd C. de Vries Feb 24 '13 at 14:49
  • @Szabolcs you mean with Off[FindRoot::bbrac]? Works for me. FindRoot[x == 1, {x, 0, 0.5}, Method -> "Brent"]; // Quiet works as well. – Sjoerd C. de Vries Feb 24 '13 at 14:54
  • 1
    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 likeHold[Message[FindRoot::bbrac],True]whereTruemeans not suppressed usingQuiet`. – Szabolcs Feb 24 '13 at 14:54
  • @Sjoerd Sorry, I have a problem with copying on OS X, it's very annoying. I pasted the previous contents of the clipboard by accident. But now I understand what you meant by Quiet and ;. – Szabolcs Feb 24 '13 at 14:55
  • @Szabolcs FindRoot seems to be called twice too. – Sjoerd C. de Vries Feb 24 '13 at 15:02
  • 1
    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? – WalkingRandomly Oct 01 '13 at 08:24

1 Answers1

8

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]
Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368