Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

learn more… | top users | synonyms (4)

1
vote
1answer
84 views

Increase Performance in the Manipulate Command

The code below pretty much looks like and does what I want it to. However, it is sluggish. I realize I have many calculations, and perhaps this is the best I can hope for. But if anybody has any idea ...
4
votes
1answer
179 views

Fast way to get edge-list of graph in terms of vertex indices (not vertex names)

I am looking for the fastest way to achieve the following: Given a Graph, retrieve its edge list in terms of vertex indices (not actual vertices). For example, ...
1
vote
1answer
78 views

How to increase time-effeciency of plotting complicated function?

A newbie here: I am trying to use ContourPlot to plot Intensity in a strongly focus laser beam. However this intensity is a function of not so trivial integrals, so ...
2
votes
2answers
282 views

Good coding for a sequence of derivatives

People on this site keep telling me that good MMa practice avoids the use of loops. The code below calculates the same Table of derivatives two different ways, ...
1
vote
1answer
186 views

Efficiency problem with least square algorithm (Error in both variables)

I was informing myself about the least square algorithms with errors in x and y. I found this post and the top answer wasn't ...
4
votes
1answer
236 views

Select elements of list

I have a list of lists list={l1,l2,l3,l4,...}; and two elements e1,e2. I want to select from lists ...
14
votes
4answers
292 views

Fast Selections Testing on Inequality

Is there a functional idiom for fast selections testing on inequality? For example, finding values from list a & b where the key is less than or equal to a value, in this case 4 or 9. An ...
12
votes
3answers
556 views

How to speed up Colorize

I have a list of about 500 images similar to the following: A = Import["http://i.stack.imgur.com/1bV4O.png"] ...
13
votes
4answers
370 views
7
votes
4answers
445 views

Speed up Schwarz-Christoffel mapping

I would like to ask your advice how to speed up Contour and Parametric plots in the following example. Let as start by defining a function ...
7
votes
1answer
90 views

fast complement with tolerance between large lists

I want a fast algorithm to get a list of elements to be kicked out of another list. But the kick out criterion is not the exact equivalence, however has a tolerance. Any two elements close enough are ...
3
votes
0answers
95 views

Extending Bresenham's algorithm for subpixel rendering

Original Bresenham's line drawing algorithm it limited to drawing lines between two integer pixel positions and does not allow subpixel rendering. However with my reformulation of this algorithm as a ...
16
votes
2answers
306 views

How to implement Bresenham’s algorithm as a system of equations?

Bresenham's line drawing algorithm is usually implemented via loops. But in Mathematica we can take advantage of its ability to solve Diophantine equations. From educational viewpoint it is quite ...
15
votes
6answers
1k views

Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
21
votes
1answer
404 views

Progress bar for FullSimplify

Sometimes FullSimplify takes a really long time and it is not really clear if it makes sense to wait another half an hour in hopes for it to finish, or if it will ...
2
votes
0answers
102 views

General suggestions to accelerate Simplify and FullSimplify

To my understanding, the function Simplify[] and FullSimplify[] work by applying a series of built-in transformation rules to ...
4
votes
0answers
121 views

Eigenvalues FEAST method - performance is very variable

I am running the FEAST method option for Eigenvalues on sparse matrices of dimension around 500,000. I look for about 50 ...
5
votes
1answer
100 views

Fast 1D BinCounts Alternative

I have lots of data which looks like this example: ...
7
votes
1answer
147 views

Speeding Up RandomVariate

Consider the following code where we first take 1000 independent samples from a Poisson distribution, and then take 1000 independent samples from 1000 different Poisson distributions: ...
9
votes
1answer
155 views

Sorting eigenvectors according to its projection

The problem I'm trying to calculate the eigenvalues and eigenvectors of a matrix that depends on a parameter x. As x changes, I ...
0
votes
0answers
41 views

Number triangle programming challenge, separate columns

I am about to enter this number triangle https://oeis.org/draft/A262964 in the oeis, but I don't know how to program it properly. This is partly a mathematics question so I could ask it at math se ...
4
votes
2answers
201 views

PixelValues along a straight Line [duplicate]

UPDATE to the question I have reformulated the question in order to make it distinct from the one suggested as a duplicate: "Line Intensity Profile From Image." The key difference is that I'm ...
17
votes
3answers
332 views

sudden increase in timing when summing over 250 entries

I see a sudden increase of Timing by a factor of thousands when I sum over 250 elements of a matrix rather than over 249. So for instance, this table contains sums ...
2
votes
0answers
66 views

Mathematica computes too slowly at the start of a session [closed]

Everyone, I'm a Mathematica new user. I find it a problem that, when I start a new Mathematica session, it executes too slowly for the first command (say, "1+1", it may take a few seconds before it ...
2
votes
0answers
62 views

Why is this function taking so much more time when its argument reaches 250? [duplicate]

I am observing something which I do not understand with the following function function: ...
12
votes
2answers
339 views

How to make geometric intersection faster for geographic borders?

I have developed a solution to identify geographic regions bordering a region in this post (94723). Can this functionality be made to execute any faster? Find which entities in a set border other ...
34
votes
5answers
8k views

Finding Local Minima / Maxima in Noisy Data

I'm trying to find local minima / maxima in noisy data, consisting of data values taken at certain time intervals. Ideally, the function should take a pair of lists (one containing time values and one ...
0
votes
0answers
53 views

NIntegrate within NMinimize - how to optimize the code?

How I can optimize these numerical calculations? Most annoying is encountering instabilities (numerical errors). I have a predefined function: ...
12
votes
2answers
308 views

Efficient conversion between two partition representations

I have a list of distinct expressions. We can represent a partitioning of list in two ways: As a list of sublists ...
11
votes
4answers
645 views

In a list of points, how to efficiently delete points which are close to other points?

Consider a list of points: pts = Partition[RandomReal[1, 10000], 2]; ListPlot[pts] I'd like to delete points so that the minimum distance between two points is ...
7
votes
1answer
178 views

Compiled function crashes kernel when trying to list over different length arguments

Bug introduced in 8.0 and fixed in 10.0 I'm trying to speed up a tally/binning operation that I have to run many times. I have many lists of between 1 and 10 numbers from the range [1,5] and I ...
4
votes
1answer
99 views

Speed up rendering of ContourPlot3D object

Please can you advise me how to speed up the rendering of the following two planes? When I click and drag to rotate the plot, its movement is quite jerky. Presumably it is working harder than I need ...
24
votes
2answers
644 views

Efficiently generating 2-D Gaussian random fields on the sphere

Context A couple of years ago I posted this question for an efficient code to generate an n-D Gaussian random field (sometimes called processes in other fields of research), which has applications in ...
0
votes
1answer
45 views

Plotting precise intersections involving singular functions

I have pseudo-elliptic functions defined on a parallelogram within $\mathbb{C}$ and I would like to clearly highlight the path within this parallelogram which satisfies the real part of my pseudo-...
5
votes
3answers
188 views

How to populate a large sparse array efficiently

I am trying to populate a large 2D sparse array and sum up all the columns at the end. I tried generating a set of rules and then generate a matrix using SparseArray or break the data into chunks but ...
1
vote
0answers
52 views

Evaluation of likelihood very slow

I am trying to implement a simple statistical model for the first time in Mathematica. My model is made my one random variable which is the sum of background and signal. Background is an exponential ...
6
votes
1answer
78 views

Closing over array values makes Compile choke with CompilationTarget -> “C”

When I attempt to Compile a closure which contains an array of the appropriate type, it works just fine with ...
1
vote
1answer
96 views

Recursive calculation is very slow

I've got a recursive definition of Arcs that shares equal length and a several other dependencies to each respective predecessor. (Imagine a book being bent.) I formulated all necessary things here: ...
0
votes
1answer
93 views

Optimization of a voxel projection function

I implemented a function to check if a voxel (3D pixel) is well projected on the space of a image (black and white silhouette) through a perspective camera. The function does the work but It need more ...
3
votes
0answers
96 views

How to speed up summing a large number of vectors

First let me explain what I am trying to do in my code. Assume that I send a very short chirp (2,000 ms long) into a domain filled with 20,000 particles randomly scattered in the domain. The ...
6
votes
1answer
134 views

Strategy to build efficiently an image using parts of many images

I have about 1000 images of 1000px $\times$ 1000px and a list which contains the coordinates of the pixels to select, for each of the 1000 images. Each pixel is used once, so the final image is a full ...
7
votes
2answers
301 views

How can this resampling code be made faster?

Suppose I have a matrix: sbt = RandomInteger[{0, 2^16 - 1}, {5202, 3465}]; It represents an image and I would like to do "pixel binning" on it, where I take non-...
3
votes
2answers
206 views

Slightly increasing complexity of function increases calculation time by magnitudes

I am trying to calculate an impedance value from voltage and current functions. The calculation method is based on how an actual measurement device performs it. I have two different current function, ...
19
votes
5answers
686 views
23
votes
4answers
3k views

Efficiently generating n-D Gaussian random fields

I am interested in an efficient code to generate an $n$-D Gaussian random field (sometimes called processes in other fields of research), which has applications in cosmology. Attempt I wrote the ...
13
votes
2answers
387 views

How to speed up the plotting of B-spline curve?

Three months ago, I asked a quesion about B-Spline basis function here, Today, I used this function to plot B-spline curve. The definition of $N_{i,p}$ ...
1
vote
1answer
56 views

NIntegrate option for FourierSeries

I would like to use FourierSeries but it is very slow. My guess is that it is because it uses symbolic integration: ...
9
votes
4answers
415 views

Looping through 3 million elements of a list to 'Set' values is slow

I am looping through the 3 million elements of a time-series (v1, o1) and corresponding values (v2, o2). v1 contains a uniformly increasing timestamp (e.g. 1 to 3,000,000 in increments of 1) o1 ...
7
votes
0answers
130 views

Is this a reliable method for getting a list of very large primes?

As noted here, both PrimePi and Prime are documented as having their limits somwhere around $10^{15}.$ ...
9
votes
1answer
237 views

Finding planetary conjunctions with Mathematica (project-level) [closed]

Summary: What's an efficient way of finding planetary conjuctions with Mathematica using the SPICE kernels, and without using AstronomicalData (which I believe is less efficient). NASA publishes ...