Questions about optimizing code for faster results, or how to do faster computations.

learn more… | top users | synonyms

2
votes
1answer
128 views

How to further accelerate arithmetic with Fermat Pseudoprime and Fibonacci number

I've been working on this all night, and I have made this go pretty fast, compared to my first iteration of the program, but now I'm out of ideas. I'm trying to write a program to test (by good ...
1
vote
0answers
57 views

Optimizing orthogonal nonlinear regression code

I'm doing a simulation problem on the Langmuir adsorption model, where I need to obtain the model parameters from simulated data using the orthogonal nonlinear least-squares regression method. Here is ...
10
votes
6answers
529 views

How to find all the positions of max value of a list efficiently?

For Example, list=RandomInteger[{1,100},2000]. Yes,I know Position[list,Max[list]] can do. But it's based on pattern ...
14
votes
3answers
568 views

Why is calling Dot with many arguments so inefficient?

Say I want to multiply a reasonably large list of symbolic matrices. ...
12
votes
0answers
164 views

Performance problems in new Sequence functions

The new-in-10.1 Sequence* family of functions should provide newly optimized methods for handling sequence problems. Happily in some cases they do! For example ...
0
votes
1answer
53 views

Returning functions that are partly evaluated

I have some performance issues when calling Table[{h, Slow1[h, n]}, {n, nlist}, {h, 0.1, 10, 0.5}]; for a given list ...
12
votes
1answer
233 views

Why does partitioning increase Dot execution speed?

I have noticed that multiplying a list of matrices can be significantly sped up by partitioning the list, calculating the product of the partitions matrices, and then multiplying the results. ...
0
votes
0answers
35 views

Speeding up a “filling in” process

I have a sparse EventSeries that looks something like ...
0
votes
0answers
51 views

Computing the coefficients for Gaussian integral

I wrote a small script to find the Gaussian integral points and weights: ...
2
votes
0answers
50 views

How to speed up solution of system of recurrence equations

I was wondering how I can improve the speed on this method for solving a particular system of coupled recurrence equations. The system is $$ \begin{align*} &V(m)=\alpha + \beta V(m+1)+\beta ...
1
vote
2answers
87 views
8
votes
4answers
129 views

ImageApply Performance Difference

How come the timing difference between these calls is so big? (0.2 and 39 seconds on my computer) ImageApply[q3, img] ImageApply[q3[#] &, img] Where ...
1
vote
1answer
33 views

Speeding up EPS exporting ?

I'm using Mathematica 10 to render some figures, and I'm noticing some strange behaviour with EPS figures. I'm making figures like the one below in EPS format. And to do so, I use some code like ...
1
vote
0answers
106 views

How can I speed up this NM optimization? Most delay seems to be due to long analytic expression

I am struggling with computational speed of a NelderMead optimization. Nevertheless my impression is that I lose lots of speed not only due to the NM optimization itself but rather to for instance ...
0
votes
0answers
58 views

Optimising prime number test code

Is it possible to speed-up this code ? Also, It would be great if people could test this algorithm. I only have a Raspberry Pi to test it on, so I can't be certain it's not a strong probable prime ...
0
votes
0answers
49 views

Broad Phase Collision Detection with Mathematica and using CUDA

In this and this post, I asked the question about a fast sweep and prune algorithm implementation for broad phase collision detection. To further speed up things a CUDA implementation would be even ...
2
votes
0answers
68 views

StreamPlot slow in version 10

In version, 10 StreamPlot seems to calculate many more points along each streamline than necessary, compared to version 7. For example, from Mathematica ...
3
votes
1answer
83 views

speeding up creation of SparseArray

I have to create the following sparse arrays, which are reshaped in a two dimensional matrix, so that i can use the build in Dot[] function to do a kind of ...
1
vote
0answers
39 views

Speeding Up the Numerical Integration of a Product of Numerical Integrands with NIntegrate

I need to solve a set of coupled integral equations within a self-consistent cycle. The final result will be functions, say $A(x)$ and $B(x)$, which are related to each other by some integrals which ...
0
votes
0answers
30 views

FindMaximum slow for fixed parameters

I hope my problem can be solved by just showing you this tiny part of my code which does not run on its own. I have an optimization problem and want these functions to work on various data sets. ...
8
votes
2answers
174 views

Relaxation of Mass-Spring System with Pinned Masses

Problem Assume that four masses are connected to each other by springs while two of them are pinned down at their initial positions. Find the position of masses when system is at its minimum ...
1
vote
0answers
86 views

Collision detection algorithm (discrete) with sweep and prune algorithm for periodic boundary conditions

EDIT: Question Updated with solution approach, but solution much slower than original implementation. Any ideas to speed up implementation? In the discussion on collision detection (see here) I asked ...
2
votes
3answers
112 views

Finding minimum of a list of pairs

Sometimes I need to find the Min of a list, whose elements are lists (say of two elements, a pair). Given that Min does not have the option to indicate a sorting function like Sort, I elaborated the ...
5
votes
1answer
144 views

Functional-programming virus infection

Update: The question may seem too broad, but the answer provided by belisarius responds perfectly to the question, as the use of $ListConvolve$ and $NestList$ meets the desired criteria in in addition ...
0
votes
0answers
103 views

Low CPU usage. How to increase it? Should I?

I'm running a programme, and below are some graphics from the resources monitor from windows 8, while running my programme in version 9 of mathematica. Sorry for the foreign writings in the pics, but ...
0
votes
1answer
53 views

How to speed up ReplaceAll in Table?

I am writing a code which solve a list of equations and then create a Table with resulst of equation solving. In applications where I use this code, I create a bunch of equations and my computations ...
0
votes
0answers
31 views

Tricks to speeding up optimisation of a function involving a heavy integration

This is the code, and energycoeffs[] is the function that takes in a dxd matrix and spits out a scalar value. ...
8
votes
0answers
106 views

Efficient image stacking

I have a list of lists of images that I would like to stack and create mean images for each list of images. Images are .jpg files 2592x1944 pixels large. Each list ...
3
votes
2answers
60 views

How do I apply a ColorDataFunction[] to a grayscale image? [duplicate]

Suppose I have a 2D array im of real values between 0 and 1, representing a grayscale image. I can turn im into an image very ...
0
votes
0answers
39 views

Retrieving a Portion of Webpage Code using URLFetch

The URLFetch command is very useful for pulling the entire html source of a given webpage, however, if one wanted to speed up the process, by only requesting a ...
2
votes
2answers
64 views

What is the fastest way to get notebook CellGroups / Cells structure?

So the question is how to get this kind of information: from This is one of my ideas: ...
9
votes
1answer
126 views

Slow work of SQLInsert with MS SQL Server in V10

This question is very similar to: Slow work of SQLInsert with SQLite, but for MS SQL Server. Unfortunately the use of SQLBeginTransaction and ...
1
vote
1answer
55 views

Is this caused by meomory usage ? (Something odd/hard to describe)

I really can't make a "smaller" example, but the files are here, for the data and for the notebook. It will cost a LOT of memory, up to 30G of RAM (maybe more). Here is the problem, (from a Linux ...
0
votes
0answers
126 views

CPU usage ~18%, but Mathematica is fully running

I run some very long Mathematica code, and the CPU usage of the kernel is 18% only. Why is not all of the CPU used, can I find the reason easily? Are there known ways to tell Mathematica to use more ...
4
votes
5answers
292 views

Check whether array has only constant entries?

I have an array arr with n entries. Now I want to check whether ...
2
votes
1answer
131 views

How to speed up my code about Divisors?

This code is about PE496 In[21]:= ParallelSum[n*Count[Divisors[n^2], a_ /; n < a < 2 n], {n, 1, 10^5}] // AbsoluteTiming Out[21]= {5.987342,10724527832} I ...
11
votes
2answers
253 views

Choose between `Apply` and `Map`

Even though this might be too general question(or not answerable), I want to get some advice here. I apologize in advance if it is not a relevant question. I frequently have to process large list of ...
1
vote
3answers
108 views

Speed up NIntegrate, which takes eigenvalues from another function

I have simplified my problem here, in my actual problem the matrix is much bigger which makes it impossible to find eigenvalues analytically. So, I chose standard BCS problem (2x2 matrix) to ...
0
votes
1answer
95 views

How to speed up execution of this function?

How can I speed up the execution of following function, specifically for larger values of n? ...
4
votes
1answer
101 views

Why is C-compiled (but not WVM-compiled) code so slow in Manipulate?

Here is a small section of code from this SE question which computes the real part of the dilogarithm (the upper limit of the sum is increased for demonstration purposes): ...
2
votes
1answer
100 views

Optimizing alphametrics code

First of all, thank you all in this great community. I have been reading a lot of threads about Mathematica optimization learning things like using Compile ...
4
votes
1answer
113 views

How do I understand this big difference in speed:

A friend of mine found a huge difference in runtime speed between these two ...
4
votes
1answer
244 views

Mathematica 10 issue: working with Entities slows down recurrence equations [duplicate]

I was looking at the Mathematica code given at http://community.wolfram.com/groups/-/m/t/326240 where example code is given to simulate the spreading of a supposed Ebola outbreak in Nigeria: ...
3
votes
2answers
213 views

Help at speeding up simplification/nested symbolic integration

I have the following problem: I want to compute an integral of the form $$\int\limits_0^{t_g}\mathrm{d}t_2\int\limits_0^{t_2}\mathrm{d}t_1\left[A(t_1),A(t_2)\right],$$where $\left[B,C\right]=BC-CB$ is ...
8
votes
0answers
98 views

How to make Graphics3D with multiple lighting sources being rendered faster

I have a very "precise"(through setting "SpherePoints") Sphere illuminated by hundreds of random color lighting sources. The ...
0
votes
1answer
68 views

Duplicate values n-times [closed]

I already asked how I can take the list {1,2,3} and get {1,1,1,2,2,2,3,3,3} out of it, adding degeneracy to the problem. So far ...
0
votes
0answers
49 views

More on performance of Sum[]

There is an interesting discussion on performance of Sum[] in this question. I actually wanted to reproduce findings from this answer. So, I entered: ...
1
vote
1answer
52 views

Speed optimization of Mean calculation in a previous calculated data range

I have following problem: My calculations work quite well with the shown testdata, the only problem is the speed of it. My original dataset is about 64000 datapoints, and it takes several minutes to ...
5
votes
3answers
254 views

The speed of Sum[] varies strangely

I was curious about the difference in speed between Total and Sum. I found out Total was ...
2
votes
1answer
68 views

How to handle Indeterminate TimeConstrain

I have to use Timeconstrained[aux] first for avoid some bigs calculation that dont need and it use a lot of time of calculate, so i can't do this. ...