# Tag Info

29

Is there a possibility to disable stack tracing, but keep messages? Internal$MessageMenu = False reverts back to the old messages. Seems to do the trick and prevent the leak from my testing. 26 Analysis current as of Mathematica version 11.0.1 and 11.1.0. We can disable the Show Stack Trace item in the new message menu as follows: MessageMenu$PruneStack; MessageMenuDump$IncludeStack = False; The reference to MessageMenu$PruneStack is there to ensure that the message menu packages have been autoloaded (otherwise our setting will be lost ...

22

In version 10 or later, we can use EvaluationData. EvaluationData[1/0; 0^0] Behind the scenes, this uses handlers, like in my first answer, meaning that only those messages will be recorded which would get printed.

16

For the case where the height function is "Count", we can use the formula from the linked page in a custom ChartElementFunction with the sample size (Length[data]) passed as metadata: ceF[d_: .2, nsd_: 3, color_: Automatic][cedf_: "Rectangle"] := Module[{e = nsd /2 Sqrt[#[[2, 2]] (1 - #[[2, 2]]/ #3[[1]])]}, {ChartElementData[cedf][##], Thick, ...

14

What I personally usually do is to still use $Failed / exceptions when a returned$Failed / thrown exception can't be used constructively when handled / caught, other than issuing the right message. In some cases, however, the application logic requires to do more than that. In particular, certain data associated with the state right before the failure may ...

12

This has been partially answered before, so here I will highlight some of its evolution since that previous answer. VerificationTest and its MUnit antecedents do not have a mechanism for introducing new error types, so we need a function to do that for us. For this, I use a function called checkGraphicsRendering (outlined at the end) with the general use ...

10

There are a few reasonable ways. I'll illustrate with an example of Newton iterations for square roots, take from this MathGroup post r[x_, n_] := x - (x^2 - n)/(2*x) x = 1.020; two = 2.020; First we run it with the usual arithmetic. Table[x = r[x, two], {30}] (* Out[680]= {1.4142135623730950488, 1.4142135623730950488, \ 1.414213562373095049, 1....

10

Consider any numerical integration method $I^*(f,a,b)$ that approximates the exact integral $I$ of a function $f$ over an interval $[a,b]$. It will be implemented by a computation represented by, say, I[f[x], {x, a, b}]. Conceiving an NIntegrate[] command in this way breaks the error into two independent components. The first is the error of the method $I^* -... 10 Short Version The ultimate cause of this problem is an evaluation leak that occurs when an expression of the form MakeBoxes[StringForm[...]] is evaluated. Longer Version MakeBoxes has the attribute HoldAllComplete. This allows it to create the box representation of any expression without evaluating it. For example: MakeBoxes[1 + 1] (* RowBox[{"1", "+", ... 9 I think InternalWithLocalSettings is the tool you want to use. The syntax is: InternalWithLocalSettings[ preliminaryCode, (* can't be aborted *) body, (* can be aborted *) postprocessCode (* can't be aborted *) ] Suppose your code looks like: code[] := (a=1; b=2; Pause[Infinity]; c=3) and you're interested in the values of a, b and c. Then: ... 8 That would mean to remove the Listable attribute from Plus. You could do it as follows, but I would not recommend that. Unprotect[Plus]; ClearAttributes[Plus, Listable]; Plus[_?MatrixQ, __?(! MatrixQ[#] &)] :=$Failed Now, you have a = IdentityMatrix[3]; Plus[a, a] Plus[a, 1] {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}} $Failed Really, you should ... 7 Assume that you have your lists of unique resistor values (resistors) and of unique capacitor values (capacitors). For now, I generate two such lists as follows: resistors = Flatten@ Outer[ Times, PowerRange[1, 10000], {100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, ... 7 I think that that the key feature is to use the MaxExtraConditions option for the Solve command. In elaborate answer of Artes in here, a very very nice presentation is referred. It is entitled as Getting the Most from Algebraic Solvers in Mathematica by Adam Strzeboński. You can download the .cdf file of the presentation which is really helpful. Slide$10$... 6 Here's one way to do it: a = {1, 2, 3, 4, 5}; b = {2, 0, 40, 5, 0}; x = Quiet[Table[a[[i]]/b[[i]], {i, 1, 5}]]; Position[x, ComplexInfinity] {{2}, {5}} Basically, ans contains the values plus the errors, which in this case are ComplexInfinity. You can locate the errors using Position, in this case, at positions 2 and 5. If you want to check for any old ... 6 This does what I think you're after, fiddle with options as desired: With[{a = Interval[1.01 + .18 {-1, 1}], b = Interval[.92 + .11 {-1, 1}], c = Interval[2.2 + .2 {-1, 1}]}, Plot[{Min[a + b*x + c*x^2], 1.01 + .92 x + 2.2 x^2, Max[a + b*x + c*x^2]}, {x, -5, 5}, Filling -> {1 -> {3}}, FillingStyle -> Darker, PlotStyle -> {None, Red, ... 6 Mmm, something like this? ClearAll[try] SetAttributes[try, HoldAllComplete] try[expr_, failexpr_, messages : {___MessageName} | PatternSequence[]] := Module[ {tag}, ReleaseHold @ Catch[ Quiet[ Check[ HoldComplete[#]& @ expr, Throw[HoldComplete[failexpr], tag], messages ], messages ], tag ] ] 5 This error should probably be reported to WRI as a bug, most likely in ExperimentalNumericalFunction; you should not be seeing this come back up to the top level. I see no obvious reason why memory allocation should fail, as this is not really a large or difficult problem, despite the apparent complexity of the expression. However, we do not really need ... 5 Do[ Check[{i/i, 1/(i - 5)}, Print@i], {i, -10, 10}] // Quiet 0 5 5 compare against a higher precision calculation n = 100000; ListPlot[Log[10, Abs[Accumulate@Tan[N[Range[n]]] - Accumulate@Tan[N[Range[n], 1000]]]]] 5 I do not know what you mean here. When I run (with$\omega=\sqrt{k/m}$): DSolve[{y''[t] + \[Omega]^2 y[t] == 1/m Sin[\[Omega] t], y'[0] == 1, y[0] == 0}, y, t] MMA (ver 11.2, macOS 10.13.1) provides this quite fast:$\text{Function}\left[\{t\},\frac{4 m \omega \sin (t \omega )+2 \sin (t \omega )-2 t \omega \cos (t \omega )-2 \sin (t \omega ) \cos ^2(t \...

4

NDSolve has already detected the largest such intervals for you, which is why the resulting InterpolatingFunctions have restricted domains. You can use InterpolatingFunctionDomain to extract those domains. I'd do something like so Clear[x1, x2, y] eqn = {x1'[t] == -x1[t]^2 - x2[t] + y[t]^3, x2'[t] == x1[t] - x2[t] + x1[t]^2 x2[t]^2, y'[t] == x2[t]^2 ...

4

Check: Check[expr, failexpr] evaluates expr, and returns the result, unless messages were generated, in which case it evaluates and returns failexpr. Check[expr, failexpr, {s1::t1, s2::2, …}] checks only for the specified messages. Check[expr, failexpr, "name"] checks only for messages in the named message group. CheckAbort: ...

4

[Too long to type as a comment, but here is why PrecisionGoal is relevant] Any number has a precision, and Precision[arb16] reflects only the uncertainty in the value of arb16 as a number. It is determined by both the precision of the input, and all the arithmetic operations subsequently done with it (see rounding error in Michael E2's excellent answer). ...

4

Another way (see How to catch complete error message information, including the message text as it would be printed? for more ways to hack messages): This works because i is effectively Block[]-ed by Do[]. badindices = {}; $MessagePrePrint = (AppendTo[badindices, i]; #) &; Do[Append[x, a[[i]]/b[[i]]], {i, 1, 5}]$MessagePrePrint = Automatic; ...

4

This answer below is not directly what you asked but rather about what you should consider doing. With more than 50 or so data points you should consider avoiding histograms completely. More often than not you probably envision some smooth density function that you're trying to estimate. Further, adding in error bars makes for a very messy and maybe even ...

4

You're creating pairs {m,h} where each pair really only depends on the previous pair. That's perfect for NestWhileList. i is irrelevant, an artifact of procedural formulation: you don't need it. You need two functions. The first transforms an {m,h} pair into a new pair, something like: f[{m_,h_}]:={m+step,(whatever makes the next h)} Then, you need a test ...

4

It looks like you're using a single-arg Catch. Single-arg Catch will not catch a multi-arg Throw. Compare: Catch[Throw[1, "FOO"]] Throw::nocatch: Uncaught Throw[1,FOO] returned to top level. Hold[Throw[1, "FOO"]] with: Catch[Throw[1, "FOO"], "FOO"] 1 Perhaps that's all that's wrong?

4

You can monitor the step size. It will be "effectively zero" well before it is zero. The code below does not quite do what you want, I think, because it cannot trap NDSolve after it has decided to exit. When NDSolve fails due to step size "zero," it does not take the last step. At best you can only catch the next-to-last step, and probably you have to aim ...

3

I'm not sure how you want to present the result, but you can cull the errors for each integration with IntegrationMonitor. Clear[f]; f[x_Real] := Block[{ferror, fint}, fint = NIntegrate[BesselJ[2, x t], {t, 0, 40000}, IntegrationMonitor -> ((ferror = Total[Map[#1@"Error" &, #1]]) &)]; (*Sow[{x,ferror},"error"];*) (* absolute ...

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