Tag Info

Hot answers tagged

14

This is not a bug, the tick specification used in the documentation is incorrect. The tick specification in these examples is {bottom, left} which is the short form of {bottom, left, top, right} which was an older tick specification that was deprecated in v7 (according to the docs). But, it was allowed to continue to work until v10. The form you are ...


11

Use NDSolve antiD = NDSolveValue[{f'[x] == Sqrt[1 + x^3], f[0] == 0}, f, {x, 0, 10}] Example usage: Plot[antiD[x], {x, 0, 10}] Alternatively... This works because this function can be antidifferentiated (by Mathematica). antiD = FunctionInterpolation[ Evaluate @ Integrate[Sqrt[1 + x^3], {x, 0, t}, Assumptions -> 0 < t < 10], {t, 0, ...


10

One possible solution is using Quiet: ds[All, Quiet[#a/#b]&] Another possible solution is using the FailureAction option: ds[All, #a/#b, FailureAction -> None]


10

FYI a more elegant way to get tweets1 is tweets1 = Rule @@@ tweets; Classify automatically separates words under the hood (via StringSplit), so you don't actually need to do that yourself. Classify has a built in sentiment classifier: Classify["Sentiment", "Windows 10 why is It called windows 10 when there was no Windows 9?"] (* "Negative" *)


9

The reason you get a message is because Compile cannot handle non tensor arrays, and the first argument to MeijerG is not a tensor (i.e. {{1/2, 1/2}, {}}). Now DumpsterDoofus is correct in that MeijerG cannot be compiled, but we can get around this error, which will make MeijerG usable in compiled code. What I mean by usable is Compile will call ...


8

The following works in Version 9.0.1.0 and Version 10.0.1.0 BoxForm`$UseTemplateSlotSequenceForRow = False; {x^a, Sqrt@b, ArcSin[c]} // Row // TeXForm (* x^a\sqrt{b}\sin^{-1}(c) *)


8

You can specify a general error message that only consists of a placeholder General::error = "`1`"; and then use foo[x_] := Module[{}, If[x < 0, Message[foo::error, "x<0 detected"], x]]; r = foo[-1] foo::error: x<0 detected


8

I see there are no accepted answers for this question after more than 10 months so I thought I'd have a go at it. Although I have been using Mathematica for since V8, I am only an occasional user and hence not at all an expert like the others who have chimed in so far - but I'll give it a shot. Rather than using the Java based import to open and import the ...


8

Eventually, I was able to reproduce this problem. The way to fix it is to delete the MLCleaner-1.0 directory in $UserBaseDirectory/Paclets/Repository, then restart Mathematica and run RebuildPacletData[]. The underlying reason is the same as in 84539, though it was triggered by the use of a different top-level function depending on Throw/Catch during kernel ...


7

How about using "RuntimeErrorHandler": f = Compile[{{x, _Real}, {y, _Real}}, Log[(x - y^2 - 2. x)^2]/(y x^2 - 2 (x + y) - y^2 + 3.), "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]} ]; Catch[Quiet@f[-196, 15]] // AbsoluteTiming (* {0.000019, 0.0000116843} *) Catch[Quiet@f[-196, 14]] // AbsoluteTiming (* {0.000051, ...


7

The problem is that the stdin stream for each process is being left open and needs to be closed. To demonstrate the issue, we create a single process: $process = StartProcess[$SystemShell]; WriteLine[$process, "echo example line"]; KillProcess[$process]; The call to WriteLine implicitly creates a stream object. Even though the process has been killed, ...


7

Compilation of Total As @rasher points out in a comment, the compensated summation form of Total can't be compiled. You can check this using CompilePrint - note the call to MainEvaluate. Needs["CompiledFunctionTools`"] CompilePrint@f2 (* from your question *) Summation in Mathematica There seem to be plenty of options for summing a list in ...


6

If you set the contents of your interpolation function to be the variable data={{..,..},..} (such that Interpolation[data] gives the message), you can look at the mesh generated with: Needs["NDSolve`FEM`"] mesh = ToElementMesh[data[[All, 1]]] That also gives the message. Looking at mesh["Wireframe"] gives you an idea what is going on. You can then use ...


6

I can confirm this bug under Win 7 Mathematica 10.1.0.0. A workaround for the moment is to specify all FrameTicks, e.g. Plot[Sin[x], {x, 0, 10}, Frame -> True, FrameTicks -> {ConstantArray[{-1/2, 1/2}, 2], {#, #} &@{{0, 0 °}, {Pi, 180 °}, {2 Pi, 360 °}, {3 Pi, 540 °}}}] Three more workarounds that narrow down the ...


6

I believe the simplest change to your code is to replace the Return[$Failed] expressions with Sets that restore the default values of the options: ClearAll[func] Options[func] = {Method -> Automatic, WorkingPrecision -> MachinePrecision, Order -> 2}; func::badval = "`1` is not a valid value of option `2`"; func[arg1_, arg2_, opts : ...


5

We can use Hold to prevent message names from being evaluated until the time is right: g[a_, verbose_:False] := Module[{messageList} , messageList = If[verbose, {}, Hold[FindRoot::lstol]] ; messageList /. _[m___] :> Quiet[FindRoot[x^2 + x + a, {x, 3}], {m}] ]


5

A simple way would be to assign the value of expr to a variable and then return that variable after printing the messages. For example: info::values = "n was `` and d was ``"; Module[{n, d, v} , n = 100 ; d = 0 ; Check[v = n / d, Message[info::values, n, d]; v] ]


5

We had a bug like this on v. 10: it specifically stopped running new processes after you created 100 of them. This was fixed in version 10.0.1. I recommend testing it there, as version 10.0.1 has a number of improvements with respect to StartProcess. I can't test your example in MacOS right now, so please let me know if this isn't working on v. 10.0.1. ...


5

The term incidence matrix has caused confusion on this site before, so I think it's time to clear this up. There's no standard, generally agreed upon definition of incidence matrix. It's a loose term for a matrix that describes the relationship (connections) between two different classes of objects. What these objects are can vary. When you see the term ...


5

I can reproduce the error with Mathematica 10.0.2 on Windows 7. In fact it is sufficient to open the example notebook and evaluate Rasterize[test] in a new input cell: It appears that problem is due to the embedded stylesheet, which contains $CellContext`ParentList as an entry in the InputAutoReplacements list for the style cells StandardForm and ...


5

A method from Kuba's answer, no GUIKit` is needed. Tested on Mathematica 10.1. Module[{masknb, img}, masknb = CreateWindow[{}, WindowSize -> Full, Visible -> False]; img = MathLink`CallFrontEnd[FrontEnd`NotebookImage[masknb]]; NotebookClose[masknb]; img ] We can even make a fairly fast screen recorder from it: ...


5

It is often not necessary to use If to check arguments. Rather, since the formal arguments that appear in function definitions are almost always patterns to be matched, you can take advantage of Mathematica powerful pattern matching capabilities. Here is a fairly simple example. validColor = (_RGBColor | _GrayLevel | _Hue); colorToRGB::badarg = "bad ...


4

I have found a workaround which works for my purposes, though it is not particularly pretty, and the weird behaviour of Evaluate on error messages remains a mystery to me. It is possible to switch between different Quiet behaviours by setting a custom message group and then switching that within the logic. The following code works, as far as I can tell. ...


4

The answer why it is not valid incidence matrix is given by the above answers. To verify if your matrix is valid, use the following command m = {{1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, {0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0}, {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0}, {0, 1, 0, 0, 1, 0, 0, ...


4

The test matrices are matrices but not incidence matrices. The rows represent the vertices and each column represents an edge. Consequently each column must have only 2 non-zero entries or a single entry of 2 for self loops. This is not the case for any of the matrices or their transposes. To check for yourself, try yourself, e.g.: mat = ...


4

Sorry, but your matrices aren't valid incidence matrices. From the IncidenceMatrix help page: For an undirected graph, an entry $a_{ij}$ of the incidence matrix is given by: 0 if vertex $v_i$ is not incident to edge $e_j$ 1 if vertex $v_i$ is incident to edge $e_j$ 2 if vertex $v_i$ is incident to edge $e_j$ and a self-loop In ...


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

One can define a dynamic environment where Message will be overloaded. Here is one way: ClearAll[withMessageDetection]; SetAttributes[withMessageDetection, HoldAll]; withMessageDetection[code_] := Internal`InheritedBlock[{Message}, Module[{inMessage, tag}, Unprotect[Message]; (call : Message[args___]) /; ! TrueQ[inMessage] := ...


4

I use \$MessagePrePrint = StandardForm since without that the real number 1.5 is displayed in a message as 1.5`. However, you might have $MessagePrePrint set to something else. Check is used to control what should happen when a built-in message occurs. Quiet prevents the built-in message from being displayed. I made a pure function (i.e. #1,#2,& ...


4

Why not something a little simpler? g[a_, verbose_: False] /; ! verbose := Quiet[g[a, True], FindRoot::lstol] g[a_, True] := FindRoot[x^2 + x + a, {x, 3}] Now: g[1] (* no message *) g[1, True] (* FindRoot::lstol: printed *) This has the advantage of separating the primary definition from the one that controls Message printing, making both ...



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