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 (3)

0
votes
1answer
81 views

Making ReplaceAll faster

I have a list of functions ncalc that is calculated by ...
1
vote
0answers
38 views

Fast construction and reshaping of large tensors

I'm trying to construct a large matrix which is derived from some higher rank tensor (the rank of interest to me changes case by case, so it needs to be a general method). Currently, the process of ...
11
votes
2answers
388 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"] ...
8
votes
1answer
191 views

Why is `Block` significantly faster than `ReplaceAll` for inputting variable values

Given that the documentation for FindMinimum uses ReplaceAll for its various examples of what to do with the found solution to ...
1
vote
0answers
56 views

Optimizing orthogonal nonlinear regression code

I'm doing a simulation problem on the Langmuir adsorption model, where I need to obtain the model parameters from simulated data using the orthogonal nonlinear least-squares regression method. Here is ...
4
votes
1answer
71 views

How to create fast functions based on units?

Using units is a good means for rapidly developing code, since it provides some error control. Hovewer, using Mathamatica functions containing units appears to be copmutationally inefficient. ...
0
votes
0answers
69 views

NIntegrate gives message NIntegrate::vars:

As seen in the code below, I initially constructed a list of functions of two variables ζ and t0. These functions are pure ...
10
votes
6answers
513 views

How to find all the positions of max value of a list efficiently?

For Example, list=RandomInteger[{1,100},2000]. Yes,I know Position[list,Max[list]] can do. But it's based on pattern ...
1
vote
0answers
53 views

Orthogonality relations of Hermite polynomials

The Hermite polynomials are orthogonal. $$ \int_{-\infty}^\infty H_m(x) H_n(x) e^{-x^2}\, \mathrm{d}x = \sqrt{ \pi} 2^n n! \delta_{nm} $$ Does Mathematica not use this relationship? Because running ...
12
votes
0answers
157 views

Performance problems in new Sequence functions

The new-in-10.1 Sequence* family of functions should provide newly optimized methods for handling sequence problems. Happily in some cases they do! For example ...
3
votes
1answer
112 views

Constructing lists in an efficient way

I have a list of functions and I want to separate them into two lists: a list that contains the functions that have at least one zero and a list that contains the functions that do not have ...
4
votes
2answers
43 views

NaNs in tabular data and import performance

I'm working with some data files that are just too large for Import. I tried using ReadList, specifying either ...
0
votes
1answer
53 views

Returning functions that are partly evaluated

I have some performance issues when calling Table[{h, Slow1[h, n]}, {n, nlist}, {h, 0.1, 10, 0.5}]; for a given list ...
0
votes
0answers
37 views

What is the right way to remove head of a number? [duplicate]

I often have a number for which I want to remove its head, e.g. {1}. I know of two ways to remove the head: {1}[[1]] # & @@ {1} Neither of these methods seem ...
19
votes
2answers
221 views
1
vote
1answer
72 views

Slow program- Mathematica shuts down

I've been trying to draw dynamic pictures of level sets of certain polynomials. The code right now looks like that : ...
5
votes
2answers
144 views

Combinatorics: Placed errors

Consider a vector of length n where each element can take one of the values U, X, ...
0
votes
0answers
23 views

Timing of an Evaluation is not correctly displayed

From: http://reference.wolfram.com/language/howto/DisplayTheTimingOfAnEvaluationInANotebookWindow.html I ran a process that took about two minutes to finish. But the time recorded is only 0.18 ...
4
votes
1answer
66 views

Speed up the auxiliary function magicSquare when $n$ is doubly-even

Today, I saw a question about magic square. Please see here When $n$ is doubly-even.Namely, Mod[n,4]==0 ...
0
votes
2answers
84 views

Is it possible to sum the results of a Map - Apply?

I am fairly new to functional programming and would like to replace a For[] loop that sums the results over a Dataset. This may be a bit different since the ...
2
votes
0answers
46 views

Optimization of custom probability distibutions?

Consider the two tests: Timing[Do[RandomVariate[NormalDistribution[0.5, 0.3]], {200}]] {0.001188, Null} ...
0
votes
0answers
26 views

How can I find all stationary points? i.e Something like MinDetect but for saddle points (that applies to data arrays of arbitrary rank)

I would like to find all stationary points of a data set of arbitrary rank. MinDetect and MaxDetect are great for finding minima and maxima but I can't find a good way of finding the saddle points. ...
2
votes
1answer
63 views

Faster variant of Reduce for finding zeros of holomorphic functions in a region

I'm currently using Reduce to find zeros of a function in a region on a complex plane: ...
8
votes
4answers
129 views

ImageApply Performance Difference

How come the timing difference between these calls is so big? (0.2 and 39 seconds on my computer) ImageApply[q3, img] ImageApply[q3[#] &, img] Where ...
1
vote
1answer
80 views

Improving Performance - Finding Polynomial Roots [duplicate]

I'm fairly new to Mathematica. In the past, my usage has mostly been limited to solving the occasional equation, making some plots, and working with small scaled statistics. None of these have been ...
11
votes
2answers
181 views

Faster trimming of leading/trailing zeroes in rectangular array

Given a (large) rectangular array, e.g. (small for example case): ...
8
votes
2answers
141 views

why MeanFilter is nearly 100 times slower than MovingAverage for 1D array?

I used to average over my data with MeanFilter before I learn about MovingAverage and thought that these two functions are similar except that MeanFilter is more powerful for its ability to deal with ...
2
votes
1answer
92 views

Efficient way to perform local Otsu thresholding on image

I have images of cell nuclei that have locally varying intensity distributions. Therefore, I need a robust local threshold algorithm. LocalAdaptiveBinarize works ...
9
votes
5answers
373 views

Most efficient way of making pair list from a list

I have a bunch of datasets which looks like: 3 7 1 6 5 8 2 4 1 2 8 1 5 2 5 ... and I need to make a list of pairs such that the first element makes a pair with ...
1
vote
0answers
105 views

How can I speed up this NM optimization? Most delay seems to be due to long analytic expression

I am struggling with computational speed of a NelderMead optimization. Nevertheless my impression is that I lose lots of speed not only due to the NM optimization itself but rather to for instance ...
-1
votes
1answer
67 views

Looping within linear programming

I am trying to do some network programming around optimization. Here is a reduced sample: ...
7
votes
3answers
204 views

How to speed up auxilary DoolittleDecomposite function?

The Doolittle Decomposition algorithm as below: $$A=LU$$ where $A= \begin{bmatrix} a_{11} & a_{12} & \cdots a_{1n}\\ a_{21} & a_{22} & \cdots a_{2n}\\ \vdots & \vdots & \vdots ...
2
votes
1answer
82 views

speeding up creation of SparseArray

I have to create the following sparse arrays, which are reshaped in a two dimensional matrix, so that i can use the build in Dot[] function to do a kind of ...
6
votes
1answer
60 views

DatePlus and DayPlus perform much worse than my user-defined-function

I was debugging a function speed, and discovered that the time bottleneck was in DatePlus. I tried to change to DayPlus and get ...
6
votes
2answers
132 views

How can I generate a $2n$-point moving maximum of a list as efficiently as MaxFilter?

This is based on the prior question, Moving maximum function?, where @rasher provided two winning solutions (i.e. clearly the most efficient): MaxFilter[list, 1] ...
13
votes
1answer
160 views

Unexpected slowness checking for empty list?

I thought I had a firm understanding of the differences between Equal and SameQ, but this has me puzzled: ...
3
votes
1answer
129 views

How to accelerate my code?

Given a 2D $M \times N$ matrix with non-negative values, I would like to find a path going from top to bottom such that the sum of the path is minimum. My function is defined as follow: ...
3
votes
1answer
172 views

Very slow mathematica finite differences

I have a simple code which solves an equation by an explicit method (FTCS). It takes mathematica several minutes (mathematica 10.0.2) to finish the calculation while the same code in Fortran runs less ...
2
votes
2answers
133 views

NIntegrate over a list of functions

This question is the result of these other two questions. Question 1 and 2. I thought it would be better to ask a new question rather than deleting previous one. I think When ...
0
votes
0answers
16 views

What is the most efficient method to find a single eigenvector with eigenvalue that is numerically 0?

I need to find an eigenvector of a (numerically calculated) square matrix M corresponding to the eigenvalue 0. The methods I know are ...
24
votes
7answers
679 views

Faster position list construction from a “take instructions” list

Take some list, e.g., {1,2,3,4,5}, and a "take instructions" list, say {1,1,2,1,1}. The latter is read as "take the first ...
5
votes
1answer
154 views

Slow exponential evaluation over lists

This question,which is still unanswered, might be relevant because it involves NIntegrate over lists and it also has Exp. In ...
4
votes
1answer
58 views

How to get probabilities for multinomial & hypergeometric distribution ranges more quickly?

I often need to calculate the probability of a result from a multinomial distribution falling within some range, e.g., the maximum of the categories having an upper bound, or a lower bound for the ...
3
votes
0answers
62 views

Decrease computation time of module [closed]

I need to compute the exponential of a matrix (in this caseR) by the summation method where R is a square matrix with symbolic ...
1
vote
1answer
155 views

Slow evaluation of NIntegrate when used as a pure function

I asked a perhaps related question here. Here is my code in below. The goal is that to define a function which must be integrated numerically. The function itself first is calculated over different ...
0
votes
1answer
85 views

Animating a Large Graphic Aborts, but Dynamic Works Fine

I'm trying to animate a large Graphics output, and it is returning $Aborted. I'm confused because when I use Dynamic and Slider, the graphics output is exactly what I want, i.e., I can 'animate' the ...
14
votes
1answer
187 views

Major slowdown when using a ColorFunction with more than one named scheme

Problem remains in 10.1 Earlier Kuba noted a major slowdown with code Simon Woods posted. Here is a simplified example. First a color function using two different named gradient schemes: ...
0
votes
0answers
58 views

Improve performance of processing transactions in a large file

I want to work with a table which has 296,705 transactionslines and 172,147 transactions. ...
2
votes
3answers
112 views

Finding minimum of a list of pairs

Sometimes I need to find the Min of a list, whose elements are lists (say of two elements, a pair). Given that Min does not have the option to indicate a sorting function like Sort, I elaborated the ...