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)

3
votes
1answer
36 views

Is it possible to generate a message when precision upgrade occur?

I use Mathematica mostly for numerical simulation, so most of the time double precision (or machine precision) is enough for me. Mathematica has this nice feature of automatically upgrade to arbitrary ...
1
vote
0answers
42 views

Complex input for Compile makes it slow

I asked a question here and then tried to use Compile for the solution to gain even more speed. Inside Compile there is a loop ...
3
votes
1answer
88 views

Making table of matrix product and efficiency

I want to make a table in which each element is a matrix product: ...
4
votes
2answers
182 views

Generate lists that satisfy a condition in an efficient way

The following code produces lists of sublists with maximum length 5 that shuffle zeros around an ordered list (here {1,2}). It produces all permutations while ...
15
votes
2answers
379 views

Why is my data 10 times slower than random data when doing matrix multiplication

I have some data generated from some program, and it appears that matrix multiplication on these data are about 10 times slower than on some random data: ...
8
votes
0answers
181 views

Choose between `Apply` and `Map`

Even though this might be too general question(or not answerable), I want to get some advice here. I apologize in advance if it is not a relevant question. I frequently have to process large list of ...
1
vote
1answer
209 views

Lookup construction using data matrix and Reap/Sow versus AppendTo`s

I am a user of MMA9 and made my own kind of Lookup, which is now a standard command in Version 10. In my program there is a section in which by means of a StringReplace[ ]-command containing a lot of ...
4
votes
1answer
82 views

Number of divisors visualized with the QPochhammer function, how improve performance of code?

I have this code that originally is Jeffrey Stopple's code for the Riemann zeta function in the complex plane. Because I discovered yesterday that the number of divisors can be generated with the ...
1
vote
0answers
56 views

Speed up replacement using Rule Dispatch Associtation

I knew that this has asked many times, but I hope there is something more could be done to speed this up. The expression kappa is here. ...
3
votes
1answer
111 views

Fast matrix multiplication in MMA and GPU

Matlab multiplies two 3000by3000 matrix around 0.18s faster than MMA. While for just a few matrix multiplications the speed difference is not important, it becomes crucial when I want to do those ...
10
votes
1answer
189 views

Max element of a list with a custom ordering function

I need a function to find max element of a list according to some custom ordering function, assuming that the function implements a total order (elements being compared might not even be numbers). ...
10
votes
2answers
643 views

Rendering thousands of points

I am trying to render an image with some 120,000 Points. Technically it's just 10,000 points, plus their reflection, plus 5 rotations of both of those sets, but I'm ...
0
votes
1answer
88 views

How to speed up execution of this function?

How can I speed up the execution of following function, specifically for larger values of n? ...
4
votes
2answers
236 views

Speed up calculation

First of all thanks to: rm -rf, Mr.Wizard, Simon Woods, Pickett, Piotr Wendykier, Mac, Yves Klett, belisarius, halirutan, bill s, nikie, wxffles, ... Everybody of you helped me (a mathematica ...
0
votes
1answer
68 views

Extend a function to all polynomials ( just 2 variables) when one knows its values on monomials

I need your help to make my code faster. I have a formula for computing a value from any monomial $x^i y^j$, say formular1[i_,j_]:=(Gamma[i]/Gamm[j] ). It is just ...
2
votes
1answer
111 views

How to use slots and patterns to reduce repetitive calculation?

This is kind of complicated... How can we make MMa calculate values of a function before doing multiple pattern or slot substitutions? Answers to similar questions didn't cover the case where the ...
0
votes
0answers
36 views

Order of evaluation when using Solve and Minimize

I have to solve numerically an integral, that ends up being more or less as follows: Solve[f[x]==a*Sum[Sin[x-i]*(f[i]-f[i-1]),{i,1,x}],f[x]] (not actual ...
1
vote
0answers
103 views

Best way to create symmetric matrices with block structure and additional symmetries of the submatrices

Update: you can now skip the "My attempted solution" part and jump to "My first attempt for improvement" in the end of the question. My question is related to Best way to create symmetric matrices . ...
1
vote
1answer
51 views

Performance of Extract-Transform operations

I'm doing simple data analysis. I load some date-time data from a file, it's a simple list: ...
1
vote
1answer
79 views

Apply functions to functions yields slow execution speed

I'm trying to write a function that parametrizes a curve c(t) by its arc length. Technicly I'm finished but if I plot the result for an example curve like ...
4
votes
1answer
84 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
3
votes
1answer
83 views

Mathematica taking too long to calculate recursive function

I have been trying to plot those specific recursively defined functions p1 and q1 in Mathematica: ...
1
vote
1answer
82 views

Use Compile to speed up evaluation

I have read, that using Compile command can speed up evaluations in mathematica. I have a mathematical expression, which I evaluate using following command: ...
0
votes
0answers
41 views

Faster way to build a specific height in a thickness plane graph? [duplicate]

Test image can be a Plot, ParametricPlot, RegionPlot, ...
12
votes
5answers
3k views

Division by zero is slow

Suppose I have two arrays of data, which I want to divide: ...
6
votes
3answers
180 views

How to get “Signature” of each element of “Permutation” output

I need to sum over all possible permutations, multiplied by the Signature of each permutation of a given list of symbols. But, I don't know how to determine the ...
2
votes
2answers
147 views

Speeding up the generation of all k-edge-coloring of a graph

A $k$-edge-coloring of a graph $G=(V,E)$ is a function from $E$ to $\{1,\ldots,k\}$, so in other words every edge of $G$ receives one of the $k$ colors available. (In particular, note that we are not ...
4
votes
2answers
91 views

How to speed up Min of DateObjects?

I'm in version 10.0.1 using a Dataset to do some plots and things. For one of the plots I need to get the minimum date of a some filtered set of the ...
2
votes
3answers
126 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
98 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 ...
1
vote
1answer
77 views

How to Increase Performance of Manipulate Recalculating List?

I have a list in the form of prices below. ...
14
votes
1answer
537 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
337 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 ...
6
votes
2answers
138 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
289 views

Will Parallelize in this programme help it run faster? [closed]

I have a programme, and inside it this line of code. ...
0
votes
1answer
141 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 ...
5
votes
1answer
228 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 ...
14
votes
6answers
952 views

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

This is a math problem I came across the other day: $365$ can be written as a sum of two and also three consecutive perfect squares: $365=14^2+13^2=12^2+11^2+10^2$ What is the next ...
5
votes
1answer
74 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 ...
9
votes
3answers
203 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
111 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 ...
14
votes
2answers
410 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 ...
9
votes
2answers
144 views

Export[] performance

Consider this sequence of commands: ...
3
votes
0answers
66 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
1answer
142 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 ...
7
votes
3answers
215 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 ...
3
votes
1answer
96 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
104 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 ...
3
votes
1answer
207 views
1
vote
1answer
60 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 ...