# Tag Info

26

I found a robust solution described in this MathGroup message by Maxim Rytin: messageHandler = If[Last[#], Abort[]] & InternalAddHandler["Message", messageHandler] This will abort the computation whenever a message would be printed. It can be turned off using InternalRemoveHandler["Message", messageHandler] Alternatively this can be ...

22

Use Reduce[(1/x) Cosh[x/2] == Sqrt[2], x, Reals] or Solve[(1/x) Cosh[x/2] == Sqrt[2], x, Reals] the latter yields {{x -> Root[{-E^(-(#1/2)) - E^(#1/2) + 2 Sqrt[2] #1 &, 0.75858229952537718426}]}, {x -> Root[{-E^(-(#1/2)) - E^(#1/2) + 2 Sqrt[2] #1 &, 5.4693513860610533998}]}} For transcendental equations you may get with Reduce ...

21

Solutions to algebraic or transcendental equations are expressed in terms of Root objects whenever it is impossible to find explicit solutions. In general there is no way express roots of 5-th (or higher) order polynomials in terms of radicals. However even higher order algebraic equations can be solved explicitly if an associated Galois group is solvable. ...

19

rcollyer's method looks great but for a reason I have yet to determine it fails in Mathematica 7. Here is a variation that does not. Block[{$MessagePrePrint},$MessagePrePrint := Row@{#, " at i = ", i} ~ToString~ StandardForm &; Do[i^0, {i, -1, 1}] ] This may not be ideal however, as every field in the message gets this tag. For example, if ...

18

If you look carefully, you'll notice that the usage messages of package functions are nicely formatted. Notice the nice italicised and subscripted $x_1$. If you actually look in the package, you'll find a usage message that doesn't have any formatting at all, and even differs from the version ?DelaunayTriangulation gives us. ...

15

I cannot seem to make it do exactly what you want do to how messages are created, but here is a serviceable alternative using $MessagePrePrint.$MessagePrePrint formats the variables specified in the message string, and in your example, the message has the form General::indet = "Indeterminate expression 1 encountered." where the 1 will be replaced by ...

14

It is actually straightforward. You use Messages[symbol] to get the list, e.g. Power::infy (* trigger loading the message *) Messages[Power] (* {HoldPattern[Power::infy] :> "Infinite expression 1 encountered."} *) then, as it is a list of replacement rules, you can simply do Power::infy /. Messages[Power] (* "Infinite expression 1 encountered." *) ...

11

rcollyer has a nice solution. Here's another possibility using Check and printing the list of messages generated at the current evaluation. Quiet@Block[{$OldMessages = 0}, Do[Check[#^#/# &@Mod[i, 2], Print@StringForm["At i=, ", i,$MessageList[[$OldMessages + 1 ;;]]];$OldMessages = Length@$MessageList;], ... 11 I agree completely with J.M., Quiet is the answer. Implementing WithOff using Quiet is (as I'm sure you know) trivial. Here it is, just for fun: ClearAll[WithOff] SetAttributes[WithOff, HoldAll]; WithOff[msg_, expr_] := Quiet[expr, {msg}]; WithOff[Pattern::patv, rule = (f[x_Integer | {x__Integer}] :> g[x])]; rule2 = x_[x__] :> x; 11 What about something like this? Function[i, {i, ParallelEvaluate[i]};, HoldFirst][ Unprotect[Message, Check, Quiet]; Module[{$guardMes = True, $guardChck = True,$guardQuiet = True}, Message[args___ /; $guardMes] := Block[{$guardMes = False}, Message[args]; If[Head[First@{args}] =!= $Off, Abort[]]; ]; Quiet[args___ /;$guardQuiet] := ...

10

You can do something like this: resetMessages[symbol_] := With[{mysymbol = symbol}, Unprotect[$MessageList];$MessageList = DeleteCases[$MessageList, HoldForm[MessageName[mysymbol, _]]]; Protect[$MessageList];] And you will have to call it after each function... Sqrt[a, b, c, d]; Exp[a, b]; resetMessages[Exp]; Sqrt[a, b, c, d]; \ Exp[a, b]; ...

8

New Method FJRA pointed out that my original method will fail in certain cases. Here is what I hope is a more robust approach: Unprotect[Message, $MessageList] Message[args___] /; ! TrueQ[$msgClear] := Block[{$msgClear = True},$MessageList = DeleteCases[$MessageList, HoldForm[Power::infy]]; Message[args] ] Now the specified message will print ... 8 You can define the function: messageIsOn[msg_]:=Head[msg]===String Which yields True if the message is on. Than do e.g: msgStatus=messageIsOn[Pattern::patv] If[msgStatus, Off[Pattern::patv]] < some calculation suppressing message Pattern::patv > (* Restore the message status *) If[msgStatus, On[Pattern::patv]] 6 Following R.M's suggestion, and shamelessly lifting code from the Wizard’s fine answer there, you can use Stack[] and get the following: SetAttributes[withTaggedMsg, HoldAll] withTaggedMsg[] := Function[, InternalInheritedBlock[{MessagePacket}, Unprotect[MessagePacket]; MessagePacket[name__, BoxData[obj_, form_]] /; ! TrueQ[$tagMsg] := ...

6

The easiest and, so far, the best solution I have found is the following: (* Put the following two lines at the top of every notebook. *) messageHandler = If[Last[#], Interrupt[]] & ; InternalAddHandler["Message", messageHandler]; The above code is slightly modified from Szabolcs's solution at the beginning of this thread. I changed Abort to ...

5

How about doing something as simple as sym1::msg = "I am feeling grumpy."; sym2::msg = sym3::msg = sym1::msg; Then Do[With[{ff = f}, Message[MessageName[ff, "msg"]]], {f, {sym1, sym2, sym3}}] Outputs sym1::msg: I am feeling grumpy. sym2::msg: I am feeling grumpy. sym3::msg: I am feeling grumpy.

5

Why don't you use Check. You could combine it with Reap/Sow or Throw/Catch. Here's an example that counts divisions by zero. SeedRandom[1]; list = RandomInteger[{-2, 2}, {100}]; Quiet[results = Reap[Table[Check[1/x, Sow["bad news"]], {x, list}]]]; Length[results[[2, 1]]] Of course, since the second argument of Check can be anything, you could arrange ...

5

There were some attempts on that in this discussion. I also have this functionality in my debug function posted here

3

It seems to me that there's a better approach, but one way is to define your own DownValue for this particular message. For example: Unprotect[Message]; Message[NIntegrate::maxp, its_, int_, err_] := Sow[err] Then NIntegrate[Sin[x]/Sqrt[x], {x, 0, 100}, Method -> "MonteCarlo", PrecisionGoal -> 6] // Reap (* Out: {1.07721, {{0.0761274}}} *)

2

First, I put $t = \sin x - \cos x$, eq1 = (3 - Cos[4x]) ( Sin[x] - Cos[x]) - 2 == 0; eq2 = t == Sin[x] - Cos[x]; Eliminate[ TrigExpand[ {eq1, eq2}], x] I receive 2 t - 2 t^3 + t^5 == 1 And then, I solve Solve[ 2 t - 2 t^3 + t^5 == 1, Reals] finally Reduce[ -Cos[x] + Sin[x] == 1, x, Reals] (C[1] ∈ Integers && x == π/2 + 2 π C[1]) || (C[1] ∈ ...

Only top voted, non community-wiki answers of a minimum length are eligible