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 (4)

17
votes
3answers
551 views

How to speed up estimation of Mean and Gaussian curvatures on triangular meshes?

I am trying to estimate curvatures on a triangulated surface/manifold using the algorithm of : Meyer, M., Desbrun, M., Schröder, P., & Barr, A. H. (2003). Discrete differential-geometry operators ...
3
votes
1answer
102 views

Efficiently compute this Table of NullSpace

I have two $(2n,2n)$ matrices, $A_1$ and $A_2$, and I would like to compute $$\ker(A_1^p A_2^q -I)$$ for $p,q\leq 2n$. Both matrices are orthogonal and have exactly four non-zeros values on each ...
2
votes
0answers
64 views

How to use Compile? Bivariate Gibbs Sampler

I am trying to use compile to speed up my Gibbs sampler. I know I can use Reap and Sow to speed up tremendously. I have a more complicated Bayesian posterior that I want to speed up with compile so I ...
7
votes
2answers
512 views

How to speed up interpreting numbers from strings?

In processing a large text file I have batches from ReadList of 100,000 Records of the form. ...
0
votes
1answer
47 views

Speeding up WhenEvent + NDSolve (Performance tuning and handling instabilities)

I am solving a non-linear partial differential equation using NDSolve. The equation models a liquid film on an isothermal solid substrate. As a result of various fluid physics mechanisms such as ...
1
vote
1answer
69 views

Keeping determine digits in Append to process

The end of my code is written as below. Ignoring the inefficient role of Append, I want to have very simple set of values as for example: ...
1
vote
2answers
228 views

MatrixPower performs slower than Do loop

I have two almost identical pieces of code: one with MatrixPower responsible for matrix multiplication and another with Do loop. Why the latter performs much faster? It looks counterintuitive... <...
26
votes
5answers
981 views

Can (compiled) matrix permanent evaluation be further sped-up?

Update III  Mathematica 10.2.0 now ships with a predefined System`Permanent function, which the PermanentCode package ...
17
votes
3answers
518 views

How to compute the boundary of a group of ellipse efficiently?

Update1 I discovered that the bountary of a series of ellipses consists of the following three parts Part (I): the first ellipse's effective black-segment; Part (II): the effective ...
2
votes
1answer
179 views

Compiling in mathematica

I'm trying to compile what I think is a pretty simple function that does matrix multilplications in a loop (see below). But Mathematica issues the message: Could not complete external evaluation ...
1
vote
0answers
76 views

Speed differences between Table, Replace, Array, Map, and AssociationMap

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for ...
1
vote
0answers
70 views

Build basic Adobe Kuler-type construction: improving performance / speed

Adobe Kuler is a useful web tool to create colour palettes, but it is limited to 5 colours. I am trying to make a basic Kuler-type construction, but it is very slow, and crashes on my computer for > ...
5
votes
3answers
186 views

Delete all strings that are prefixes of another string

I have a long list of strings and I'm trying to find a more efficient way of removing those elements that are prefixes of another: ...
2
votes
1answer
53 views

how to use Expand command efficiently

Recently I got in a problem and I will try to explain with a simple example. I have an expression which reads : y = (10 + 2*x )/x; Now I want to substitute 1/x ->...
2
votes
0answers
43 views

Is there a way to figure out the “upper limit” of my PC's computational ability in Mathematica?

I am doing some simulations with Finite Element Analysis (FEA) and part of it is forming a mesh in 3D and then using NDSolveValue to solve a differential equation on that mesh. For some meshes, my ...
1
vote
1answer
99 views

How to read a part of huge matrix saved in a TXT file as single expression?

I saved a huge matrix of numbers with dimensions {400, 4001, 2} using Put and got a TXT file formatted in the following way: <...
17
votes
2answers
491 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
2answers
148 views

Definite Integral. Perfomance problem

I have a notebook in Mathematica 4. I'm trying to convert it to use in Mathematica 9. One of the problem is the long computation of definite integral. In Mathematica 4 the result of the following code ...
15
votes
0answers
163 views

FindMinimum doesn't increase step size when necessary

I've spent much time finding a minimal example demonstrating this problem with FindMinimum. Normally one faces this problem when fitting very large and complicated ...
0
votes
1answer
115 views

How to speed up my code for plotting purposes?

Below is my code in order to produce a numerical expression for the final function that needs to be plotted. I have tried to see the output of each successive expression by running the code and ...
7
votes
4answers
229 views

Getting AbsoluteTiming to display in hours, minutes, and seconds

I'm doing some extended length calculations and was wondering how I could get AbsoluteTiming to display in hours, minutes, and seconds. I googled and found nothing, ...
0
votes
0answers
47 views

How to get ContourPlot3D to run involving elliptic functions?

I need to plot zeroes of a function of three variables that involves elliptic functions. For example, I have ...
7
votes
2answers
99 views

TimeSeries interpolation with time gap awareness

Is there an option for ResamplingMethod (or any other practical way) for specifying different behaviours of the interpolation, depending on, for instance, closest dates (on the ...
1
vote
1answer
52 views

Fastest way for data input into StreamPlot function

I'm interested in looking at graphing the phase portraits of 2x2 autonomous ODEs, and I'm using the StreamPlot function. Here is one simple example: ...
3
votes
3answers
110 views

Finding negative sequences in a large list: optimization

I ran across an interesting challenge recently, and I was thinking this community would know how to optimize it. I have several data sets which have (currently) about 50k-100k points. The sets ...
0
votes
0answers
28 views
17
votes
4answers
360 views
6
votes
3answers
233 views

How to speed up computation of medoids?

I need to compute medoids (based on SquaredEuclideanDistance for large lists of k-vectors (k = 14). My implementations so far are impractically slow. Here is a ...
1
vote
0answers
36 views

Prevent infinite product from trying to evaluate?

Consider an expression involving several infinite and non-infinite products, like ...
5
votes
0answers
60 views

Inconsistent performance of code

I'm trying to do some optimizations to my code to make it run faster, but it seems that there are inconsistencies in the performance of the code. Namely, the codes have different performance in ...
3
votes
1answer
81 views

Table with programmatically specified number of iterators in Compile

Compare two ways of computing a table of values of a multivariable Gaussian: ...
0
votes
0answers
102 views

Absolute minimum of a function

I would like to ask for some recomendations in order to get a faster result of a function evaluation to get the absolute minimum. In my desperate moments I have written the following code to get the ...
3
votes
0answers
63 views

What's the most efficient way to load a very large dispatch table?

This question is possibly related to this topic, although I think I have something a little more specific in mind. Recently I've been working with dispatch tables for a project, since it seemed like a ...
0
votes
1answer
91 views

Accessing the elements in a table is slower than calculating each time?

This is a follow-up of How to accelerate combinations and sum calculations here? I have tried all tricks but when N reaches 35 the time is still intimidating in a 16-core server, which is far better ...
2
votes
3answers
94 views
1
vote
0answers
78 views

Using Map instead of For?

Since i am new to mathematica i tried to do some code with several for-loops. However i saw that mathematica is not efficient with for loops and discovered some functions like map etc. So my question ...
4
votes
1answer
211 views

Mathematica 10.X benchmark report for high-end surface pro 4/surface book?

Recently, I am seriously considering purchasing the high-end surface device (with intel i7 and maximal RAM). Mathematica will be one of the main applications. Since it is not a full or traditional ...
2
votes
1answer
62 views

How to accelerate combinations and sum calculations here?

I have a 4d matrix H defined as below (embedded with combinations and sums) ...
1
vote
1answer
60 views

Fast Eigensystem calculation

I have a code which finds the eigensystem for a matrix H = H0 + x HInt, where x is a variable which turns on the interaction. H0 is diagonal, and HInt is a sparse matrix (with about 400 states, I hope ...
0
votes
0answers
42 views

Parallelization and efficiency improvement

Hey i am new to mathematica and at the moment i am writing some test code. It works but it is unrefined. I try to make it more efficient by using parallelization or other techniques. I wanted to ask ...
6
votes
2answers
101 views

Speed up AbsoluteTime with string input

I have millions of strings representing dates in the form: "05-Mar-2004 10:15:00". I would like to convert these to absolute times. For example: ...
24
votes
0answers
2k 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 ...
2
votes
1answer
85 views
1
vote
0answers
34 views

Fast Creation of Label Matrix for Use With ComponentMeasurements?

I am taking a lot of measurements from regions of interest in microscopy images and am finding that generating binary masks to use with ComponentMeasurements is rather slow (at least it's slow the way ...
15
votes
1answer
135 views

Is it better to completely forget about the existence of PowersRepresentations?

I noticed that in several cases the performance of PowersRepresentations is hugely worse than that of IntegerPartitions. (Mma 10....
5
votes
0answers
51 views

Is there a way to tell how much time FindRoot is spending calculating Jacobians? [closed]

I am solving a large number of trascendental equations by scanning FindRoot over a bunch of seeds and a bunch of different parameter values, and I would like to ...
0
votes
1answer
79 views

Problems with NMaximize [duplicate]

The Objective function I would like to Maximize takes less than a second to evaluate. There are several packages needed to evaluate it, so I'm not showing it here. ...
1
vote
1answer
135 views

Speed Up Sampling of Perimeter of Polygon

I have a polygon whose vertices (points) are defined by some image coordinates that I have manually selected. The polygon is used to create a mask for a region of interest in a microscopy image. ...
11
votes
1answer
157 views

Why FoldList 5 times faster than Apply for matrix multiplication? [duplicate]

Consider this list of $2\times 2$ matrices: list=RandomReal[{-2,2},{500,2,2}]; Now compare timings of Apply and ...