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.
0
votes
2answers
106 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 ...
4
votes
0answers
79 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 ...
7
votes
1answer
108 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
142 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
50 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 ...
6
votes
1answer
112 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 ...
21
votes
0answers
157 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
51 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
68 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
111 views
7
votes
0answers
69 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 ...
5
votes
0answers
180 views
2
votes
3answers
142 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
181 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
84 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 ...
3
votes
4answers
170 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
...
4
votes
3answers
179 views
Improving speed of Exp[]
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 ...
4
votes
1answer
120 views
Why is this code in functional style is slower than procedural style?
I know that in Mathematica a functional programming style is often more efficient than procedural style programming using For loops. But the code shown below seems ...
5
votes
0answers
117 views
Parallelizing is much slower than single kernel evaluation?
Starting with a vector of matrices, tVec, I would like to parallelize the multiplication of each element with the same matrix ...
1
vote
1answer
107 views
how to reduce the time to calculate triple integral
i want to evaluate the following integral, but it takes 15 min to do it. i must reduce the time to calculate it, i have to do a table and create a graph, but takes too long.
anyone have an idea ?
...
6
votes
2answers
127 views
How can this AbsoluteTime call be made faster?
I need to convert tons of date strings into absolute times. This generates an example data set of 10,000 strings:
...
5
votes
0answers
79 views
Compiled function crashes kernel when trying to list over different length arguments
I'm trying to speed up a tally/binning operation that I have to run many times.
I have many lists of between 1 and 10 numbers from the range [1,5] and I want to ...
2
votes
0answers
59 views
Significant platform-dependent efficiency when importing data?
I'm curious, as I understand that answer this way:
If you are using a Linux derivative or something like cygwin on
Windows, then this is an efficient solution for reading only the third
field ...
4
votes
2answers
92 views
Efficient drawing of convex polyhedron given a set of points [duplicate]
I have a set of points in the 3D space and I want to draw the bounding convex polyhedron of those points. A very naïve solution would be to draw a triangle between every three points:
...
2
votes
2answers
122 views
Importing several huge files with headers & footers
having here several files in ASCII format
http://ge.tt/91rv0Jf/v/0
I want to import, while removing headers and footers and then join the several lists.
...
13
votes
3answers
384 views
Select performance
I am fairly new to mathematica and working my way thru Paul Wellins book on Mathematica programming so experimenting with various language constructs. I was experimenting with ...
2
votes
1answer
94 views
How can I place gui controls inside Grid? [duplicate]
In all my apps, I am facing a problem about placing the Gui controls inside Grid.
For this purpose, I wrote three functions.
The first function, ...
0
votes
2answers
146 views
Fast Autocorrelation Computation
I want to compute the Autocorrelation Function (ACF) of a data table with $10^6$ entries. I know that there is a built-in function in Mathematica for that, but because I do not know how exactly it is ...
0
votes
0answers
98 views
Speeding up a for loop by removing a Sum command
I am attempting to create an array that has of order 1000 x 1000 entries. In the entry of the last column of each row, I have to carry out a sum that could contains 100s of terms (I only used 40 here ...
10
votes
4answers
413 views
Finding Local Minima / Maxima in Noisy Data
I'm trying to find local minima / maxima in noisy data, consisting of data values taken at certain time intervals. Ideally, the function should take a pair of lists (one containing time values and one ...
2
votes
0answers
150 views
MathKernel.exe capped to use only 13% of CPU?
I am using a Windows machine with 8 cores. No other process than Mathematica 8 is using CPU time right now - still the MathKernel.exe CPU usage does not go beyond 13%. My current computation takes ...
5
votes
1answer
273 views
Montgomery Modular Exponentiation
I'm trying to write a Montgomery exponentiation based on this which can compete with Mathematica PowerMod. We know that PowerMod ...
13
votes
1answer
310 views
Optimizing a Numerical Laplace Equation Solver
Laplace's Equation is an equation on a scalar in which, given the value of the scalar on the boundaries (the boundary conditions), one can determine the value of the scalar at any point in the region ...
13
votes
2answers
333 views
Fastest way to measure Hamming distance of integers
I am looking for a fast and robust way to calculate the Hamming distance of integers. The Hamming distance of two integers is the number of matching bits in their binary representations. I expect that ...
1
vote
2answers
163 views
What ways are there to convert an Integer to a list of digits?
How can I convert an Integer to list of numbers? For example:
781049 ==> {7, 8, 1, 0, 4, 9}
What are the possible ways of ...
4
votes
0answers
101 views
Speeding up multilinear PRA branch-and-bound algorithm with worst-case exponential time scenario with respect to basic events
The algorithm is a branch-and-bound algorithm that calculates dominances for PRA, probalistic risk assessment. The task was to find faster ways to do it in numerical software such as Matlab but we ...
1
vote
1answer
175 views
-1
votes
1answer
64 views
Integral evaluation taking too long [closed]
When I try to evaluate the following integral, it runs for a much longer time than I think is should without producing a result. What might be the problem? Can anybody please point it out?
...
7
votes
1answer
144 views
Efficiently filling area with disks located at certain points
Starting from a set of points, I want to fill an area using disks. Each disk's center should be one of the points and the disks should not overlap. I've managed to write a function that, given a list ...
4
votes
2answers
122 views
Speed up plot of $\sum_{j\ge1} 2^{-j}(1-2^{-j})^{n-1}$
I'm a beginner at Mathematica. I would like to plot the following function:
$${n\over2} \sum_{j\ge1} 2^{-j}(1-2^{-j})^{n-1}$$
However the following code is just too slow:
...
1
vote
2answers
92 views
Speeding up a simple simulation with random extractions
I wonder if anybody can help, I need a hand with a simple simulation I am writing with Mathematica (I am using version 8). Basically it creates a list (called l) with numbers from 1 to n and a random ...
0
votes
0answers
86 views
Speeding up numerical computations
So, after seeing this and this post, I was thinking whether there were any general rules for speeding up numerical computations (not only NIntegrate or ...
2
votes
0answers
97 views
Is there documentation on the comparative performance of Mathematica functions?
Recently I have been solving some Project Euler problems. I find there are always several ways to do the same thing. For example, one could join two lists like this:
...
5
votes
3answers
162 views
Benchmarking expressions
It often happens that I'd like to know which of two or more alternative expressions (that should evaluate to the same value) is fastest. For example, below are three ways to define a function:
...
6
votes
4answers
157 views
Why does array packing in Table behave like this?
Consider the following example, which generate two identical arrays. Why sometimes the array is packed and sometimes it doesn't? And why they perform differently?
Here the arrays are packed:
...
9
votes
1answer
168 views
Modular arithmetic - efficiently calculating the remainders of factorials
When working on this question regarding the divisibility of the sum of factorials, I decided to write some code to test "small values" of the problem using the following code.
...
14
votes
4answers
278 views
How to remove duplicates from set of machine precision 2D points?
I have a set of 2D points with machine precision coordinates. I need to remove all duplicates. Performance is important.
This is the most obvious fast solution:
...
12
votes
3answers
574 views
Fastest way to calculate matrix of pairwise distances
It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
12
votes
5answers
205 views
Faster way to convert triangle list to edge list with no duplicates
I have a list of triangles returned by a Delaunay triangulator, in the following format:
...
10
votes
5answers
497 views
Iterate until condition is met
I want to find the first 5 prime numbers of the form $n^6 + 1091$. I have used this code:
Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]]
Which gives ...





