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
2answers
274 views

Why does having many Print statements slow down my code?

I have a code that I need to debug. I have put a Print[] into it that should give about 10^4 prints for table entries. I know that 10^4 is large, and this exposes ...
4
votes
1answer
412 views

Fast matrix multiplication in MMA and GPU

Matlab multiplies two 3000by3000 matrix around 0.18s faster than MMA. While for just a few matrix multiplications the speed difference is not important, it becomes crucial when I want to do those ...
4
votes
1answer
125 views

Most efficient searching algorithm in a table

I am completely new in Mathematica (and in data analysis in general) and I find it really useful, although I still do not use it properly. I have the following question related to data manipulation: ...
4
votes
1answer
392 views
4
votes
2answers
137 views

Values (or positions) of array row elements within a specified number of positions from target value

I have the need to collect values from the rows of rectangular arrays of arbitrary precision integers, given a target element value and allowed "distance" (positions +/- within the row from found ...
4
votes
2answers
303 views

DynamicModule/Dynamic CheckboxBar Slow for Large Lists

I am trying to create a dynamic construct that takes a large list of expressions and allows the user to interactively select any number of entries for further manipulation. This is what I have ...
4
votes
1answer
272 views

MapThread Alternatives

I want to add two matrices, the first one containing a 2D vector at each position the other one a list of 2D vectors. The 2D vector from the first matrix should be added to each of the 2D vectors at ...
4
votes
2answers
310 views

How can this DivisorSigma code be made fast?

Since Project Euler problems are now fair game for questions I have a question of my own. A certain problem* states: For a positive integer n, let σ2(n) be the sum of the squares of its ...
4
votes
1answer
663 views

How to do the polynomial stuff over finite fields extensions fast?

This question is raised from the problem of package FiniteFields being very slow (please, see the corresponding question): I have had an evidence that Mathematica ...
4
votes
1answer
441 views

using interpolation functions in ParallelMap

Edit I am editing the question to give a simple workable example. It is at the bottom under the heading Example. The original question is now headed withe Background. Background I am trying to ...
4
votes
2answers
123 views

How to be more efficient/faster with this MatrixExp-vector multiplication?

I am looking for expertise that helps to improve speed of the code below. First, a little bit of background: There is some system of differential equations $\dot{\vec{m}}(t)=S(t)\vec{m}(t)$. In order ...
4
votes
1answer
99 views

Huge overhead in RandomPoint[ImplicitRegion]

Commenting answers of this question @JasonB noticed the big overhead of RandomPoint ...
4
votes
2answers
447 views

Quickly reducing the number of decimal digits for a set of real numbers

How can I quickly convert a number with $n$ decimal points to a number of with $m$ decimal points? Round works, however, it is slower than I would like. This ...
4
votes
1answer
234 views

How do I put a Monitor into CDF?

I would like to keep track of progress of a database request in an Enterprise CDF, but it won't allow PrintTemporary or ...
4
votes
2answers
478 views

Collatz Tool Box — any speed ups possible?

I have created a tool box for experimenting with the Collatz conjecture. Info here: Wolfram MathWorld and here: Wikipedia The patterns I have found allow us to make the conjecture jump through some ...
4
votes
1answer
606 views

A Faster way to combine two Lists of different structures into one of a different structure [duplicate]

I have the following two lists (each containing over 500,000 elements). Here is a sample: ...
4
votes
1answer
295 views

Noticeable slowdown in graphical performance when using manipulate

I have been making these mathematica 3D objects that involve a molecule with some sort of surface displayed above them. This is done fairly easily by: ...
4
votes
2answers
204 views

Setting a lower limit on calculation time

Sometimes it can come in handy to set a lower limit for a calculation. Consider for example an animation that is generated by some infinite loop, which would run way too fast to display properly for ...
4
votes
1answer
133 views

How to efficiently find all combinations of the letters in an alphabet given a condition

Problem: I want to find all unique expressions with n number of terms that contain all the digits (or characters) in alphabet. ...
4
votes
1answer
75 views

Fishing for monomials in a nested or partially factored polynomial stream

I have a problem where I'd like to be able to take a multivariate polynomial whose variables are nonscalar and is not written explicitly as a sum of it's nonzero monomial terms and determine which ...
4
votes
1answer
166 views

Optimizing a function containing a complex exponential

I've noticed the following significant different in performance for different formulations of the same function: ...
4
votes
1answer
86 views

Efficiently traversing a list

Suppose I have a large list of algebraic expressions, sorted by their equivalent numerical value (under a certain set of assumptions). Some of these expressions are identical, but commands like ...
4
votes
1answer
290 views

Performance of a Do-Loop of variable length

If I'm changing a basis depending on a (non quadratic) matrix $\mathbf{M}\in\mathbb Z^{d\times k}$ and some $\mu\in\mathbb N^k$, i.e. i have an array a of the same ...
4
votes
1answer
146 views

How to speed up mouse events?

Grids of dynamic objects responding to mouseovers seem to be quite slow in general, for instance: ...
4
votes
1answer
67 views

More efficient method to implement knots instertion algorithm

Knots instertion algorithm of B-spline About the definition of B-spline, please see here. Suppose $\overline u \in [u_{k},u_{k+1})$initially has multiplicity $s$, and suppose it is to be inserted ...
4
votes
2answers
49 views

NaNs in tabular data and import performance

I'm working with some data files that are just too large for Import. I tried using ReadList, specifying either ...
4
votes
1answer
99 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
4
votes
1answer
146 views

Listable on first level [duplicate]

I have some function which take List as input. f[l_List]:=someActions[l] I need apply this function to a list of lists. Now I ...
4
votes
1answer
328 views

How to choose MaxStepFraction for optimal speed of NDSolve

I'm trying to use NDSolve to solve a 1D Schrodinger's equation, and it seems that MaxStepFraction has huge effect on the ...
4
votes
1answer
141 views

Selecting expressions from a sequence that are not subexpressions of earlier elements

I have a While loop that generates and prints an expression on each iteration (there can be thousands of iterations). UPDATE: Some expressions are generated in ...
4
votes
1answer
180 views

MapThread and Compile

After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of ...
4
votes
1answer
260 views

speed up iteration with conditionals plus optimize memory usage

Given list1 and list2 whose elements are vectors of a certain (fixed) dimension, I am interested in the behaviour of a scalar ...
4
votes
1answer
464 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 ...
4
votes
0answers
78 views

Is it possible to prohibit unnecessary CopyTensor in Compile? Just like .noalias() in Eigen library?

Turn on Needs["CompiledFunctionTools`"] First example ...
4
votes
0answers
144 views

strange timing result of LinearAlgebra`BLAS` in mathematica? [closed]

BLAS is short for "Basic Linear Algebra Subprograms". It is a famous collection of routines for doing linear algebra. I just know from Oleksandr R. that mma can directly call BLAS under the context ...
4
votes
0answers
97 views

Eigenvalues FEAST method - performance is very variable

I am running the FEAST method option for Eigenvalues on sparse matrices of dimension around 500,000. I look for about 50 ...
4
votes
0answers
145 views

CompilationTarget to C takes long compilation time

Consider I have a function, with one version that compiled to the virtual machine and one that compiled to C: ...
4
votes
0answers
432 views

Fast principal component analysis

I'd like to speed up a principal value value analysis. The data contains a large set of vectors with a large dimension. Both are in the range of 1000. I want to obtain the loadings matrix for further ...
4
votes
0answers
278 views

Module in numerical model for NonlinearModelFit is slow and leaks memory

I am trying to make a NonlinearModelFit where the model is the result of a numerical calculation. My code works, but it is very slow and also seems to have a memory ...
4
votes
0answers
104 views

2X slower with ; — LibraryLink performance problem [duplicate]

This is the continued problem of the LibraryLink memory usage question here and here. In the following code, there is a 2X performance difference with only the change of ";". ...
4
votes
0answers
137 views

Efficient Generation of Subgraphs (or, unfriend a friend a day)

NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above. My friends ...
3
votes
3answers
584 views

Speed optimization

I have a part of a program that I have to repeatedly call many times (about 2000 to 10000 times) ...
3
votes
2answers
717 views
3
votes
4answers
552 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 ...
3
votes
3answers
299 views

fastest way to perform the following summation

I have a vector $A$ with components $A_{i}$, and two matrices $X$ and $Y$ with components $X_{ij}$, and $Y_{ij}$ respectively. What is the fastest way of performing the following summation ...
3
votes
2answers
222 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 ...
3
votes
3answers
165 views

Optimizing a series of basic matrix operations—scaling doesn't seem right with matrix size

I have a simple operation that I'd like to apply to an n×n matrix. My problem (well, one of them...) is that it runs in, say, 4 seconds for a 100×100 matrix, but it took five and a half minutes to run ...
3
votes
1answer
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? ...
3
votes
3answers
287 views

Mandelbrot set—efficiently iterate over a list of initial points

OP edit: This is a Mathematica-specific question about an approach it attempted for a fractal visualization problem described HERE. I'm using the Mandelbrot set there and here as an example, but the ...
3
votes
2answers
172 views

Optimize evaluation time for a Quantum Walk simulation

Here's the problem. I'm trying to simulate a noisy Quantum Walk to obtain results similar to these, experimentally obtained. I wrote my code, and I get results which are in accordance to what I ...