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
1answer
189 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: ...
0
votes
0answers
31 views
2
votes
0answers
84 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
40 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
65 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
489 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
121 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
464 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 ...
-1
votes
1answer
50 views

CompiledFunction::cfsa Argument x at position1 should be a machine-size real number [on hold]

I have a compiled function: g:=Compile[{{x, _Real}},...] and call g through an interim function: g2[x_?NumericQ] = g[x] If ...
-2
votes
0answers
73 views

unordered lists with maximum dispersion [on hold]

As you can implement the following I have a list $$L = {p1, p2, p3, p4, p5 ........ pn}, n <50$$ I need cluttering and print this list 4 ...
8
votes
0answers
119 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)? ...
7
votes
0answers
56 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 ...
8
votes
1answer
103 views

Why FoldList 5 times faster than Apply for matrix multiplication?

Consider this list of $2x2$ matrices: list=RandomReal[{-2,2},{500,2,2}]; Now compare timings of Apply and ...
5
votes
1answer
126 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 ...
4
votes
0answers
115 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 ...
0
votes
0answers
67 views

NMinimize vs Simulated Annealing [closed]

Update I would find the global minima, the plotting shows that this function has many local minima. ...
2
votes
3answers
109 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
87 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
159 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
53 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
146 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
73 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
188 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
63 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
329 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?
9
votes
0answers
115 views

Is there a linter to help write good Mathematica code?

I don't do much real programming, but I've recently been turned on to Atom, which has linter plugins for over 50 languages to make coding easier (most drawing on pre-existing lint-like programs). In ...
8
votes
1answer
91 views

DatePlus and DayPlus perform much worse than my user-defined-function

I was debugging a function speed, and discovered that the time bottleneck was in DatePlus. I tried to change to DayPlus and get ...
3
votes
1answer
93 views

Speed up computation of sum from large matrix

I have a 3x3 matrix (252^3) of data (densities) and I want to compute a correlation xi from nearest neighbours as well as a sum involving a check whether the density is in a certain bin. The ...
8
votes
3answers
341 views

Give a element rank list of a list

SeedRandom[417] list1 = RandomChoice[Range[22, 28], 4] {22, 24, 26, 23} We can get the rank list ...
5
votes
0answers
74 views

Is it possible to speedup these simple linear algebra operations

I'm trying to numerically solve some equations using splitting operator method. The solver I construct iteratively constructs a matrix and feeds it to LinearSolve. ...
9
votes
1answer
115 views

How to optimize my own BezierFunction?

A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail. I also know that BezierFunction[] is built-in ...
2
votes
0answers
86 views

Optimization of custom probability distibutions?

Consider the two tests: Timing[Do[RandomVariate[NormalDistribution[0.5, 0.3]], {200}]] {0.001188, Null} ...
2
votes
1answer
58 views

Twin Prime Max Gaps (Performance Tuning)

Ok, let's build a foundation here: A common way of testing primality, is dividing by all primes smaller than the number's square root. For instance, $97$ is prime because dividing by none of the ...
0
votes
0answers
45 views

How to calculate a continuous function once and access values later?

I have a function that involves a numerical calculation: h[v_]:=NIntegrate[f[x]*Log[p[x, v]], {x, -Infinity, Infinity}] I need to visualize how well a bunch of ...
4
votes
0answers
67 views

Sudden changes in performance

Last week Mathematica was working fine. At the beginning of this week I went on a trip and it slowed down. I ran Needs["Benchmarking`"] BenchmarkReport[] The ...
2
votes
0answers
74 views

FourierCoefficient performance

I encountered weird performance issue while using FourierCoefficient[]. I narrowed it down to calculating $n$-th coefficient for $\cos(nx)$. ...
1
vote
1answer
208 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 ...
3
votes
2answers
137 views

Fast way to evaluate the PDF of a multivariable distribution

I'm trying to evaluate the PDF of a truncated multi-normal distribution. My distribution has 8 dimensions and each value must be ≥ 0. ...
1
vote
0answers
50 views

Estimating processing time for commands

I am trying to evaluate some equations by using Taylor series of expansion (Series[], ExpandAll[], and Normal[] command), and using n equation and n unknown (Solve). Following is not full command (if ...
0
votes
1answer
159 views

How I can get faster code for computing a fractional integral?

I use of this code Fractional Integral and wrote the following code: ...
9
votes
2answers
192 views

ParallelTable behaves differently when it is run inside a package

I've been butting my head against some very weird behaviour by ParallelTable, and its interaction with packages, over the past few weeks, and making relatively ...
4
votes
2answers
100 views

Efficiently strip off coefficients in front of variables?

I am working with multivariate polynomials and need a very efficient way to decompose monomials into coefficients and pure monomials. for instance consider variables ...
3
votes
2answers
76 views

Perform matrix/tensor contractions more efficiently

Problem: explicit index contractions for matrices using the Sum command take too long, and I want to improve the performance for complicated computations. Let me ...
8
votes
5answers
291 views

What is the most efficient way to replace items in a list at periodic intervals?

For example, if I want a list of $\phi(n)$ for $1 \leq n \leq 100$ but if $n$ is a multiple of 3 I want to show a 3 instead of $\phi(n)$. I tried ...
1
vote
0answers
80 views

How to speed up the construction of a large matrix

As a part of a physics problem that I'm working on, I need to construct a rather large matrix. The matrix is a real symmetric $2^{m}\times 2^{m}$ matrix for some integer $m$, which we would like to ...
1
vote
0answers
94 views