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)

1
vote
1answer
89 views

efficient element wise multiplication of SparseArray vector and matrix

I have a large SparseArray $P$ of dimensions $\{d,d\}$ and I want to multiply a vector (also a SparseArray) $v$ of length $d$ ...
3
votes
0answers
42 views

Prepending a sequence with zeros gives `FindGeneratingFunction` hard time

Asking for FindGeneratingFunction[{1, 3, 11, 43, 171, 683, 2731, 10923, 43691, 174763}, t] gives the answer (namely ...
14
votes
6answers
430 views

Given a large binary matrix, find the largest submatrix containing non-zero elements

I'm looking for a way to reduce a binary matrix containing zeros at some positions into a matrix that contains no zeros by deleting rows and columns of the original matrix until only non-zero values ...
10
votes
2answers
262 views

What is the fastest way to compute digits of $\pi$ using Mathematica?

There are a lot of ways to calculate digits of $\pi$ using Mathematica. The most naïve way I can think of is N[π, 100000000] Of course, there are a lot of fast ...
1
vote
1answer
39 views

Customized `ParallelTable` - Automate `ParallelSubmit` - Possibly an issue with `HoldAllComplete` attribute

Related to this question and in particular its answer I am trying to wrap everything into a new parallelTab function that takes into account some cost per job, ...
11
votes
1answer
99 views

Speed up Dynamic for graphical interface

I am trying to create a user interface where I can click on certain points in a set of data and save them into a list that can be used later in my code. The problem is it is currently sluggish. Is ...
3
votes
4answers
174 views

Find the minimum positive-integer value which meet the requirement

If the equation is Mod[515 Sum[10^(3 d), {d, 0, n}], 53] == 0 Then I can get the minimum positive-integer value of n. ...
4
votes
1answer
220 views

How to speed up calculation of this equation (FindRoot)

I have come up with the following functions, and I need to calculate a value, in order to have a condition valid. In my problem, all data are given, and I need to calculate variable l. I am using ...
9
votes
1answer
119 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 ...
4
votes
2answers
224 views

Elegant way to partition list to be faster than `ParallelTable` (using `ParallelSubmit`), or some alternative?

Suppose you have a function fun[x_] := (Pause[.05*x]; x^2); of which you know that its evaluation time increases with its argument - in this case obviously ...
2
votes
1answer
214 views

Error with FindMinimum. The Message is FindMinimum::cnpcons

I want to run a rather demanding check of feasibility. I have 3565 non-negativity constraints for my variables, and one that makes them sum to a certain budget they shall not surpass. I also have ...
11
votes
0answers
172 views

Slow JoinAcross performance

Bug introduced in 10.3 I am using JoinAcross to combine two datasets, where the key is an Integer. ...
1
vote
0answers
60 views

Speeding up ImageData[image,“Byte”]

For my image analysis I need the Byte values of many sequential 8bit PNG images. To obtain the Byte data I use: ...
8
votes
2answers
283 views

Why is ListPlot[] so slow for coordinate pairs? Can we speed it up?

I compared the time it took to create a plot in two different ways. I expected the first method to be slower, but I was surprised at how much. Is this an inherent limitation or the function, or are ...
0
votes
1answer
53 views

why URLFetch is slow when encapsulated by module and how to fix it [closed]

I'm using Mathematica 10.0.2 on Win7. I'm writing some program to crawl etymology of words on http://www.etymonline.com/. Below lies the example code: ...
3
votes
1answer
116 views

Memory limit hit: optimize code for finding twin primes

I need some help optimizing a Mathematica code so that it'll not max out RAM. Here's the code: Cell 1 ...
1
vote
1answer
35 views

Access variable middle of the run [duplicate]

I execute a Table[] that need large time to be finished. If I abort it I loose what evaluated until now. Does it possible to stop running and save what evaluated ...
1
vote
1answer
97 views

How to improve speed of the following code

The following code do what I needed, but it takes too long ...
0
votes
0answers
59 views

Is this problem parametrically solvable or it can just be solved for specific $\sigma$ and $\theta$?

In order to solve This problem: What is the maximum value of coefficient fv with the constraint that the matrix is positive semi-definite?, I have used the following code (Determinant is computed by ...
6
votes
1answer
197 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
85 views

Is it possible to recover the efficiency of ListConvolve when generalizing the convolution?

I've noticed that, while ListConvolve is very fast, it becomes much slower when you use anything but the standard Times,Plus as ...
7
votes
1answer
152 views

Why is Random faster than RandomReal?

As of version 6, Random[] was superseded by RandomReal[ ] etc, but both still work perfectly well. Playing with some timing ...
19
votes
5answers
492 views

Partitioning a list when the cumulative sum exceeds 1

I have a long list of say 1 million Uniform(0,1) random numbers, such as: dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65} I want to ...
0
votes
0answers
84 views

FindInstance—why doesn't it work with my expression?

I want to find arbitrary solution of a system of equations: ...
3
votes
1answer
136 views

Efficiently generating tuples with Outer

I'm trying to efficiently generate tuples of lists of objects that satisfy a given criterion. The similar questions that I have found on this website end up finding a specific workaround for the given ...
-2
votes
1answer
66 views

Manipulate aborts the computation of NDSolve with the Piecewise function after curtain time [closed]

I'm facing the problem with performance: Manipulate is working fine till end time =60 sec, after that it aborts. There is NDSolve inside Manipulate with Piecewise function, and the plot of the ...
3
votes
0answers
65 views

NelderMeadMinimize for 2D Gaussian fitting

I would like to fit a large number (10^5-10^6) of small images to 2D gaussians by taking advantage of the NelderMeadMinimize package from Oleksandr: Shaving the last 50 ms off NMinimize. The ...
8
votes
0answers
116 views

What are the time and space complexities of Classify/Predict?

Does anyone have knowledge of the O(n) time & space complexities for various model types supported by Classify[] and ...
0
votes
1answer
71 views

Slow sum computation

I'm doing a simple OLS regression and I strikes my attention that this very simple computation takes several seconds to perform in Mathematica ...
4
votes
2answers
119 views

How can I make this code to count Hamiltonian paths faster?

I have this very basic code to count Hamiltonian paths in a graph: ...
15
votes
3answers
481 views

Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
3
votes
1answer
50 views

Replacing elements of a matrix

I'm trying to write a program that takes a given matrix $A$ of 1's and 0's and flips a designated amount of 1's to -1's. ...
39
votes
9answers
2k views

What would you ask Mathematica to do on a big system?

Our hardware supplier has given us the opportunity to test Mathematica on a big Windows system. The specs will be 1 to 4 TB of working memory and 12 sockets with 18 cores each. I got 1 full week of ...
1
vote
0answers
57 views

Solving a polynomial equation with an approximate constraint is slower than the symbolic solution

Why do these two operations have such different timing, when the only difference is specifying r as approximate $0.1$ vs arbitrary-precision $1/10$? Here are the ...
6
votes
1answer
177 views

Fast loading of png files

I need to process through 600 images that are stored as png-files. Each file has 8.3-ish Mb and 2400x2400 pixel (Real32). For a single processor it takes 0.93sec per image to be loaded with Import ...
6
votes
1answer
147 views

Finding mean brightness, standard deviation, count of pixels in gray scale images

I have many sequential gray scale images (2048*2048 pixels, 8bit). To determine the brightness, standard deviation, and count of pixels with in two bins, zero and non-zero brightness, I use the code ...
9
votes
3answers
300 views

Implementation of a matrix formula

For the Bézier surface, which owns the following matrix definition: $$\begin{align*} S(u,v)&=\sum_{i=0}^m \sum_{j=0}^n P_{i,j} B_{m,i}(u) B_{n,j}(v)\\ &=\small ...
3
votes
0answers
57 views

Why is a LibraryLink function, which returns a list, not parallelizing with ParallelTable?

First example: librarylink function return a list of two element ...
16
votes
5answers
626 views

Easiest/most efficient way to delete duplicates from one list at the positions of another?

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the ...
2
votes
2answers
82 views
2
votes
2answers
336 views

How to optimize this code?

I am implementing a code that works correctly but it takes too much time. I did not see how to optimize it to be run quickly. Here is my code: ...
3
votes
2answers
344 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 ...
1
vote
1answer
93 views

How to do this Function with compile

There is 4 lists, 3 of them are at same length (l0, l1 and l3). ...
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 ...
3
votes
1answer
144 views

How to speed up filling a matrix as much as possible in a loop?

In order to find the solution of an $n\times n$ system of nonlinear equations by the method $x_{k+1}=x_k-D_k^{-1}f(x_k)$ where $D_k$ is an approximation of the Jacobian and defined by ...
11
votes
1answer
248 views

Why does Outer sometimes return a packed array, and sometimes not?

For example In[342]:= test3 = Flatten[Outer[Plus, Range[1000], Range[1000]], 1]; // AbsoluteTiming Out[342]= {0.0198735, Null} returns PackedArray ...
1
vote
1answer
91 views

Manipulating Some Lists in Compile

Consider a list of lists, such as: Z={{1,4,3},{2,1,3},{3,1,4}} Z is an $n \times n$ matrix (here $3 \times 3$) which ...
2
votes
1answer
99 views

Product of $N\ 2 \times 2$ matrices and subsequently solving an equation dependent on the product

I have $N\ 2 \times 2$ matrices, each one containing one variable energy which may be complex. I want to muliply them all together to a single matrix ...