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)

2
votes
1answer
342 views

Simulated Annealing InitialPoints option

I have a cost function that depends on 4 parameters: CostFunction[{tx,ty,tz,ox}]. I used NMinimize[] function with ...
3
votes
1answer
192 views

MapThread Alternatives

I want to add two matrices, the first one containing a 2D vector at each position the other one a list of 2D vectors. The 2D vector from the first matrix should be added to each of the 2D vectors at ...
4
votes
1answer
140 views

MapThread and Compile

After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of ...
6
votes
1answer
291 views

Imposing a Periodic Boundary Condition in Nearest Neighbour Search

I am trying to find first nearest neighbour distributions of randomly dispersed point-like objects in an infinite system. To do this I make a finite sized box unit cell with a chosen concentration of ...
5
votes
0answers
84 views

Is there something like MaxProcessorUsed?

For standard procedures it is easy to test if the implementation is better or worse than other by using Timing etc. It does not help us with creating ...
2
votes
0answers
195 views

Taking real and imaginary parts of indexed functions and speeding up ComplexExpand

I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts. I am ...
9
votes
2answers
276 views

Why is ParallelMap way slower than Map

I recently tried to use ParallelMap instead of Map and to my surprise encountered that ...
3
votes
2answers
278 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 ...
5
votes
2answers
170 views

How to optimize computing a product?

Problem description Write a function to caculate the formula My solutions Solution 1: ...
6
votes
1answer
578 views

Fastest way to do vector / matrix multiplication with constant matrix

Suppose we have a fixed n x n matrix, call it $B$. What is fastest way to evaluate $v^t B\;v$ over many different vectors $v$? Since $B$ is a constant matrix, does this allow the number of operations ...
5
votes
1answer
168 views

How to speed up multi-curve plotting?

The following example is a very simplified version of the problem I'm working with, though I hope it still captures the essentials. First, the definitions: ...
20
votes
5answers
472 views

Compiling ColorFunction for faster complex phase-amplitude plots

I have gotten into the habit of plotting complex-valued functions on a plane using a color-function along the lines of ...
0
votes
1answer
138 views

johansen test error in code

Cross-posted at the Wolfram community forum I have found this code on a forum, apparently it worked in a previous version of mathematica. Now when I run it, it keeps running for ages. I am not able ...
1
vote
1answer
81 views

Insert glyphs into a string using functional code

I asked this question few days ago: Replace For-loop with functional code Suppose I use strings instead of lists; for example a = ToString /@ {123123, 112233};` ...
2
votes
2answers
180 views

Reducing quality of Graphics3D scene to improve performance?

ProteinData["SERPINA1", "MoleculePlot"] gives the detailed Graphics3D plot below. I'd like to make many small copies of this ...
8
votes
2answers
165 views

How to reduce the number of operations needed to evaluate an expression? [duplicate]

For some numerical calculations in C++ I have, for example, this complicated expression to evaluate. Given as Mathematica input, in its original form it is ...
2
votes
1answer
173 views

Manipulate executes expressions multiple times

I am using Manipulate for a rather intricate front end for data visualization. I was getting very sluggish performance and was able to boil the problem down to a ...
5
votes
2answers
258 views

Faster Eigenvalues with lower precision goal

I compute all eigenvalues of a large matrix, and I decide that the speed is more important than the precision. Then the question is, can I speed up Eigenvalues[] by ...
4
votes
1answer
198 views

How to speed up calculations with large number of replacement rules?

In my program I have an expression which looks like: ...
5
votes
1answer
227 views

How to avoid unpacking from Language`ExtendedFullDefinition

Consider this code: LaunchKernels[]; On["Packing"] a = RandomReal[{0., 1.}, {64, 30000}]; ParallelMap[Fourier, a]; // AbsoluteTiming Developer...
9
votes
1answer
271 views

Why I only get 2X speedup when parallelized with 16 kernels

I'm trying to parallelize a function by ParallelTable, and it seems the speedup is not very good. I have 16 parallel kernels on my computer node: ...
3
votes
1answer
161 views

Optimization of power tower fractal generator [closed]

I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list. Here is my code : ...
12
votes
2answers
678 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 ...
8
votes
1answer
163 views

Why is building a table of function values so much slower than just plotting the function?

Here is a function that take some time to evaluate: n = 1000; coeffs = RandomVariate[NormalDistribution[], n]; f[x_] := Sum[coeffs[[k]] Sin[k x]/k, {k, 1, n}]; ...
7
votes
0answers
167 views

Improving the performance of a package for working with rational functions

As Mathematica gets slow for large symbolic calculations, the cost of putting terms over a common denominator (Together), in particular, gets too high. It occurred ...
3
votes
2answers
145 views

How can I track the execution time of an evaluating Manipulate cell?

In Wolfram's tutorial on Advanced Manipulate Functionality, a nice example of a continually evaluating Manipulate cell is presented: ...
6
votes
2answers
104 views

Consecutive Print to target same output Cell

Is it possible to conveniently direct the output of consecutive Print statements to the same output without actually accumulating the output in a temporary string/variable. This would be useful in ...
5
votes
0answers
71 views

Does one need to be careful about loading multiple (many) contexts or packages in the same session?

I have a number of large pieces of precomputed data which I am considering putting into individual packages in order to load them (via DeclarePackage) and unload ...
6
votes
3answers
1k views

Simulate MATLAB's meshgrid function

Here is MATLAB's meshgrid. I came up with these implementations in Mathematica: ...
9
votes
1answer
93 views

IntegerDigits has Listable attributes, but not fast

See this example, a function has Listable attributes often more efficient than Map,but why is this one is an exception? ...
4
votes
1answer
163 views

How do I put a Monitor into CDF?

I would like to keep track of progress of a database request in an Enterprise CDF, but it won't allow PrintTemporary or ...
9
votes
1answer
260 views

Mathematica9: NDSolve slows down after repeated calls

I have noted that in Mathematica 9 my code, which involves a lot of calls to NDSolve, slows down considerably after some time. Apparently, the problem is NDSolve itself and it seems to be related to ...
17
votes
1answer
348 views

Underlying Algorithms for List Manipulation Functions

Does anyone know, or know of a link for the underlying algorithms used for list manipulation functions? Specifically: Union with and without the ...
2
votes
0answers
89 views

Speed improvement in string distance function

I'm using this distance function to compare distance between strings: ...
4
votes
2answers
150 views

Replace function call with expression resulting from the symbolic evaluation of the function when defining a second function?

Suppose the evaluation of a function f[x_, y_] := ... takes a very long time, but the output is a not-so-complicated polynomial in ...
2
votes
0answers
104 views

Force Dispatch to generate dispatch tables

Dispatch creates hash tables only for lists of length larger than 3. Is there any way to force MMA to create hash tables even for lists of length smaller than 4? ...
9
votes
0answers
112 views

Fast two dimensional version of Range[] [duplicate]

I have need of a two dimensional version of Range[]. I have a few ideas of varying speeds, and I was wondering if anyone knew a better way to do this. ...
4
votes
1answer
104 views

Strange behavior of Mathematica regarding calculation time

Today I witnessed the following strange behavior of Mathematica, when it comes to calculation time involving larger nested lists. The following is the short example that I setup, I am sure one can ...
11
votes
0answers
756 views

Mathematica performance on Mac

I recently got a trial version of both Mathematica 9 and MATLAB 13a for Windows. I was stunned by the performance difference in the Windows and the Mac version. It was a simple test in matrix ...
4
votes
0answers
90 views

2X slower with ; — LibraryLink performance problem [duplicate]

This is the continued problem of the LibraryLink memory usage question here and here. In the following code, there is a 2X performance difference with only the change of ";". ...
1
vote
2answers
348 views

Collatz Tool Box — any speed ups possible?

I have created a tool box for experimenting with the Collatz conjecture. Info here: Wolfram MathWorld and here: Wikipedia The patterns I have found allow us to make the conjecture jump through some ...
4
votes
2answers
366 views

Numeric calculation of Hessian

I want to calculate the Hessian matrix for a function that can only be evaluated numerically. So far, I have the following (where f is just for testing): ...
0
votes
0answers
48 views

Fastest way to add a constant column into a array [duplicate]

What is the fastest way to add a constant (1 in this test) into a array? There is my attempt: ...
3
votes
1answer
92 views

Slow CreateDialog when passing image sequence

I'm attempting to display an image sequence of 40 images inside of a Manipulate that cycles through each frame with a slider. I would like the ...
13
votes
0answers
280 views

What Mathematica features and idioms have n^2 complexity or worse

Here are a few: AppendTo[data, elem], Sort[data, test], in some cases use of ___ (as ...
3
votes
3answers
196 views

Speed up Eliminate

I have a set of trig equations, c1,c2,c3 are constants, I excepted the result is c1 c2 c3 r^2 + (c1^2 + c2^2 + c3^2 - 1) r + c1 c2 c3 == 0 but following code ...
16
votes
1answer
738 views

Slow import of multigigabyte TIF image stacks

Update 6: After contacting Wolfram Technical Support, I was advised that the frame-to-frame import timing variability can be eliminated by reading in the frame stack from frame to frame with the ...
0
votes
1answer
436 views

ParallelTable 70 times slower on 16 cores than Table on single core

Consider these code(sorry it's messy), why the ParallelTable version is 70 times slower than the Table version? ...
-1
votes
2answers
276 views

Performance of numerical optimization with triple integral [closed]

I'm trying to solve a numerical optimisation that looks something like this: ...
0
votes
2answers
145 views

Can I speed up the following plotting code?

I have the following Mathematica code. I do get the output graphs, but it takes like 12 seconds, on my computer. Longer still if I increase the value of n1. Are ...