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
2answers
181 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
114 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
72 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
95 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
167 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
269 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
354 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
154 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
110 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
810 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
91 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
359 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
419 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
51 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 ...
14
votes
0answers
288 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
199 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
787 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
474 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
285 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
151 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
127 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. ...
7
votes
1answer
762 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
162 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 ...
18
votes
1answer
309 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
542 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. ...
0
votes
0answers
94 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 ...
17
votes
1answer
241 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
119 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
203 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 ...
5
votes
1answer
169 views

What is the fastest way to maintain a large set of expressions?

In my algorithm I need to maintain a set (an unordered list of distinct elements) of expressions supporting two operations: Test an expression for membership in the set Adding a new expression to ...
8
votes
1answer
549 views

Integration strategies for oscillatory multidimensional function

I am seeking to integrate a highly oscillatory, multidimensional function. I am currently using NIntegrate's QuasiMonteCarlo approach. However, this is time-consuming and, given my current resources, ...
2
votes
0answers
196 views

why version 9 is much slower than version 8 in producing these graphics

Consider this example(taken from Thomas's question here) ...
1
vote
0answers
74 views

Is the TCPIP link type compressed?

Since I'm already piping a MathLink connection in a ssh tunnel (connect back is a pain!), I wonder if it makes sense to compress the data in the stream (ssh -C). As ...
11
votes
3answers
685 views

Every second evaluation in notebook front end is slow

I'm having a rather baffling problem that Wolfram was unable to help me diagnose, and I'm hoping one of you geniuses in residence here can figure it out. (I don't get access to the Technical Support ...
27
votes
0answers
452 views

Why is StringExpression faster than RegularExpression?

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
5
votes
0answers
84 views

Faster way to perform SameQ[Reduce[…], Reduce[…]]

I'm have some expressions that I need to confirm the equality of. SameQ[Reduce[...], Reduce[...]] works like a charm for the more simple expressions, however when ...
2
votes
0answers
168 views

Speeding up a numerical constrained quadratic optimization

I'm trying to solve a quadratic optimization problem in 35 variables, $\vec{α} = \left< α_1, \ldots, α_{35}\right>$: $$ \begin{aligned} &\operatorname*{maximize}_\vec{α}&&1.0\cdot ...
8
votes
2answers
128 views

vectorized operations is not efficient?

Consider the following example: ...
14
votes
1answer
249 views

How to create internally optimized expression for computing with high WorkingPrecision?

I have large dataset and need to fit rather complicated function on it with different values of one of its parameters (this parameter must be fixed in every fit). I use the ...
2
votes
3answers
284 views

Using ImageTransformation[] with a lookup table

I need to transform images by ImageTransformation in a time critical application. Therefore I precalculate a lookup table lut of ...
3
votes
2answers
208 views

How to replace Do loops by Inner

I need to replace Do loops by something else because it takes forever with big programs. I have been hinted towards Inner, but ...
2
votes
1answer
114 views

Optimizing a simple calculus using a list of matrices - Repeated dot product between a vector and a list of matrices [closed]

I want to make the following operation : $$ \begin{bmatrix} \dot q_1\\\dot q_2 \end{bmatrix} + \begin{bmatrix} \begin{bmatrix} q_1 & q_2 \end{bmatrix} \mathbf A_1 \begin{bmatrix} q_1\\ q_2 ...
4
votes
4answers
397 views

Remove linear trend from data

I have a large data set with 150k lines and two data columns. I noticed that there is a linear trend, which I want to remove. So, I do the following: first fit with a linear model ...
18
votes
3answers
380 views

How to flush machine underflows to zero and prevent conversion to arbitrary precision?

I'm working on some pretty intense computation in Mathematica; when my code started running slowly, I tracked the source of the problem to Exp[]. I need to ...