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

learn more… | top users | synonyms

1
vote
0answers
56 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
522 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
563 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
162 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
232 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 ...
8
votes
2answers
171 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 ...
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
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. ...
5
votes
3answers
254 views

Split list of states by run lengths and discontinuous changes in state

I was asked to look into writing some simulation code for a user, where the simulation output (x) would oscillate between three possible states: ...
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 ...
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 ...
21
votes
3answers
806 views

DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?

Déjà vu: a new-in-v10 function should provide a better solution to an old problem, but my enthusiasm is curbed when I run timings. This time the function is ...
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
105 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 ...
22
votes
1answer
455 views

Total much slower in version 10

Issue introduced in version 10, fixed in 10.0.2 Compilation nowadays may give very fast functions. Here is an example for finding the sum of a list of machine numbers, just as the built-in function ...
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
48 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 ...
2
votes
2answers
63 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: ...
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 ...
8
votes
0answers
105 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 ...
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. ...
1
vote
0answers
83 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 ...
17
votes
1answer
310 views

Why some built-in functions are slow

I just wonder why some built-in functions are slower compared to some other ways using more than one built-in functions for doing same job. consider this example: ...
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 ...
8
votes
5answers
959 views

Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
9
votes
3answers
347 views

Slow work of SQLInsert with SQLite

I want to store my data in SQLite database, but writing large numbers of data its too slow. For example: ...
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 ...
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 ...
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: ...
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 ...
7
votes
1answer
212 views

Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
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 ...
1
vote
3answers
107 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): ...