Tag Info

Hot answers tagged

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 pink box shows a formatting error. You can disable highlighting of formatting errors for a specific object using Style: Style[ Graphics[{Disk[], garbage}], AutoStyleOptions -> {"HighlightFormattingErrors" -> False}] You can also change the setting globally using the Preferences dialog (Edit - Preferences - Messages - Formatting error ...


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

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 ...


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

Note: this response was written before sample data for the question was changed from 24 3D points to 96 2D points. The main message remains unchanged, however. The error message is complaining that the first zero in the first polygon specification is not a valid index into the list coord which has 24 elements. A GraphicsComplex defines a list of points of ...


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 ...


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

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

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


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 ...


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

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

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 ...


4

Since gh is a tensor, you need to say what rank it is, so replace {gh, _Real} with {gh, _Real, 2} to fix the error. costFxn = Compile[ {{P, _Real}, {Ns, _Integer}, {gh, _Real, 2}, {Kg, _Integer}, {G, _Integer}, {betaGN, _Integer}}, Sum[ -Exp[Kg/(P gh[[g, n]])] (Kg * betaGN)/ Log[2] ...


4

Assumptions is an option to Integrate. The message is telling you to add the assumption that x is real (by default, variables are usually treated as complex). f[x_] := Piecewise[{{1, -1/2 <= x <= 1/2}}, 0]; ProbabilityDistribution[ Integrate[f[a], {a, x - 1/2, x + 1/2}, Assumptions -> x ∈ Reals], {x, -2, 2}] For this simple example one ...


3

The function Check is what you are looking for. fib[n_] := Check[If[n == 1, 1, n*fib[n - 1]], Print["n = ", n]; Abort[]] Block[{$RecursionLimit = 20}, fib[25]] $RecursionLimit::reclim: Recursion depth of 20 exceeded. >> n = 17 $Aborted


3

You have the x overloaded in too many places. You use it as free variable for the Series, then you use it for the plot command variable. I think this error happens because ?? Plot show it has HoldAll. Then the x for the plot takes effect before the Series is expanded. But this 'x' is now a number, so Series complains as it needs a symbol. But best to ...



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