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)

0
votes
1answer
135 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
176 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
160 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
167 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
239 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
195 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
219 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
268 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
159 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
625 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
161 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
163 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
134 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
101 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
70 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
161 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
253 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
341 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
87 views

Speed improvement in string distance function

I'm using this distance function to compare distance between strings: ...
0
votes
0answers
50 views

Calculate Shapely Shubic power index for larger datasets (enhance performance of code)

I want to calculate the Shapely Shubik Power Index for larger datasets. The code I have (from wolfram demonstration project) runs forever on my mac with a dataset of 15 elements, eventually my ...
4
votes
2answers
149 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
103 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 ...
-1
votes
1answer
298 views

Can we hide Mathematica code? [closed]

Can we hide Mathematica code, so that just input requirements are visible? e.g. ...
11
votes
0answers
719 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
342 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
350 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
47 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
272 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
194 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
713 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
418 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
269 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
139 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 ...
0
votes
0answers
125 views

My algorithm produces too many permutations

Imagine the following problem. A population of size $n$ consists of $i$ men and $n-i$ women. The population goes to the casino. Call $g_m$ ,$g_w$ the amount of money won by men and women respectively. ...
5
votes
1answer
661 views

Hardware Performance Metrics for Mathematica

Dear Mathematica users I am looking into buying a new computer and Mathematica is one of the main applications I run. To help me assess the overwhelming welter of choice out there: I'd like to know ...
1
vote
1answer
159 views

Parallelization of the stochastic Euler scheme

I wrote a simulation to approximate the law of a stochastic differential equation via a Monte Carlo method using the stochastic Euler scheme. Then I thought, it would be a good idea to speed up ...
15
votes
1answer
267 views

A fast, robust DropWhile

For reasons that have never been entirely clear to me, Mathematica has had a built-in TakeWhile function since version 6.0, but has no equivalent ...
7
votes
1answer
454 views

Exporting a sequence of graphs as video efficiently

I have a sequence of graphs that are being created within Mathematica which I'm exporting to create an animated plot of the graph, as follows. ...
2
votes
0answers
72 views

Is there a way to output the number of operations done? [closed]

Analogous to //Timing, I would like to be able to see how many operations my program goes through before producing an output. Does anybody know of a way to do this? ...
0
votes
0answers
91 views

Inconsistent results in fits from NArgMin

EDIT: Just realized I had misspelled "inconsistent." I'm using version 7.0. I'm trying to fit a (noisy) data set to a large-order polynomial. (Just for context: there isn't a model for the ...
15
votes
1answer
229 views

Performance of compiled functions

I am trying to find the fastest way to calculate two values where both of them are sum of different expressions. I combine both calculations in one Sum[]. I'm ...
4
votes
0answers
110 views

Efficient Generation of Subgraphs (or, unfriend a friend a day)

NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above. My friends ...
0
votes
2answers
190 views

Seeking faster method than using Table and If together [duplicate]

See the example below. Is there any way to make this execute much faster and still get the same output ? I have read Conditionals slower than operators? but it didn't really help me as I can't seem to ...