# Tagged Questions

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

18 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 ...
11 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 ...
21 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. ...
50 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 ...
62 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 ...
291 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: ...
94 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 ...
125 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 ...
887 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 ...
53 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. ...
248 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 ...
71 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 ...
44 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 ...
24 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. ...
55 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 ...
89 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 ...
33 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 ...
748 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 ...
48 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: ...
120 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 ...
307 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: ...
94 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 ...
53 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 ...
221 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: ...
101 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 ...
196 views

### Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
289 views

### Check whether array has only constant entries?

I have an array arr with n entries. Now I want to check whether ...
121 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 ...
93 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 ...
88 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? ...
405 views

### Total much slower in version 10

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 Total: ...
93 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): ...
112 views

### How do I understand this big difference in speed:

A friend of mine found a huge difference in runtime speed between these two ...
190 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 ...
3k views

### Understanding differences between Maple and Mathematica in examples picked by Maplesoft

I am reading the document "How Maple Compares to Mathematica" found at http://www.maplesoft.com/products/maple/compare/HowMapleComparestoMathematica.pdf. On page 15 there is an example where ...
63 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 ...
537 views

### Suppress connection to Wolfram|Alpha when making unit conversions

I want to speed up calculations with unit conversions. I suspect primarily that some units evaluate from Wolfram|Alpha. Any way to prevent this automatically, so that Mathematica throws ...
48 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: ...
50 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 ...
251 views

### The speed of Sum[] varies strangely

I was curious about the difference in speed between Total and Sum. I found out Total was ...
473 views

### Over 30mins to generate the first eigenvector?

Is it normal for Mathematica to take over 30mins to try to compute the first eigenvector of a 100x100 matrix? The matrix is reasonably sparse - about 90% of the cells are 0s and each column sums to ...
65 views

### Improve on timing of NMinimize

I got a little performance problem with the function NMinimize (it takes mathematica approximately 10 minutes to compute the results). Here i s my sample code: ...
134 views

### Neighbourhood - Calculations

SeedRandom[0]; n = 5; (m = N @ RandomInteger[{1, 3}, {n, n}]) // MatrixForm result1 = MeanFilter[m, 1] // MatrixForm ...
57 views

### Speed up numerical optimization (for plotting and solving)?

Briefly speaking, I want to plot a function PIfun[], which its value is based on numerical optimization using NMaximize. It ...
289 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. ...
418 views

### Colorize Grayscale Image

I have a grayscale image that contains two objects. The grayscale pixel values can be divided into three intervals where two of them represent objects and the third represents the background. The ...
2k views

### Speed up ordering digit code?

My goal is given an integer number to deduce if its digits increase (or remain the same) from left to right or not. Example: $1236, 123336$ are both considered numbers with increasing digits, but ...
138 views

### 2D Fourier transform of a few (4) disjoint discs on a plane

I'd really appreciate some advice. Short Version I'm trying to calculate the following  ...