Tag Info

New answers tagged

3

I think this is a very relevant question as I think it is agreed standard that having "a" coding styleguide for every project where several people write code is a very good (inevitable?) thing. It also seems to be agreed that it is more important to have a styleguide/standard than how excatly that looks like. I also am convinced that especially for ...


5

Everyone will have their own preferences about coding style. This is especially true for Mathematica, as most work done in this language is interactive, and until recently there was relatively little open collaboration between people that could have led to the development of standards. The existence of this site (Mathematica.SE) helped make a big progress ...


6

Let me try with a few simple ("obvious"?) style guidelines I try to follow: Use meaningful names that are spelled out or that use widely-adopted abbreviations from the field of application. Begin names with lower-case letters (except when they're going into a Package for others' use) and then use camelCasing. Avoid nesting functions too deeply with use of ...


0

We have purchased a new Mathematica-10 vesrsion license Softwatre just a few days ago, When I posed the same question to the person who walked down representing the Mathematica seller , he says you can buy extra kernels if u want it to be still more fast. Which did not sound a valid answer!! Probably as u said, as the variables keep on increasing it will ...


0

I myself want to compare the weak and strong points of Mathematica with another programming language. I found that the report of Mathematica analysis team is really helpful. I cite some of them KEY ADVANTAGES OF MATHEMATICA AS A PROGRAMMING LANGUAGE: ( vs C, C++, Java, C#, Fortran, Pascal, ...) Immediate built-in access to the world's latest ...


1

My feeling is that this question is probably too broad and a definitive answer might be too long or nearly impossible. This a comment to point out issues to consider in deciding whether and how to localize symbols. + Is the application self-contained? Or does it consist of several components that need access to a shared variable (e.g. a database or ...


1

The most clean formulation, I believe, is “add an element and delete a pair if one occures”. Thus, I would just use something similar to idempotentAppend[{most___, x_}, x_] := {most}; idempotentAppend[l_List, x_] := Append[l, x]; idempotentPrepend[{x_, most___}, x_] := {most}; idempotentPrepend[l_List, x_] := Prepend[l, x] with “idempotent” in the ...


5

Similar approach to Mr Wizard's but using a silly trick with pure functions rather than the auxiliary function f: Replace[{{1, 2, 3}, {-∞, 1, 2}, {1, 2, ∞}, {-∞, 1, 2, ∞}, {-∞, ∞}, {∞}, {-∞}, {}}, {a : (-∞ | PatternSequence[]), Shortest[x___], b : (∞ | PatternSequence[])} :> {#2 &[a, Unevaluated[], -∞], x, #2 &[b, Unevaluated[], ∞]}, {1}] ...


5

Let me relax rules a bit just to write some compact code without external functions. I can add -∞ and ∞ and delete double infinities Replace[{{1, 2, 3}, {-∞, 1, 2}, {1, 2, ∞}, {-∞, 1, 2, ∞}, {-∞, ∞}, {∞}, {-∞}, {}}, {mid___} :> ({-∞, mid, ∞} /. {x_, x_, y___} :> {y} /. {y___, x_, x_} :> {y}), {1}] (* {{-∞, 1, 2, 3, ∞}, {1, 2, ∞}, {-∞, 1, 2}, {1, ...


5

I set out to condense the rules shown in the question by use of "vanishing patterns" but I found it rather difficult. The best I could come up with is this: f[x_ | __] := x Replace[ {{1, 2, 3}, {-∞, 1, 2}, {1, 2, ∞}, {-∞, 1, 2, ∞}, {-∞, ∞}, {∞}, {-∞}, {}}, {a : -∞ ..., Shortest[s___], b : ∞ ...} :> {f[a, -∞], s, f[b, ∞]}, {1} ] {{-∞, 1, 2, 3, ∞}, ...


3

expr = {{1, 2, 3}, {-∞, 1, 2}, {1, 2, ∞}, {-∞, 1, 2, ∞}, {-∞, ∞}, {∞}, {-∞}, {}}; Not general but useful: Flatten[Replace[Split[{-∞, ##, ∞}], {x_, x_} :> Sequence[], {1}]] & @@@ expr Not working if in the list are repeated elements already. Also Flatten should be restricted if we are dealing with more complex structures.


2

There's no built-in automated way to interrupt a calculation, quit Mathematica, then resume the calculation at a later time. It is however often possible to implement something like this yourself. I have done this several times when the problem was simple enough to allow it. But it needs to be done manually. You need to store the state of the calculation ...


1

Your notebook may have the option OutputAutoOverwrite set to False, or the output cell below your input has the setting CellAutoOverwrite->False. You can use the Option Inspector in the Format menu to set this option.


2

Just an example: tab = Table[{If[PrimeQ[i], "type" -> "Prime", "type" -> "NoPrime"], "n" -> i, "dc" -> DigitCount[i!, 2, 1], "dc1" -> DigitCount[i! + 1, 2, 1]}, {i, 20, 40}]; make a Dataset: ds = Dataset[Association @@@ tab] get the column heads: First@Keys@ds You can then make a table, export, to Excel, or whatever. Excel Export of ...


0

Append[eMap // Normal, eMap[1] // Normal] // Dataset {<|"ModuleId" -> 0, "SegmentId" -> 0, "x1" -> 0, "y1" -> 0, "z1" -> 0, "x2" -> 0, "y2" -> 0, "z2" -> 0|>, <|"ModuleId" -> 0, "SegmentId" -> 0, "x1" -> 0, "y1" -> 0, "z1" -> 0, "x2" -> 0, "y2" -> 0, "z2" -> 0|>} Note: using eMap[1] as per your example. At this ...


5

It is hard to figure out what you really need. If you describe the surrounding application you may get better answers. You should avoid using capital letters to start user Symbols in Mathematica as this may conflict with internals. If I follow your updated question I believe you want this: fn[x_, y_] := Min @ Quotient[{x, y}, {2, 1}] Test: fn[2, 1] ...


0

if you have Mathematica 10 use Association function: asc=<|"U0[1]"-> U0[1], "U0[2]"-> U0[2], "B0"-> B0, "V0[1]"-> V01, "V0[2]"-> V0[2]|> this new build in container function supports extracting its content by keys, which are strings in this case, and by indexes asc = <|"U0[1]" -> U0[1], "U0[2]" -> U0[2], "B0" -> B0, ...


3

If the curly braces are left out, this seems to work. Remove[eMap]; eMap = Dataset[{<|"ModuleId" -> 0, "SegmentId" -> 0, "x1" -> 0, "y1" -> 0, "z1" -> 0, "x2" -> 0, "y2" -> 0, "z2" -> 0|>}]; eMap = AppendTo[ eMap, <|"ModuleId" -> 0, "SegmentId" -> 1, "x1" -> 1, "y1" -> 0, "z1" -> 0, "x2" -> ...


0

I ended up figuring this out on my own, If you define the "Orbits" array before the plotting, it works like so: Orbits = Map[Orbit, Range[Particles] Manipulate[ ListPointPlot3D[Table[Orbits[[i, j]], {i, 1, Particles}]], {j, 1, n, 1}] If you add this to the end of my code, it works just fine. Also, if anyone is using the above code, you should redefine ...


4

belisarius left a hint in a comment on how to solve this problem more efficiently, but I'm going to take it at face value and try to optimize your code. The pattern matcher is slow, so you don't want to use the pattern matcher in any kind of loop generally. On my computer your code takes 3.87 seconds to execute, whereas ParallelSum[ n ...


2

This is one solution, encapsulating all your expressions in the form: AbsoluteTiming[expr1;expr2;]. AbsoluteTiming[ a = Range[123456]; Pause[1]; Total[a] ] (* 1.01503 seconds, returns 7620753696 *) Needs["GeneralUtilities`"] AccurateTiming[ a = Range[123456]; Pause[1]; Total[a] ] (* 1.001246 seconds *) Also works fine with Timing[] for just ...


4

I don't know anything about the structure of an InterpolatingFunction (the documentation doesn't seem to provide much information about it), but could you just reconstruct your function like this: data = {{0.5`, 0.01739227213704432`}, {0.75`,0.01526028474172406`}, {1.`, 0.01376257284655001`}, {1.25`,0.01269413117458243`}, {1.5`, 0.01187709007513161`}, ...


2

Here is my try using MapIndexed, Mouseover, and Tooltip. The idea is to highlight parts of an expression as the mouse is over it and to display at the same time the exact level indices corresponding to it. Here is a simple example to understand the core idea : myExpr = {{1, 2, {11, 22}}, {3, 4, {111, {222}}}}; and level = 3; (* For example all parts at ...


10

I use something similar to @Sjoerd's suggestion with OpenerView. Here is the essence: ClearAll[Inspect] Inspect[x_] := inspect2[x] ClearAll[inspect2] SetAttributes[inspect2, HoldAll] inspect2[x:_[a__]] := OpenerView @ {inspectView[x] // Framed, Dynamic @ Column[List @@ inspect2 /@ Hold[a]]} inspect2[x_] := inspectView[x] SetAttributes[inspectView, ...


9

Try OpenerView[{Head[#], args @@ #} ] & //@ g [For this demonstration I opened a few of the OpenerView-s. There are many more to explore.]



Top 50 recent answers are included