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

learn more… | top users | synonyms

0
votes
1answer
75 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
71 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): ...
1
vote
1answer
45 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
101 views

How do I understand this big difference in speed:

A friend of mine found a huge difference in runtime speed between these two ...
3
votes
1answer
169 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
151 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 ...
0
votes
1answer
59 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
47 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
47 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
237 views

The speed of Sum[] varies strangely

I was curious about the difference in speed between Total and Sum. I found out Total was ...
1
vote
1answer
38 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
1answer
463 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 ...
0
votes
0answers
53 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: ...
2
votes
1answer
131 views

Neighbourhood - Calculations

SeedRandom[0]; n = 5; (m = N @ RandomInteger[{1, 3}, {n, n}]) // MatrixForm result1 = MeanFilter[m, 1] // MatrixForm ...
0
votes
0answers
41 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 ...
17
votes
1answer
249 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: ...
4
votes
2answers
387 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 ...
20
votes
1answer
384 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: ...
2
votes
1answer
127 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 $$ ...
6
votes
1answer
138 views

Collision detection algorithm (discrete) with sweep and prune algorithm

For a more complex collision detection approach, I need an efficient (aka fast) algorithm to prune the elements by using boundary boxes. A classical algorithm is the so called sweep and prune (SAP) ...
3
votes
3answers
268 views

Faster Integer Approximation of pi

I'd like to speed up this calculation: First[Sort[Table[{k,Abs[Round[k/Pi]Pi - k]1.{k,1,100000}],#1[[2]]<#2[[2]] &]] The code above generates a list of ...
25
votes
3answers
2k 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 ...
1
vote
1answer
83 views

NSolve for complicated equation involving double cross product

I have the following issue. I am trying to solve a 3-vector equation for the vector slx, sly, and ...
6
votes
3answers
211 views

Speed of ConvexHullMesh

Pick $N$ random points on the surface of the sphere, then use ConvexHullMesh[] to compute their convex hull. Empirically, this takes time quadratic time in $N,$ ...
9
votes
4answers
289 views

Replacing matrix values

I want to find the n largest values in a matrix and replace all others with zero. The solution I found uses ReplaceAll and becomes very slow as the size of ...
9
votes
2answers
174 views

Extracting values with multiple keys

I want to extract sorted data from a huge database based upon two (or more) keys in a very timely manner. Here is a reproducible toy example for two keys only: ...
17
votes
5answers
1k views

How to speed up my Project Euler code

The evaluation speed of Mathematica often depresses me. It did it again when I wrote a code to solve a Project Euler problem. https://projecteuler.net/problem=206 Here's my code: ...
5
votes
4answers
249 views

Speed up Schwarz-Christoffel mapping

I would like to ask your advice how to speed up Contour and Parametric plots in the following example. Let as start by defining a function ...
0
votes
1answer
51 views

Speeding up ReplaceRepeated while truncating to desired order

I need to program in an algorithm that recursively makes algebraic replacements which leads to an utterly complicated algebraic function of $x$, but whose final result is only needed at fixed order in ...
2
votes
0answers
75 views

An efficient way to merge a pair of 4d arrays of non regular length lists

Question I have two 4 dimensional non regular length lists of complex values. I have working code however it seems quite slow and I am not sure how I could improve this. Mathematically I am trying ...
7
votes
1answer
140 views

How do I speed up a plotting of NIntegrate when repeated multiple times inside Plot?

I am studying a set of functions (many of which I know only as a definite integral) and I have assembled into a list. Here is a sample: ...
8
votes
3answers
232 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: ...
2
votes
2answers
84 views

Improving the speed/efficiency of multiple (finite range) convolutions for a causal response plot

So I am looking at modelling the response of a system that is excited by multiple pulses over a period of time. The way to find the response at time t is to take the convolution between the impulse ...
4
votes
2answers
189 views

Time-efficient creation of matrix

I have expressions like xx1=FF[1, 1] GG[1, 1] + FF[1, 1] GG[2, 2] + FF[2, 2] GG[2, 2] xx2=2*FF[1, 2] GG[1, 1] + FF[1, 1] GG[1, 2] + FF[2, 2] GG[2, 2] and I want ...
3
votes
2answers
109 views

Time-efficient manipulation (zeroing) of expression

I have huge matrices in the form of ...
2
votes
1answer
123 views

How can I reduce computation time while still obtaining a good approximation for my function?

I am new to any CAS (and Mathematica, for that matter) and new to StackExchange too, so forgive me and correct me on any mistakes. I have this function: $J_p=\sum_{m,n=1}^{\infty} ...
21
votes
2answers
455 views

Why is Query so much slower than Part?

Time for another of these(1),(2) as yet another new-in-10 function appears to have poor performance compared to older alternatives. This time: Query appears to be ...
3
votes
1answer
130 views

Why is my compiled code slower?

I am trying to make a Mathematica program run faster. Here is part of the original version. It takes as input the integers X (of order 100), J (of order 10000), and n (of order 100), the real number p ...
15
votes
1answer
318 views

Speed up adding Poisson noise to an image

I'm simulating some images corrupted with Poisson noise, but I'm encountering a few problems with performance. According to the documentation on ImageEffect, one ...
5
votes
1answer
154 views

Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
8
votes
4answers
320 views

Fast method to select matrix elements based on a vector of positions

There is an operation for which I have long wanted to find a better solution. Let: a be a matrix of dimensions $m\times n$ ...
7
votes
1answer
238 views

Porting code from MATLAB

I'd like to switch from MATLAB to Mathematica for my research in digital signal processing. I used Mathematica a lot during the '90s but I haven't used it since then, so I might as well be a complete ...
2
votes
0answers
83 views

Mathlink program with low cpu usage on linux machines only

Question I am incorporating some c++ code via Mathlink into my simulations in Mathematica. My questions involves the execution efficiency of the c++ code on different machines. For example, on my ...
6
votes
1answer
176 views

Why is AllTrue much slower than VectorQ?

This seems to be a theme with V10, a new function dedicated to a specific task doesn't live up to expectation performance-wise. Mr. Wizard has already uncovered 2 such functions here and here. So how ...
19
votes
3answers
671 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 ...
34
votes
2answers
785 views

Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
0
votes
0answers
93 views

Timing: how make a program to work faster using built in functions and tables

I want to improve my code to make it working faster even for very large numbers. ...
5
votes
0answers
212 views

Problems extending NelderMeadMinimize into 2D

Update The eventual route I followed was to adapt a version of the NM-simplex written in C and link to it with MathLink. Once I've tested this out fully I'll post it here. I've been playing around ...
0
votes
1answer
87 views

How can I speed up this multi-equation Solve problem?

I'm trying to solve a set of equations (chemical kinetics for a complex system, but don't worry about that). I ran it for 24 hours and I got no output. Here is the relatively simple code (I want to ...
0
votes
0answers
28 views

Speed up series expansion [duplicate]

I have a rather complicated function that I need to expand it in series, which is quite straightforward but takes a long time. I was wondering if there is a way to speed up such a calculation: ...