# Tagged Questions

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.

876 views

### How can I speed up the classic GA for graph coloring?

I'm trying to compute the chromatic number of this graph (which is 28): g = Import@"http://www.info.univ-angers.fr/pub/porumbel/graphs/dsjc250.5.col"; My genetic ...
2k views

### How to speed up the function DelaunayTriangulation?

First define a function meshGrid to generate some points: ...
1k views

### How to solve an eigensystem faster?

I have a module that I need to call 1-10 million times in my program. Currently, it is taking several hours to run so I am hoping that I can cut down some runtime with your help. ...
440 views

### Removing calls to MainEvalute when using inlined compiled closures

This question is tightly related to the answer Shaving the last 50 ms off NMinimize. There @OleksandR shows how inlined closures can be used to eliminate calls to ...
5k views

### Making fractals with Mathematica

I recently saw this post on math.stackexchange and was curious as to how to generate the image in Mathematica. I tried the following naive approach; however, it is extremely slow. ...
1k views

### How to speed up Minimum Spanning Tree algorithm?

How to speed up MST algorithm? I work with graphs and I have adopted Prim's algorithm for my needs, from here. The graphs which I use are very dense (number of vertexes: $V=500$ and every vertex is ...
2k views

### 3D Random Walk with Periodic Boundary Conditions

I am working on a 3D random walk with periodic boundary conditions and have written a program that will do this for me, but it is extremely slow. Does anyone have any suggestions on how I could speed ...
692 views

### Speeding up construction of simple tridiagonal matrix

I have the following code to construct a tridiagonal matrix: ...
696 views

### How to sum up large number of elements in a table quickly?

I have been using Mathematica for some time now but I have a feeling that I am not using it as efficiently as it could be. I have the following problem which I am unable to figure out and it would be ...
5k views

### How to calculate the mode of a probability distribution

I was wondering if there is any command to get the mode of the probability distributions. Calculating manually, the mode is (alpha-1)/(alpha+beta-2) While the mean, median or variance of the beta ...
594 views

### Using Evaluate and Evaluated -> True in Plot

A few use cases: (1) This, as expected, returns (almost) immediately: f[x_?NumericQ] := Evaluate[(Pause[1]; x)] Plot[f[x], {x, 0, 1}] (2) This takes ...
114 views

### Factor out invariant code from Plot

Given a simple Gaussian kernel UnscaledKernel[a_, b_, sigma_] := Exp[-(((a - b)/sigma).((a - b)/sigma))/2] and un-normalized smoothing function ...
433 views

### Why is AstronomicalData so slow?

I'm having trouble getting some pretty simple functions using AstronomicalData to perform at anywhere near the speed I need them to. For example, I have many ...
704 views

### Launching remote kernels - will it help RAM needs?

Given the exasperating RAM needs of my Mathematica program, I contemplated launching remote kernels to run my Mathematica script. This is a two part question: Part 1 If I launch a remote kernel(s), ...
2k views

### Improving NDSolve speed for heavily stiff problems

Having looked around the intergoogles and Mathematica.SE, I thought I'd pose a question with a minimum working example. Here is the situation I am trying to improve: I am solving a 4th order non ...
557 views

### Faster code for specific problem

Sorry, but I need the following code much faster and I'm running out of ideas. I do appreciate any help. I post two of my fastest ideas (tab and mat), although they are not really fast. Thanks in ...
322 views

### Comparing LetL and Module efficiency

I was recently introduced to the LetL macro thanks to Leonid's answer to one of my prior questions. I was, needless to say, impressed by the simplicity of its ...
881 views

### Web scraping and multi-threading in Mathematica

I'm working in some web scraping using Mathematica, and today, to speed-up the process, I used bash commands (xargs with parallel options with curl and wget) using ...
522 views

### How to speed up drawing a tangent plane?

I have this code to produce an interactive visualization of a tangent plane to a function: ...
481 views

### Efficient way to perform elementary integration step with NDSolve internal method

I'm trying to tweak the NDSolve function to perform one elementary integration step (using some explicitly selected stepping algorithm via ...
422 views

### Elementwise, compilable min function

I am trying to implement efficiently a transfer-matrix like algorithm. On each iteration, I have two vectors $x=\{x_1,\dots,x_n\}$, $y=\{y_1,\dots,y_n\}$ with real numbers and I need to compute the ...
585 views

### How to solve simultaneous equations faster with Compile?

I have large 6x6 matrix Uwhich is a multiplication of 15 rotational matrix. All of the elements are Sin\[theta] and ...
1k views

### How to quickly calculate intersections of filled curves?

I am trying to quickly calculate the intersection of polygons with more than 6,000 points. A compiled solution would be preferable. Here is one example of the problem: ...
1k views

### Why is my animation so slow?

I have an animated plot of the kind ...
478 views

### Combining lists with common elements efficiently [duplicate]

Possible Duplicate: Computing the equivalence classes of the symmetric transitive closure of a relation I am required to process sets consisting of 2-element subsets of integers by combining ...
938 views

### Is there a simple example using OpenCLLink that shows performance advantages?

OpenCLLink allows Mathematica to use the OpenCL parallel computing language. I have done some tests on simple examples, but so far, the CPU regularly outperforms ...
1k views

### Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
312 views

### Using Compile to speed up Function with PermutationProduct [closed]

I have the following fairly simple routine dot involving PermutationProduct that I wish to speed up using ...
2k views

### Fast Spherical Linear Interpolation of list of quaternions

An accurate way to interpolate between two quaternions is to use Spherical Linear Interpolation (Slerp) because it preserves the unit length, whereas straightforward linear interpolation does not, as ...
269 views

### Why is LogLogPlot[] slower than Plot[]?

I notice that LogLogPlot runs quite bit more slowly than ordinary Plot. For example, consider the following two blocks of code ...
2k views

### How to improve the performance of solutions to Project Euler (#39)?

This is the problem 39 of Project Euler, which I asked in the chat room two days ago. My original code runs as slowly as snails, and finally I got two answers from JM and Rojo. Unfortunately, both of ...
331 views

### How can I efficiently check if a graph is unit distance?

A unit distance graph is a graph that is embeddable in the plane so that every edge has length 1. ...
1k views

### What is the fastest way to count square-free words?

Background A word is a string of letters in an alphabet. A square-free word has no adjacent repeating substring. For example, (in the ternary alphabet of {0,1,2}) the words 00, 012121, and 0212012021 ...
352 views

### Compiled version of (Norm/@coordinates)

Here I define (NormCoordinates). ...
562 views

### Compiled function error - nontensor object created

I'm trying to optimize code that uses Position MANY times. The following toy code works: ...
609 views

### Very fast way to do a coordinate frame transform

I need a function that rotates and translates a huge amount of line segments. For example, I have a set of line segments in the form {{x0,y0,z0},{x1,y1,z1}} ...
697 views

### Preconditioning the objective function of NIntegrate for higher PrecisionGoal

By default, NIntegrate works with MachinePrecision and its PrecisionGoal is set to ...
2k views

### Methods to speed up numerical NDSolve, NIntegrate,

I am not very used to do numerical simulations on Mathematica. Do you have any ideas how to improve i.e. speed up my code? ...
1k views

### PolarPlot render oddities

I apologize if this is a obvious question and answer, I don't often use Mathematica to display plots or graphics in general to be honest. So, I was tutoring my cousin yesterday in relation to Polar ...
649 views

### How can I effectively performance-profile Dynamics?

How to optimize performance-wise a complex dynamic expression (like a GUI) with lots of dynamically updated components, which require different update-frequencies? I was hesitant to ask this question ...
4k views

### Best way to create symmetric matrices

From time to time I need to generate symmetric matrices with relatively expensive cost of element evaluation. Most frequently these are Gram matrices where elements are $L_2$ dot products. Here are ...
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?
403 views

### Faster Alternatives to DateDifference

I need a faster implementation of FractionOfYear and FractionOfMonth, which do the following: Input: A time/date specified by <...
947 views

### How to tell mathematica not to resolve stiffness issues

Very often I solve partial differential equations that are nonlinear and could be up to 4th order. In these cases, it is usual for the solution determined by NDSolve...
2k views

### Happy 2K prime question

This being the Q number 2K in the site, and this being the day we got the confirmation of mathematica.se graduating soon, I think a celebration question is in order. So... What is the fastest way to ...
1k views

### Faster alternatives for DayOfWeek

It has been noticed on several occasions that DayOfWeek function is rather slow when applied to a large list of dates, e.g. in this recent question. What faster ...
557 views

### Tridiagonal symmetric matrix eigenvalue using bisection

I know that Eigenvalues is already quite well implemented in Mathematica, nor am I foolishly trying to improve on it. In order to improve my programming skills, I ...
1k views

### What compilers are “suitable” for CompilationTarget->“C”?

The documentation for CompilationTarget says, "if you do not have a suitable C compiler then you will not be able to set CompilationTarget to C". Well at this time, I don't have a compiler installed ...