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)

4
votes
3answers
139 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 ...
0
votes
0answers
26 views

Parallelization or other speed-up of the algebraic evaluation of Eigensystem

I am calculating the eigen system of a 16 x 16 matrix HCF[B02, B04 …] of 8 variables in it. The matrix is Hermitian and has many 0 elements and only a few ...
1
vote
0answers
28 views

Prevent infinite product from trying to evaluate?

Consider an expression involving several infinite and non-infinite products, like ...
17
votes
3answers
480 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 ...
5
votes
0answers
53 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
72 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
44 views

How to make sure that Mathematica doesn't hog memory for intermediate steps while using functions like FindRoot? [on hold]

I am using Mathematica 10.4. I am trying to solve a set of around 10000 non-linear algebraic equations that I have computed upon discretization of a set of coupled non-linear differential equations. ...
5
votes
4answers
165 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
99 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
59 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
87 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
92 views
7
votes
1answer
88 views

How to boost the performance of my own BSplineFunction

In my CAGD package, I implemented a CAGDBSplineFunction[] like built-in BSplineFunction[]. ...
16
votes
3answers
291 views
1
vote
0answers
74 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
180 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
54 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
48 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
41 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
99 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
81 views
1
vote
0answers
29 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
133 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 ...
5
votes
0answers
48 views

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

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
75 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
123 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. ...
1
vote
1answer
230 views

Histograms of gray scale images

I have a large set of subsequent 8bit gray scale png images (50 Hz). They show the noise of a CMOS camera, with the lens covered. A subset of 50 images is available here: https://goo.gl/Sa3P9P I ...
11
votes
1answer
149 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 ...
4
votes
1answer
282 views

Writing Faster Mathematica Code - Sow and Reap?

I am applying Select function to a large list called xyCoordinateCentreCircle. The dimensions of the list are: ...
3
votes
0answers
112 views

Mathematica Newmark Optimization

Here is my Mathematica code which implements the Newmark method to solve a equation of motion. The variable "ag" contains the accelerations from an earthquake record. Is it possible to optimize this ...
0
votes
0answers
47 views

How to speed up NDSolve?

I have a program where I need to iterate NDSolve thousands of times for different configurations of a diffusion problem. The thing is, I only need about 3 digits of accuracy. I looked thru previous ...
0
votes
1answer
70 views

Faster code for calculat in Integral include derivative

I saw this question How I can get faster I tried help that. But I can not understand. I want to write a faster code for: ...
13
votes
3answers
525 views

Particles bouncing in a 3D box

I made this Manipulate code which shows a pack of particles randomly moving inside a box. It has a huge performance issue. What should be the best way in doing ...
10
votes
1answer
137 views

RandomInteger: speed with long lists

I noticed an interesting effect with RandomInteger when looking at the time to create 10^8 random integers. The following code lines all take about 0.5 seconds on a ...
18
votes
1answer
477 views

Numerical inverse Laplace-Hankel transform

When trying to reproduce the result of this paper about numerical solution of Lamb's problem, I encountered the following double integral (to be more precise, the 0-order inverse Hankel-Laplace ...
8
votes
0answers
126 views

Exporting a high-resolution GraphPlot of a very large graph (65,536 nodes)

Problem I have a very large graph of 65,536 vertices. GraphPlot yields: But the vertices are too dense to see in any detail, and attempting to use any of the ...
0
votes
1answer
75 views

Why are CoefficientRules and MonomialList so slow?

Why is CoefficientRules so slow in this example (v10.2 on OS X 10.11.4)? ...
6
votes
1answer
130 views

Calculate the ESP Grid based on Density Grid

I want to build a fast way to convert a density grid file into a grid file of the respective electrostatic potential (ESP; also known as MEP, the molecular electrostatic potential). This ...
2
votes
3answers
112 views

Strong glitch with Evaluate in Manipulate

I'm experiencing a strong evaluation problem for a Manipulate box and I can't find the best solution yet. Here's a MWE to show the glitch : ...
8
votes
0answers
88 views

More efficient way to generate lattice graph with edges between visible vertices?

Given a nXn lattice, I need to generate the graph such that there is an edge between two vertices iff they are directly "visible" to each other, i.e., there is no vertex between them. I'm using ...
1
vote
1answer
164 views

Why timing of FindRoot is almost the same even if the function is speedup significantly

This question is almost the same issue as this one. However, it seems that it didn't draw enough attention. Now I encountered the same problem. I previously make this post, I will copy the code here. ...
1
vote
0answers
54 views

How to speedup Plot3D with precompiled argument

I have a huge problem with my code: I estimate it to take hours to run. The scheme of the code is the following (I left the steps the same, but took much simpler functions): ...
5
votes
1answer
149 views

Efficiently importing data into Mathematica

I have a graph data file infile.txt. 3 2 0 1 1 2 3 2 0 1 2 1 3 2 1 0 1 2 3 3 0 1 1 0 1 2 3 3 0 1 1 0 2 1 3 4 0 1 1 0 1 2 2 1 ...
3
votes
0answers
74 views

What is the good source to study advanced custom coding in Mathematica [duplicate]

My question is, probably, too general ... I deal a lot with complicated symbolic evaluations, integrations, plotting. I have troubles with optimizing my codes. They come out way too slow. Google and ...
9
votes
1answer
191 views

Fast implementation of Metropolis-Hastings update with multiple sets

This is an optimisation question rather than something I am unable to do. I have a naive, primitive working version of the code (I submit it below) but I am trying to make it work faster. I am asking ...
2
votes
1answer
66 views

Can this simple loop with several counters be improved or parallelized

I am running the following calculations. The timing for H = 2000 is about 8 days on my machine. Can this be parallelized or improved upon in some other way. Also I am trying to avoid storing the ...
6
votes
2answers
341 views

Performance of calculation of means squared displacement

How can I improve the performance of the following code which calculates the mean squared displacement for coordinates stored in data? Here for each time difference ...
62
votes
2answers
3k views

Profiling from Mathematica

I've always wished I could do some profiling like you get in Wolfram Workbench, but directly from Mathematica, without using or having Workbench. If it is possible, how can I do it?