18
votes
Optimize search for rational numbers on unit circle?
This method is called the Stereographic approach and can be used to generate arbitary rational triples without needing brute force searching. I was fortunate to have learned this trick off Minhyong ...
- 21.7k
18
votes
Optimize search for rational numbers on unit circle?
This is a compiled program to find all Pythagorean triples $(a,b,c)$ with $a^2 + b^2 = c^2$ and $a \leq b$ and where c lies between ...
- 98.3k
12
votes
Accepted
Memory leak with Mathematica Graph functions
Here is another possible way to eliminate the impact of history, etc. The following code aborts on my machine after printing to the console three times.
...
- 4,753
12
votes
Accepted
NDSolve very slow on 2D heat equation
The simplest solution I find is, add SolveDelayed -> True to NDSolve:
...
- 58.5k
12
votes
Accepted
Speed up replacement of very large alternatives expression
Use threaded rules instead of alternatives: instead of 1 | 2 -> 0 use {1 -> 0, 2 -> 0}. Combined with a ...
- 40.1k
11
votes
What is a good way to compute successive primorials with Mathematica?
Mathematica code is already provided in the
The On-Line Encyclopedia of Integer Sequences, here http://oeis.org/A002110
oeis Sol 1
...
- 33k
8
votes
Accepted
Optimize search for rational numbers on unit circle?
This is not the fastest solution in the world for finding rational points on the unit circle (takes 4.3 seconds on my laptop for denominators up to 100000), but at least it's short:
...
- 16.2k
8
votes
NDSolve very slow on 2D heat equation
Try FiniteElement method with NeumannValue instead of derivative-bc:
...
- 41.5k
7
votes
What is a good way to compute successive primorials with Mathematica?
Luckily Prime is Listable and we can make an elegant solution with FoldList:
...
- 7,754
5
votes
What is a good way to compute successive primorials with Mathematica?
Not sure if the following is considered a good way, but at least it gave results in realistic time frames and did not crash anything.
Create the list of primes and then multiply the elements of the ...
- 9,067
5
votes
Accepted
RegionIntersection runs for a very long time and then aborts without returning a result
Edit
$Version
13.2.0 for Microsoft Windows (64-bit) (November 18, 2022)
...
- 49.1k
5
votes
Optimize search for rational numbers on unit circle?
As mentioned above, we may search for Phytogorean triples: n1^2+n2^2==n3^2. To simplify, we may restrict the search to the first quadrant, as all the other solutions are mirror images, mirrored at the ...
- 35.3k
5
votes
improving efficiency of a code
In addition to what Syed already pointed out, you can speed up the search for the restricted set of edges by using a SparseArray and by using ...
- 98.3k
4
votes
How to gather functions which intersect at the same point?
This goes through all $2^n -n -1$ subsets of length 2 or more. An overkill that allows very simple code, but it's not practical for large $n$. See other answer(s).
...
- 33k
4
votes
Why does `MemoryInUse` keep increasing?
Explanation
At least on my system, the slope Mean@Differences@ml is equal to $16$
bytes, which is equal to ...
- 33k
4
votes
Accepted
4
votes
Speed up replacement of very large alternatives expression
v2 is not as fast as Roman's v1
...
- 30.3k
3
votes
Give a element rank list of a list
Not sure if this simplification helps:
ordinalScale[list_] := AssociationThread[Sort@list, Range@Length@list] /@ list
2
votes
Bugs with computational geometry: versions 12.2 vs 13.2
If simple polygons are given by lists of their vertices, then the fastest and most reliable way to check their intersection is:
...
- 623
2
votes
How to gather functions which intersect at the same point?
This goes only through all $(n^2-n)/2$ Subsets[func, {2}] as suggested by @Syed. For $n=100$ that is only $4950$ cases.
It calculates the intersection points of ...
- 33k
2
votes
Accepted
NIntegrate: slow convergence error and speed efficiency
If we change the method of integration, we can obtain the NNt[1,1] which we see in the screenshot without any errors. The method is ...
- 9,067
1
vote
Quickly summing matrix elements
One possibility is to use TensorContract/TensorProduct, but you need to also use Inactive to ...
- 126k
1
vote
Efficient memory usage while building a large sparse matrix
Even though you have shared no details about f, as others have mentioned, I think I understand your problem.
Consider this (note that ...
- 4,753
1
vote
Accepted
How to refer to calling notebook instead of my personal include? / detector for high-memory-usage cells
The issue is that the default values EvaluationNotebook[] and EvaluationCell[] are evaluated when the function is defined, not ...
- 29.9k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
performance-tuning × 2777list-manipulation × 507
matrix × 223
compile × 160
numerical-integration × 155
parallelization × 154
plotting × 143
differential-equations × 122
mathematical-optimization × 122
equation-solving × 118
programming × 109
linear-algebra × 102
numerics × 97
functions × 92
memory × 91
graphs-and-networks × 84
code-review × 77
sparse-arrays × 68
image-processing × 67
function-construction × 66
calculus-and-analysis × 59
probability-or-statistics × 58
graphics × 54
random × 51
evaluation × 48