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
39 views

Let's do this list-rearrangement prettier [duplicate]

Suppose that i have a list in this format= $list=\{ \{a,obj1 \} ,\{c,obj2 \}, \{a,obj3 \}, \{b,obj4 \} \dots\}$ I want to construct a new list in this way: $ newlist= \{ \{ \{a,obj1\} , \{a,obj3\} ...
0
votes
0answers
50 views

Is there a way to give Mathematica extra memory?

I am running Mathematica 10 (Student Edition) on Mac OS X 10.7.5 on an old Mac Pro. I have lots of extra RAM that the system isn't touching, and I would like to give some of it to Mathematica in the ...
3
votes
2answers
59 views

Slow application of `Outer` on a matrix

I have some performance issue with the calculation of a gaussian kernel applied to a not-that-large dataset. I'm not very good with performance tuning in Mma and I have the feeling this one could be ...
12
votes
3answers
1k views

Can Mathematica's random number generation be improved?

Performance on Random Number generation is intolerable. Whenever you need many deviates from the same distribution but with different parameters it takes forever. Here is a thread on Poisson ...
5
votes
2answers
896 views

Dramatic speed difference of code on Matlab and Mathematica

Background: I was trying to convert a Matlab code (fluid simulation, SPH method) into a Mathematica one, but the speed difference is huge. Matlab code: ...
1
vote
1answer
44 views

Performance boost for definite integration with symbolic limits

In Mathematica, the symbolic definite integration ...
1
vote
2answers
73 views

Performance in calculating maximum-likelihood- based estimates

My probability density function is a complicated one for which numerical estimation is necessary. Here my pdf: ...
2
votes
1answer
59 views

Simple-looking Minimize takes for ever

Consider the following: Minimize[{(ξ - x)^2 + (η - y)^2, a ξ + b η == c}, {ξ, η}, Reals] After asking Mathematica to do this yesterday afternoon and forgetting ...
2
votes
1answer
46 views

What is the fastest way to get notebook CellGroups / Cells structure?

So the question is how to get this kind of information: from This is one of my ideas: ...
6
votes
2answers
150 views

Efficient Lloyd Sampling of Images

I want to sample a grayscale image so that every voronoi cell contains approximately the same total intensity using lloyd sampling. My current code is kind of slow and I was hoping for some advice to ...
5
votes
1answer
254 views

Function takes hugely different times to evaluate on sets of virtually (but also literally) identical data

I'm experiencing something which I believe to be weird with a function that I wrote. Briefly: what happens is that I generate random data to feed my function in two different but equivalent ways ...
10
votes
1answer
244 views

Does NRoots own an abstract counterpart? If not, can we write one?

We know when solving linear algebra equations, despite its abstract syntax, LinearSolve is much faster compared to Solve: ...
3
votes
3answers
244 views

fastest way to perform the following summation

I have a vector $A$ with components $A_{i}$, and two matrices $X$ and $Y$ with components $X_{ij}$, and $Y_{ij}$ respectively. What is the fastest way of performing the following summation ...
3
votes
1answer
38 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
44 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
93 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
393 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: ...
11
votes
2answers
243 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
216 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
89 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
62 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. ...
4
votes
1answer
141 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
197 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
650 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
253 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 ...
2
votes
1answer
79 views

Optimizing alphametrics code

First of all, thank you all in this great community. I have been reading a lot of threads about Mathematica optimization learning things like using Compile ...
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
115 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
40 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
114 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
52 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: ...
7
votes
0answers
89 views

How to make Graphics3D with multiple lighting sources being rendered faster

I have a very "precise"(through setting "SpherePoints") Sphere illuminated by hundreds of random color lighting sources. The ...
1
vote
1answer
81 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
86 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
3
votes
1answer
85 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
91 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
187 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
149 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 ...
5
votes
2answers
97 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
128 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
78 views

How to Increase Performance of Manipulate Recalculating List?

I have a list in the form of prices below. ...
15
votes
1answer
563 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
338 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
141 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. ...