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

1
vote
1answer
141 views
4
votes
5answers
244 views

Can I generate a “piecewise” list from a list in a fast and elegant way?

Suppose we have a number list a: n = 1000000; a = RandomReal[{0, 1}, {n}]; We want to generate a list ...
2
votes
3answers
110 views

Can you compute more terms in this sequence?

I am trying to identify a sequence related to the von Mangoldt function matrix. Since I believe/conjecture that the columns in the matrix have period lengths as in this sequence b: ...
5
votes
2answers
87 views

Paralleizing the Plot function internally

I have a function of several parameters, funct(a,b,c,d,f,...). Mathematica deals with this function fine but it takes a minute or so to make a data point. I want to plot graphs of funct using code ...
11
votes
4answers
830 views

Integers which are the sum of both two and three consecutive squares

This is a math problem I came across the other day: I would like to know what would be a good way (esp. performance-wise) to check all first, lets say, 1000000, natural numbers if they can be ...
1
vote
1answer
63 views
14
votes
1answer
474 views

Has this implementation of FDM touched the speed limit of Mathematica?

Still, I'll use the implementation of the 1D FDTD method (you can simply understand it as a kind of explicit finite difference scheme for the Maxwell's equation) as the example. Just for completeness, ...
13
votes
2answers
324 views

Bad performance of LengthWhile?

A friend of mine showed me this example, it's a test comparing LengthWhile to a self-made lengthwhile written in a direct and ...
5
votes
1answer
208 views

A more perfect Union[]

I was doing a Project Euler problem with my class, and found the following weird fact: Union[] of a list of some 50 million numbers (of which only around 15000 were ...
6
votes
2answers
126 views

Bad performance from SubsetQ?

Can I say this is a bad performance from the new V10 function SubsetQ? Here are some tests comparing it to ...
2
votes
2answers
277 views
5
votes
1answer
124 views

Speed up MinimalPolynomial

My Mathematica code runs slowly MinimalPolynomial[Sqrt[2] + Sqrt[3]+ Sqrt[5]+ Sqrt[7]+ Sqrt[11]+ Sqrt[13], x] runs slowly, but the Maple version ...
0
votes
1answer
113 views

My Baum-Welch algorithm is very slow. Is it due to Mathematica?

I've also posted this question here, since I'm not sure which community is more adequate for this type of question. I've programmed imperatively the Baum-Welch algorithm for a 2 state hidden Markov ...
18
votes
4answers
4k 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 ...
5
votes
1answer
59 views

Speedup of KL Divergence by Monte Carlo Simulation

I started with Mathematica about just a week, so I don't know how to take all of this environment. What I want to know is if there is a way to speedup my code to compute the KL-Divergence of Gaussian ...
24
votes
1answer
273 views

Exporting extremely large images; arrays generated via TensorProduct use 5 times as much RAM as expected?

I am generating plots of the roots of certain classes of polynomials, in the spirit of the multicolored visuals on the Wiki page on algebraic numbers. I've thus far been able to make some extremely ...
9
votes
3answers
186 views

Improving selection of elements from large multidimensional array

Frequently in my profession I deal with large arrays of data. Typically these are mixed types including integers, strings, dates, and reals. To recreate a typical data array: ...
5
votes
1answer
98 views

Optimizing code containing an infinite sum

I have the following expression. It's based on the negative-log-likelihood of a Poisson-Gaussian noise model, i.e. a convolution of a Poisson & Normal distribution. The value $x_{i}$ is the ...
4
votes
3answers
373 views

Improve the performance of solutions to Project Euler (#14)

Problem I have following code, when n<=10^5 it's not slow, but n>2*10^5 it's became very slow. I think maybe some temp value greater than 2^31-1, so make compile invalid. Could you give any idea ...
4
votes
1answer
151 views

Calculate the covariance of a large matrix

I have to compute the covariance of 50 very large integer matrices (2500x2000 elements). However, according to my estimation this will take around 10 days. Do you have any ideas how to speed things ...
8
votes
2answers
126 views

Export[] performance

Consider this sequence of commands: ...
95
votes
3answers
4k views

Performance tuning in Mathematica?

What performance tuning tricks do you use to make a Mathematica application faster? MATLAB has an amazing profiler, but from what I can tell, Mathematica has no similar functionality.
14
votes
2answers
391 views

Better way to test that a matrix is upper-triangular?

Today, I got to thinking about how to test that a matrix was upper-triangular. So I had a try at it. Algorithm $\quad \quad a_{ij}=0 $ Or $i \leq j$ $\Rightarrow$ $True$ My solution is ...
4
votes
1answer
107 views

Optimizing a function containing a complex exponential

I've noticed the following significant different in performance for different formulations of the same function: ...
7
votes
1answer
127 views

Simpler code evaluating Dickman's function?

I've read here that Mathematica 10 can Obtain symbolic solutions to delay differential equations. Would that help in numericaly evaluating Dickman's function $\rho(u)$ ? It is a delay differential ...
3
votes
0answers
57 views

Listable on first level

I have some function which take List as input. f[l_List]:=someActions[l] I need apply this function to a list of lists. Now I ...
7
votes
3answers
206 views

Issue with very large lists in Mathematica

I have a need to work with very large arrays of data in Mathematica. The length of the list is not known upfront. The typical size is a few hundred thousands elements and could easily go beyond a ...
17
votes
0answers
637 views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
3
votes
1answer
74 views

How to efficiently select elements from a Hash?

How can I write an efficient version of the following selection statement: Keys[Select[hash, # < constant &]]; // AbsoluteTiming hash can be made from: ...
3
votes
0answers
67 views

Fast principal component analysis

I'd like to speed up a principal value value analysis. The data contains a large set of vectors with a large dimension. Both are in the range of 1000. I want to obtain the loadings matrix for further ...
1
vote
1answer
55 views

Faster way to extract partial data from AdjacencyMatrix

I am dealing with a lot of Graph objects. One task is to obtain an Id for each of them. So I first used ...
4
votes
1answer
335 views

Using Compile Function Options efficiently

While this gives general pointers, I want inputs on ground rules for improved performance of nested/interdependent compiled functions. sample problem: a, ...
15
votes
1answer
270 views

Speed up adding Poisson noise to an image

I'm simulating some images corrupted with Poisson noise, but I'm encountering a few problems with performance. According to the documentation on ImageEffect, one ...
2
votes
0answers
69 views

Mathematica 10 loads too long time [duplicate]

After starting Mathematica 10 it hangs for about a minute before becoming operational. Internet connectivity is disabled. Start screen is disabled. What should I do? P.S. Opening any help page ...
5
votes
1answer
122 views

How to efficiently select element in a list of lists?

How can I write an efficient version of the following statement? Cases[list, {_, feature_} /; feature < constant]; // AbsoluteTiming List is of the form, list ...
12
votes
1answer
160 views

A bug in Commonest in version 10

Bug introduced in 10.0.0 m_goldberg demonstrated that in Mathematica 10 Commonest does not behave as the documentation indicates that it will. Concisely: ...
21
votes
1answer
208 views

Why is multidimensional Reverse slow?

I have found that multidimensional Reverse is ~10 times slower than exact -1 ;; 1 ;; -1: ...
2
votes
3answers
149 views

Alternatives to Append/AppendTo for generating a list in an interactive DynamicModule?

I have a stack of timelapse microscopy images that I am trying to segment frame-by-frame using some of Mathematica's image processing functions. I have created a little interactive DynamicModule with ...
3
votes
0answers
64 views

Efficient processing of Special Ordered Sets with LinearProgramming

I'm playing with integer linear programming, especially problems involving lots of constraints which would appear to be special ordered sets. Below is a toy example, three last rows of the matrix ...
0
votes
1answer
69 views

Unusual Slow Down with LocatorPane/DynamicModule

I have coded up a little interactive DynamicModule to help me with image processing/segmentation of stacks of timelapse microscopy images. I am experiencing a crippling slow down in the ...
21
votes
2answers
446 views

Why is Query so much slower than Part?

Time for another of these(1),(2) as yet another new-in-10 function appears to have poor performance compared to older alternatives. This time: Query appears to be ...
6
votes
1answer
153 views

Optimizing the front end on the Raspberry Pi

Using Mathematica's Front End on the Raspberry Pi is truly a test of one's patience. The most basic of notebooks become unresponsive after seemingly trivial additions to the notebook. Consider the ...
2
votes
2answers
75 views

Improving the speed/efficiency of multiple (finite range) convolutions for a causal response plot

So I am looking at modelling the response of a system that is excited by multiple pulses over a period of time. The way to find the response at time t is to take the convolution between the impulse ...
1
vote
1answer
73 views

Faster code for solving an equation with parameters

I am new to Mathematica and wanted to solve an equation that depends on parameters. The code is below ...
17
votes
1answer
964 views

Faster way to compute the distance from a point to a surface in 3D

I am trying to compute the shortest distance between a point and a triangle in 3D ...
32
votes
1answer
1k views

Benchmarking Mathematica performance on the Raspberry Pi

It is not surprising that Mathematica on the Raspberry Pi is slow and clunky. In Stephen Wolfram's words, the command line is "quite zippy" but the notebook interface is "a trifle sluggish by modern ...
2
votes
1answer
118 views

How can I reduce computation time while still obtaining a good approximation for my function?

I am new to any CAS (and Mathematica, for that matter) and new to StackExchange too, so forgive me and correct me on any mistakes. I have this function: $J_p=\sum_{m,n=1}^{\infty} ...
7
votes
1answer
217 views

Why do Tooltips slow down Dynamic so much? Is there a faster alternative?

I'm working on a Dynamic ListPlot with a few thousand plots, and it seems that wrapping the points with Tooltip slows the Dynamic responsiveness substantially. With the simple example below, dragging ...
8
votes
2answers
279 views

Finding all sets of elements with two common elements in a large dataset

I have a very large network of atoms ($\approx 10^6$ atoms) with fixed positions that resemble a cellular structure: I have two files including: fixed locations of each atom set of points which ...