FJRA
  • Member for 9 years, 11 months
  • Last seen more than a week ago
How to plot Venn diagrams with Mathematica?
Accepted answer
45 votes

Based on that outdated notebook, I did the following function: VennDiagram2[n_, ineqs_: {}] := Module[{i, r = .6, R = 1, v, grouprules, x, y, x1, x2, y1, y2, ve}, v = Table[Circle[r {Cos[#], Sin[#...

View answer
Sort data after specific ordering (ascending/descending) in multiple columns
30 votes

If you want to keep the rows and your preferences of ordering is first ascending, second descending and third ascending, you can use SortBy: SortBy[data, {#[[1]],-#[[2]],#[[3]]}&]

View answer
Does AbsoluteTiming slow the evaluation time?
15 votes

When I don't want to use a wrapper to see how much time is used, I use AbsoluteTime[]: timming=AbsoluteTime[]; calculations... timming=timming-AbsoluteTime[]; Something I like about AbsoluteTime[] ...

View answer
Sequentially numbering a nested list
14 votes

With ReplaceAll and Increment you can do it: i = 1; {a, b, {c, d}, e, {f, {g, h}}} /. p : Except[List]?AtomQ :> {i++, p} {{1, a}, {2, b}, {{3, c}, {4, d}}, {5, e}, {{6, f}, {{7, g}, {8, h}}}} ...

View answer
Parallelizing Numerical Integration in Mathematica
Accepted answer
13 votes

The best you can do it is to speed up your function. Your calc is using a replace, but it's better if you use With: calc[a_, b_, c_, d_, e_, f_] := With[{Q = (8000000 \[Pi] Sin[ 1/2 ArcCos[ ...

View answer
Creating a table/Matrix during a For loop
12 votes

Try using Table, assuming x is an array of values you could try: matrix = Table[{xi, y1[xi], y2[xi], ..}, {xi, x}] Table will "do the For loop" while building matrix, in this case xi will take each ...

View answer
ParallelTable and Table do not give same result
12 votes

Your arrayToBeFilled doesn't change in the global kernel but in the parallel kernels. The way you should do your parallel is this: arrayToBeFilled = Parallelize[Table[If[arrayA[[i]] <= 0, arrayA[[...

View answer
How to make a 3D globe?
11 votes

"Antarctica" is part of CountryData, but it is not returned by CountryData[All], and it's only returned by CountryData["Continents"]. If you want quick graphics (including country borders) you should ...

View answer
Text[] using Graphics
Accepted answer
11 votes

If you take out Method -> {"ShrinkWrap" -> True} it works as I think you expect.

View answer
Can A Plot Be Overlayed With A Map?
10 votes

I would prefer to use the "GeoImage" styling, because you can use other projections when using it. Let's say you have data for the whole world in a matrix: data = Table[ Sin[x Degree] Sin[y Degree]...

View answer
MapThread gives different results from ToExpression when trying to assign variables from a list
10 votes

I think avoiding ToExpression is important, so here is a solution using Symbol: MapThread[With[{var = (Clear[#1]; Symbol[#1])}, var = #2] &, data] I use Clear to be sure that the symbol has not ...

View answer
Create a "perspective animation"
Accepted answer
10 votes

It could be something like this? outersquare = {{-1, -.8}, {1, .8}}; innersquare = outersquare/10. + {-.1, 0}; corners[sq_] := {sq[[1]], {sq[[1, 1]], sq[[2, 2]]}, sq[[2]], {sq[[2, 1]], sq[[1, 2]...

View answer
Is there any way to allow a message to appear more than three times before General::stop shuts it off?
Accepted answer
10 votes

You can do something like this: resetMessages[symbol_] := With[{mysymbol = symbol}, Unprotect[$MessageList]; $MessageList = DeleteCases[$MessageList, HoldForm[MessageName[mysymbol, _]]]; ...

View answer
How to efficiently Append a result of an operation on each element of a list to itself
Accepted answer
9 votes

My proposition: list = RandomReal[1., {100000, 3}]; newlist = Transpose[{Sequence @@ Transpose[list], list[[All, 2]] list[[All, 3]]}]; A little benchmark using other answers: In[51]:= list = ...

View answer
Finding all dictionary words that can be made with a given set of characters (Wordfeud/Scrabble)
8 votes

Would this do the trick? selectWords[chars_, min_, max_] := Module[{charsset = Union[chars], charstally = Tally[chars], baselist, baselistchars, baselistpicks}, baselist = ToLowerCase[...

View answer
The difference between 0. and 0
7 votes

Sometimes I define my pattern using a tolerance value to consider zero: tolerance = 10.^-15; F[A___, zero_ /; Abs[zero] <= tolerance, B___] := 0; As said before, using Chop is possible too (and ...

View answer
How To interactively create a Polygon in a Graphic?
7 votes

Maybe option LocatorAutoCreate -> True is what you need, it is documented in the help. This is the example shown in the Manipulate tutorial: Manipulate[Graphics[Polygon[pts], PlotRange -> 1], {...

View answer
Replacing composite variables by a single variable
7 votes

You are looking for a variable transformation, so I would do something like (if you know that y is not 0): x/(y*z) /. z->w/y In that way, you get rid of z, and if there is any other place in the ...

View answer
Deletion of list elements containing a string character
Accepted answer
6 votes

You can use DeleteCases, Cases, Select, etc. Here a couple of examples: DeleteCases[lis, s_?StringQ /; StringMatchQ[s, DigitCharacter..~~"-"~~DigitCharacter..]] Select[lis, !StringMatchQ[#, ...

View answer
Combine Stereographic "Entity" Plot of Arctic Sea with Contour Plot
Accepted answer
6 votes

Expanding a bit @jose answer, instead of using the GeoStyling directive, maybe using the plot data is better. Let's generate a random sample, but with the same format as yours: data = Join @@ Table[{...

View answer
Undocumented Dynamic Function question
Accepted answer
6 votes

After your last comment, maybe you should assing the value of cyL[change[x]] to another variable in the dynamic, and use it outside. Something like this:

View answer
Arranging connector lines
6 votes

This is a nice problem. I get this solution: Initialization: start = RandomReal[1, {12, 2}]; end = With[{dx = 0.1, dy = 0.1}, {{-dx, 1 + dy}, {.25 - dx/4, 1 + dy}, {.75 + dx/4, 1 + dy}, {...

View answer
Dealing with numbers too large for machine precision in Graphics
5 votes

Using @Sjoerd idea of Clipping, maybe you could use too Rescale. Something simple could be a wrapper to rescale every point inside a Graphics: rescale[things_] := Module[{points = Cases[things,...

View answer
Deleting Lonely Numbers From a List
5 votes

Another approach using Split: removeLonely[list_, tol_: 1] := Join @@ DeleteCases[Split[Sort[list], Abs[#2 - #1] <= tol &], {_}]; I also included a tolerance parameter that defaults to 1. ...

View answer
Setting parts of a list
5 votes

After reading the answers, this is one way more to do it (maybe too simple): a[[4 ;; 6]] = ConstantArray[{1, 2, 3}, 3]; Thinking in it, you can do your own simple Set: Attributes[simpleSet] = {...

View answer
Max of a table/list with indeterminate values
5 votes

There is one case else to be added (how rich is Mathematica!): Max[Replace[l, Indeterminate -> -Infinity, {1}]] // AbsoluteTiming {0.639738, 99.9987} which is comparable (in my machine) to: Max@...

View answer
How to stop a .sh script that calls multiple Mathematica scripts?
4 votes

That's common in more than one case, for example, python also intercepts signals, but usually it exits, unless it is in interactive mode, where Ctrl C will stop the current computation but not exit ...

View answer
Using a variable to tell Mathematica which existing variable to manipulate
4 votes

Using With might do the trick too: ClearAll[a]; With[{paramToVary = a, paramValues = Range[0, 1, .2]}, Table[a, {paramToVary, paramValues}] ] {0., 0.2, 0.4, 0.6, 0.8, 1.}

View answer
Why some result of CityData is List[entity]?
Accepted answer
3 votes

That's an old design: if the input matches exactly the standard name, it will return the entity by itself. If the input is not a valid standard name, it will try to find the possible entities the ...

View answer
How to check the style and number of arguments like the built-in functions?
3 votes

Your Which version might be improved. In general built-in functions do not return $Failed, but themselves, so, to do it, you usually need to use Conditional expressions. This might be written in many ...

View answer