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)

5
votes
2answers
90 views

Overlap between lists of sublists with different dimensions

I have two lists of sublists. The sublists in the first list contain three elements while the points in the second list contain four e.g.: ...
1
vote
0answers
91 views
3
votes
1answer
91 views

Speeding up constrained optimization problem solving

I have a problem on my homework with Lagrangian multipliers that Mathematica has now been bashing at fruitlessly for 10 minutes. I'm not sure whether I did something horribly wrong codewise, but it's ...
7
votes
2answers
310 views

Wolfram Language symbols by their Ranks

I'd like to get the top 50, the bottom 50 and an ordered list of all Wolfram Language symbols based on their "Ranks". With ...
4
votes
2answers
110 views

Ordering and summing elements of a list based on their indexes

Suppose I have a vector. I assign to every vector index a four-element array, in such a way that index i corresponds to ...
4
votes
0answers
86 views

Improving the speed of an optimization algorithm via compilation and parallellization

I have written an implementation of eight variants of the PSO-algorithm and I want to test them over a set of test functions. I am using parallelization as it improves the speed a lot and I have also, ...
5
votes
1answer
110 views

Huge overhead in RandomPoint[ImplicitRegion]

Commenting answers of this question @JasonB noticed the big overhead of RandomPoint ...
2
votes
0answers
61 views

Follow-up to “How to differentiate formally?”: Efficiency concern

In link to "how to differentiate formally?" and particularly to the answer by @Jens, I want to do something like this: ...
1
vote
1answer
78 views

How to increase time-effeciency of plotting complicated function?

A newbie here: I am trying to use ContourPlot to plot Intensity in a strongly focus laser beam. However this intensity is a function of not so trivial integrals, so ...
14
votes
4answers
289 views

Fast Selections Testing on Inequality

Is there a functional idiom for fast selections testing on inequality? For example, finding values from list a & b where the key is less than or equal to a value, in this case 4 or 9. An ...
4
votes
1answer
233 views

Select elements of list

I have a list of lists list={l1,l2,l3,l4,...}; and two elements e1,e2. I want to select from lists ...
2
votes
2answers
281 views

Good coding for a sequence of derivatives

People on this site keep telling me that good MMa practice avoids the use of loops. The code below calculates the same Table of derivatives two different ways, ...
7
votes
1answer
90 views

fast complement with tolerance between large lists

I want a fast algorithm to get a list of elements to be kicked out of another list. But the kick out criterion is not the exact equivalence, however has a tolerance. Any two elements close enough are ...
13
votes
4answers
370 views

How to evaluate the second argument of Cases only once

I'd like to find a fast but readable way to achieve the following: ...
3
votes
0answers
85 views

Extending Bresenham's algorithm for subpixel rendering

Original Bresenham's line drawing algorithm it limited to drawing lines between two integer pixel positions and does not allow subpixel rendering. However with my reformulation of this algorithm as a ...
2
votes
0answers
110 views

integration of a list of gaussian type orbitals (GTO)

I am currently trying to integrate various components of a current density (j={jx,jy,jz}) over space. The problem is that the current j is extracted from a quantum chemical computation and is a sum of ...
2
votes
1answer
107 views

Is there a good way to check, whether a small value produced numerically is a symbolic zero?

I have a complicated 4x4 matrix and need to know the eigenvalues. I expect a zero eigenvalue for physical reasons. Giving numerical values first gives me an eigenvalue of $\mathcal O(10^{-15})$. Now ...
21
votes
1answer
396 views

Progress bar for FullSimplify

Sometimes FullSimplify takes a really long time and it is not really clear if it makes sense to wait another half an hour in hopes for it to finish, or if it will ...
2
votes
0answers
99 views

General suggestions to accelerate Simplify and FullSimplify

To my understanding, the function Simplify[] and FullSimplify[] work by applying a series of built-in transformation rules to ...
5
votes
1answer
99 views

Fast 1D BinCounts Alternative

I have lots of data which looks like this example: ...
1
vote
1answer
83 views

Increase Performance in the Manipulate Command

The code below pretty much looks like and does what I want it to. However, it is sluggish. I realize I have many calculations, and perhaps this is the best I can hope for. But if anybody has any idea ...
7
votes
1answer
146 views

Speeding Up RandomVariate

Consider the following code where we first take 1000 independent samples from a Poisson distribution, and then take 1000 independent samples from 1000 different Poisson distributions: ...
0
votes
0answers
41 views

Number triangle programming challenge, separate columns

I am about to enter this number triangle https://oeis.org/draft/A262964 in the oeis, but I don't know how to program it properly. This is partly a mathematics question so I could ask it at math se ...
16
votes
2answers
300 views

How to implement Bresenham’s algorithm as a system of equations?

Bresenham's line drawing algorithm is usually implemented via loops. But in Mathematica we can take advantage of its ability to solve Diophantine equations. From educational viewpoint it is quite ...
4
votes
2answers
196 views

PixelValues along a straight Line [duplicate]

UPDATE to the question I have reformulated the question in order to make it distinct from the one suggested as a duplicate: "Line Intensity Profile From Image." The key difference is that I'm ...
2
votes
0answers
66 views

Mathematica computes too slowly at the start of a session [closed]

Everyone, I'm a Mathematica new user. I find it a problem that, when I start a new Mathematica session, it executes too slowly for the first command (say, "1+1", it may take a few seconds before it ...
15
votes
3answers
428 views

Highlighting pattern strings in a large text

I would like to apply Style to strings that are matched, for example, with one or more specified patterns or regular expressions, a string or a list of both, ...
9
votes
1answer
153 views

Sorting eigenvectors according to its projection

The problem I'm trying to calculate the eigenvalues and eigenvectors of a matrix that depends on a parameter x. As x changes, I ...
2
votes
0answers
62 views

Why is this function taking so much more time when its argument reaches 250? [duplicate]

I am observing something which I do not understand with the following function function: ...
4
votes
1answer
170 views

Fast way to get edge-list of graph in terms of vertex indices (not vertex names)

I am looking for the fastest way to achieve the following: Given a Graph, retrieve its edge list in terms of vertex indices (not actual vertices). For example, ...
0
votes
0answers
50 views

NIntegrate within NMinimize - how to optimize the code?

How I can optimize these numerical calculations? Most annoying is encountering instabilities (numerical errors). I have a predefined function: ...
12
votes
2answers
305 views

Efficient conversion between two partition representations

I have a list of distinct expressions. We can represent a partitioning of list in two ways: As a list of sublists ...
11
votes
4answers
641 views

In a list of points, how to efficiently delete points which are close to other points?

Consider a list of points: pts = Partition[RandomReal[1, 10000], 2]; ListPlot[pts] I'd like to delete points so that the minimum distance between two points is ...
4
votes
1answer
98 views

Speed up rendering of ContourPlot3D object

Please can you advise me how to speed up the rendering of the following two planes? When I click and drag to rotate the plot, its movement is quite jerky. Presumably it is working harder than I need ...
12
votes
2answers
334 views

How to make geometric intersection faster for geographic borders?

I have developed a solution to identify geographic regions bordering a region in this post (94723). Can this functionality be made to execute any faster? Find which entities in a set border other ...
0
votes
1answer
44 views

Plotting precise intersections involving singular functions

I have pseudo-elliptic functions defined on a parallelogram within $\mathbb{C}$ and I would like to clearly highlight the path within this parallelogram which satisfies the real part of my pseudo-...
1
vote
0answers
49 views

Evaluation of likelihood very slow

I am trying to implement a simple statistical model for the first time in Mathematica. My model is made my one random variable which is the sum of background and signal. Background is an exponential ...
6
votes
1answer
78 views

Closing over array values makes Compile choke with CompilationTarget -> “C”

When I attempt to Compile a closure which contains an array of the appropriate type, it works just fine with ...
1
vote
1answer
95 views

Recursive calculation is very slow

I've got a recursive definition of Arcs that shares equal length and a several other dependencies to each respective predecessor. (Imagine a book being bent.) I formulated all necessary things here: ...
4
votes
0answers
116 views

Eigenvalues FEAST method - performance is very variable

I am running the FEAST method option for Eigenvalues on sparse matrices of dimension around 500,000. I look for about 50 ...
0
votes
1answer
91 views

Optimization of a voxel projection function

I implemented a function to check if a voxel (3D pixel) is well projected on the space of a image (black and white silhouette) through a perspective camera. The function does the work but It need more ...
5
votes
3answers
186 views

How to populate a large sparse array efficiently

I am trying to populate a large 2D sparse array and sum up all the columns at the end. I tried generating a set of rules and then generate a matrix using SparseArray or break the data into chunks but ...
8
votes
0answers
89 views

More efficient way to generate lattice graph with edges between visible vertices?

Given a nXn lattice, I need to generate the graph such that there is an edge between two vertices iff they are directly "visible" to each other, i.e., there is no vertex between them. I'm using <...
3
votes
0answers
96 views

How to speed up summing a large number of vectors

First let me explain what I am trying to do in my code. Assume that I send a very short chirp (2,000 ms long) into a domain filled with 20,000 particles randomly scattered in the domain. The ...
16
votes
1answer
1k views

Numerical integration — Mathematica vs Python (w/ Scipy) performance

I'm about to tackle a problem that involves a lot of (multi-dimensional) numerical integrations and also subsequent optimizations, and so I want to make sure at least the integration step is as fast ...
6
votes
1answer
133 views

Strategy to build efficiently an image using parts of many images

I have about 1000 images of 1000px $\times$ 1000px and a list which contains the coordinates of the pixels to select, for each of the 1000 images. Each pixel is used once, so the final image is a full ...
7
votes
2answers
298 views

How can this resampling code be made faster?

Suppose I have a matrix: sbt = RandomInteger[{0, 2^16 - 1}, {5202, 3465}]; It represents an image and I would like to do "pixel binning" on it, where I take non-...
24
votes
2answers
635 views

Efficiently generating 2-D Gaussian random fields on the sphere

Context A couple of years ago I posted this question for an efficient code to generate an n-D Gaussian random field (sometimes called processes in other fields of research), which has applications in ...
3
votes
2answers
205 views

Slightly increasing complexity of function increases calculation time by magnitudes

I am trying to calculate an impedance value from voltage and current functions. The calculation method is based on how an actual measurement device performs it. I have two different current function, ...
1
vote
1answer
55 views

NIntegrate option for FourierSeries

I would like to use FourierSeries but it is very slow. My guess is that it is because it uses symbolic integration: ...