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)

6
votes
2answers
208 views

Cross product between two lists of vectors

I'm trying to create a function that does the cross product between two lists of the same dimensions, element by element. Each entry of the list is a 3D vector. Something like this: ...
9
votes
2answers
136 views

How to optimize my own BezierFunction?

A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail. I also know that BezierFunction[] is built-in ...
12
votes
1answer
408 views

Mathematica9: NDSolve slows down after repeated calls

Bug introduced in 9.0 or earlier and persisting through 10.4.1 or later I have noted that in Mathematica 9 my code, which involves a lot of calls to NDSolve, ...
9
votes
1answer
106 views

Memory leak with NDSolve

This is not the first time the question in mentionned (cf in particular this recent question NDsolve memory leak), but there seems to be a serious issue of memory leak - or am I missing something? ...
2
votes
2answers
64 views

Slow evaluation of Recurrence plot data from NDSolve: Performance Tuning

I am trying to use a recurrence plot to pinpoint the location when a system re-visits a previous point in its phase portrait. The system (a thin liquid film) is governed by a non-linear differential ...
10
votes
2answers
216 views
+150

How to boost the performance of my own BSplineFunction

In my CAGD package, I implemented a CAGDBSplineFunction[] like built-in BSplineFunction[]. ...
2
votes
1answer
100 views

Speeding iterative computation

I want to get the following iterative sequence ...
17
votes
3answers
2k views

How can I efficiently “remap” an image?

Many image processing libraries like OpenCV, Intel Performance Primitives or Octave have a useful function called "remap", that takes an image, an array with X coordinates and an array with Y ...
0
votes
0answers
37 views

Data structures in mathematica for choosing permutations

I am trying to classify permutations of n, in this case n=6, elements depending on the cycles that contian the points 1 and 2, since these are considered to be special points. So for example, I will ...
1
vote
1answer
45 views

Control data type (or precison?) to limit memory usage

I couldn't find the answer to my question, so here it is: I have quite a large table, which I generate in Matlab (for some reasons i use both Matlab and Mathematica, I'd like to use only one of them, ...
2
votes
2answers
124 views

Multiple object detection and tracking in images

The code below: reads in a number of png images, where the background is dark and objects of interest (here 3) are bright dots determines in each image the coordinates and other information ...
3
votes
1answer
184 views

Alternatives to For/Do Loop to optimize indexing Matrix

I am trying to optimize my code that searches for elements in the rows of matrix that are greater than 0. Then use that position to grab the element from other matrix. I use the do loop to iterate ...
16
votes
3answers
528 views

How to speed up estimation of Mean and Gaussian curvatures on triangular meshes?

I am trying to estimate curvatures on a triangulated surface/manifold using the algorithm of : Meyer, M., Desbrun, M., Schröder, P., & Barr, A. H. (2003). Discrete differential-geometry operators ...
11
votes
2answers
264 views

Efficiently generating samples from an urn with maximum per element constraint?

I need to sample from a distribution that is a hybrid of uniform and hypergeometric in the sense that all elements are sampled uniformly until an element reaches some specified maximum observations, ...
3
votes
1answer
100 views

Efficiently compute this Table of NullSpace

I have two $(2n,2n)$ matrices, $A_1$ and $A_2$, and I would like to compute $$\ker(A_1^p A_2^q -I)$$ for $p,q\leq 2n$. Both matrices are orthogonal and have exactly four non-zeros values on each ...
2
votes
0answers
60 views

How to use Compile? Bivariate Gibbs Sampler

I am trying to use compile to speed up my Gibbs sampler. I know I can use Reap and Sow to speed up tremendously. I have a more complicated Bayesian posterior that I want to speed up with compile so I ...
7
votes
2answers
505 views

How to speed up interpreting numbers from strings?

In processing a large text file I have batches from ReadList of 100,000 Records of the form. ...
0
votes
1answer
43 views

Speeding up WhenEvent + NDSolve (Performance tuning and handling instabilities)

I am solving a non-linear partial differential equation using NDSolve. The equation models a liquid film on an isothermal solid substrate. As a result of various fluid physics mechanisms such as ...
1
vote
1answer
68 views

Keeping determine digits in Append to process

The end of my code is written as below. Ignoring the inefficient role of Append, I want to have very simple set of values as for example: ...
1
vote
2answers
224 views

MatrixPower performs slower than Do loop

I have two almost identical pieces of code: one with MatrixPower responsible for matrix multiplication and another with Do loop. Why the latter performs much faster? It looks counterintuitive... <...
26
votes
5answers
963 views

Can (compiled) matrix permanent evaluation be further sped-up?

Update III  Mathematica 10.2.0 now ships with a predefined System`Permanent function, which the PermanentCode package ...
17
votes
3answers
517 views

How to compute the boundary of a group of ellipse efficiently?

Update1 I discovered that the bountary of a series of ellipses consists of the following three parts Part (I): the first ellipse's effective black-segment; Part (II): the effective ...
2
votes
1answer
175 views

Compiling in mathematica

I'm trying to compile what I think is a pretty simple function that does matrix multilplications in a loop (see below). But Mathematica issues the message: Could not complete external evaluation ...
1
vote
0answers
72 views

Speed differences between Table, Replace, Array, Map, and AssociationMap

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for ...
1
vote
0answers
70 views

Build basic Adobe Kuler-type construction: improving performance / speed

Adobe Kuler is a useful web tool to create colour palettes, but it is limited to 5 colours. I am trying to make a basic Kuler-type construction, but it is very slow, and crashes on my computer for > ...
5
votes
3answers
185 views

Delete all strings that are prefixes of another string

I have a long list of strings and I'm trying to find a more efficient way of removing those elements that are prefixes of another: ...
2
votes
1answer
52 views

how to use Expand command efficiently

Recently I got in a problem and I will try to explain with a simple example. I have an expression which reads : y = (10 + 2*x )/x; Now I want to substitute 1/x ->...
2
votes
0answers
43 views

Is there a way to figure out the “upper limit” of my PC's computational ability in Mathematica?

I am doing some simulations with Finite Element Analysis (FEA) and part of it is forming a mesh in 3D and then using NDSolveValue to solve a differential equation on that mesh. For some meshes, my ...
1
vote
1answer
97 views

How to read a part of huge matrix saved in a TXT file as single expression?

I saved a huge matrix of numbers with dimensions {400, 4001, 2} using Put and got a TXT file formatted in the following way: <...
1
vote
1answer
246 views

Histograms of gray scale images

I have a large set of subsequent 8bit gray scale png images (50 Hz). They show the noise of a CMOS camera, with the lens covered. A subset of 50 images is available here: https://goo.gl/Sa3P9P I ...
17
votes
2answers
485 views

How to create internally optimized expression for computing with high WorkingPrecision?

I have large dataset and need to fit rather complicated function on it with different values of one of its parameters (this parameter must be fixed in every fit). I use the ...
2
votes
2answers
148 views

Definite Integral. Perfomance problem

I have a notebook in Mathematica 4. I'm trying to convert it to use in Mathematica 9. One of the problem is the long computation of definite integral. In Mathematica 4 the result of the following code ...
15
votes
0answers
160 views

FindMinimum doesn't increase step size when necessary

I've spent much time finding a minimal example demonstrating this problem with FindMinimum. Normally one faces this problem when fitting very large and complicated ...
0
votes
1answer
112 views

How to speed up my code for plotting purposes?

Below is my code in order to produce a numerical expression for the final function that needs to be plotted. I have tried to see the output of each successive expression by running the code and ...
6
votes
4answers
218 views

Getting AbsoluteTiming to display in hours, minutes, and seconds

I'm doing some extended length calculations and was wondering how I could get AbsoluteTiming to display in hours, minutes, and seconds. I googled and found nothing, ...
0
votes
0answers
47 views

How to get ContourPlot3D to run involving elliptic functions?

I need to plot zeroes of a function of three variables that involves elliptic functions. For example, I have ...
7
votes
2answers
95 views

TimeSeries interpolation with time gap awareness

Is there an option for ResamplingMethod (or any other practical way) for specifying different behaviours of the interpolation, depending on, for instance, closest dates (on the ...
1
vote
1answer
49 views

Fastest way for data input into StreamPlot function

I'm interested in looking at graphing the phase portraits of 2x2 autonomous ODEs, and I'm using the StreamPlot function. Here is one simple example: ...
3
votes
3answers
105 views

Finding negative sequences in a large list: optimization

I ran across an interesting challenge recently, and I was thinking this community would know how to optimize it. I have several data sets which have (currently) about 50k-100k points. The sets ...
0
votes
0answers
23 views
17
votes
4answers
353 views
6
votes
3answers
231 views

How to speed up computation of medoids?

I need to compute medoids (based on SquaredEuclideanDistance for large lists of k-vectors (k = 14). My implementations so far are impractically slow. Here is a ...
1
vote
0answers
35 views

Prevent infinite product from trying to evaluate?

Consider an expression involving several infinite and non-infinite products, like ...
5
votes
0answers
58 views

Inconsistent performance of code

I'm trying to do some optimizations to my code to make it run faster, but it seems that there are inconsistencies in the performance of the code. Namely, the codes have different performance in ...
3
votes
1answer
77 views

Table with programmatically specified number of iterators in Compile

Compare two ways of computing a table of values of a multivariable Gaussian: ...
0
votes
0answers
100 views

Absolute minimum of a function

I would like to ask for some recomendations in order to get a faster result of a function evaluation to get the absolute minimum. In my desperate moments I have written the following code to get the ...
3
votes
0answers
63 views

What's the most efficient way to load a very large dispatch table?

This question is possibly related to this topic, although I think I have something a little more specific in mind. Recently I've been working with dispatch tables for a project, since it seemed like a ...
0
votes
1answer
88 views

Accessing the elements in a table is slower than calculating each time?

This is a follow-up of How to accelerate combinations and sum calculations here? I have tried all tricks but when N reaches 35 the time is still intimidating in a 16-core server, which is far better ...
2
votes
3answers
93 views
1
vote
0answers
78 views

Using Map instead of For?

Since i am new to mathematica i tried to do some code with several for-loops. However i saw that mathematica is not efficient with for loops and discovered some functions like map etc. So my question ...