# Tagged Questions

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.

123 views

### Efficient solution of huge sparse linear system

I'm trying to improve efficiency of my code in which main task is a solution to huge (~$10^4\times 10^4$) but sparse linear system $$Ax=b$$ (In fact my aim is to solve nonlinear equations $F(x)=0$, ...
118 views

### How to increase speed of iterations with nonlinear functions

Let me ask about part of a problem which I have in solving of a nonlinear DE (numerically). I am working with vectors of length $xN$. I have an initial vector $v$, a given $xN\times xN$ matrix $A$ and ...
217 views

### Speeding up generation of block diagonal matrix

I'm struggling with the following problem. I have $48$ square matrices (full, filled with real machine precision numbers, thus are packed, all different) of size $128$. I wolud like to place them on a ...
92 views

### Deleting isomorphic graphs efficiently

I'm trying to delete isomorphic graphs from a large list. My solution is as follows: DeleteIsoG1[gl_List]:= Module[{}, DeleteDuplicates[gl,IsomorphicGraphQ]]; ...
860 views

### Terrifying performance decrease for contour/density plots in v10.1 -> 10.3

Bug introduced in 10.3 and fixed in 10.3.1 I setup for download a test dataset at http://www.inrim.it/~magni/cm.dat.gz (a set of 64800 triplets x,y,z). The behavior can be reproduced with the ...
91 views

### Count degrees of freedom of a polynomial

I want to count the independent degrees of freedom of a polynomial in three variables $(z_0,z_1,z_2)$. Therefore I take the coefficients of $f$ and compute the rank Jacobian with respect to the ...
111 views

### Manipulate gets stuck when ConvexHullMesh is made transparent

Version 10.3 The followinng Manipulate is a bit slow, but quite OK ...
172 views

### precision and speed inefficiency issues of Nearest function with sqrt expression [closed]

Recently, Nearest has been attacked for many bugs. Some are already fixed. I am going to show some issues when Nearest applied ...
151 views

### How to be more efficient/faster with this MatrixExp-vector multiplication?

I am looking for expertise that helps to improve speed of the code below. First, a little bit of background: There is some system of differential equations $\dot{\vec{m}}(t)=S(t)\vec{m}(t)$. In order ...
352 views

### Smallest element distance between two lists

I have a problem, where I generate two lists of points, and I want to see which points are the closest. If I just want to find which ones are exactly the same, I can use ...
100 views

### MySQL insert statement over remote server is extremely slow. How can I speed it up?

I need to insert values to a remote MySQL server. However it is extremely slow compared to a local MySQL server. This is my timing for the local MySQL server ...
167 views

### Efficient and fastest way to execute 4 nested loops

I have a question regarding the use of ParallelDo. I tried to parallelize the following code involving four nested Do loops by ...
216 views

### Speeding up code for lattice generation

Below is a lattice point generation code I write ...
99 views

### Expensive MeshRefinementFunction

I want to discretize a region using DiscretizeRegion. Now, I want the mesh to be more refined, when the curvature of a certain function ...
63 views

### Can not understand this timing result

I set a=1. tmptmp = Tuples[Range /@ {1000, 100}].{{3 a, 0}, {0, Sqrt[3] a}} And then run ...
57 views

### NMinimize error

I want to use NMinimize in the following way: ...
62 views

### Long delays before showing the result in a notebook

I'm new to Mathematica. I have Version 10.3.0 running under Windows 10, 64-bit. If I open the 10.3.0 kernel and type 2 + 2 Shift Return I get an immediate answer. If I open the main program and ...
130 views

### Speed matrix multiplications

I am trying to run this function ...
205 views

### Exceeding time constraint of 300 seconds when taking coefficients of some expressions from schur polynomial [closed]

I have written a code that takes coefficients of some expressions from schur function, but it seems to take a lot of time, and Mathematica will stop after 300 seconds saying that it's over the time ...
90 views

### Efficiently traversing a list

Suppose I have a large list of algebraic expressions, sorted by their equivalent numerical value (under a certain set of assumptions). Some of these expressions are identical, but commands like ...
202 views

### Timing problem with ReplaceRepeated

I have the following data: ...
108 views

### Parallel function evaluation for minimal value

I am asking myself, if the evaluation of a function f looking for a minimal value over a discrete set of values can be parallelize (brute scan for a potential ...
86 views

### Why does Timing return different times for the same calculation?

I did an experiment in which I calculated the same quantity two different ways to see which method was faster. To my surprise, the kernel time was different in different runs. In fact, which method ...
126 views

### Efficiently generating plots from lists of differing lengths

I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this: ...
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.: ...
91 views

...
94 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 ...
314 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 ...
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 ...
93 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, ...
110 views

Commenting answers of this question @JasonB noticed the big overhead of RandomPoint ...
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: ...
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 ...
292 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 ...
237 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 ...
282 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, ...
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 ...
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: ...
96 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 ...
111 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 ...
110 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 ...
405 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 ...
104 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 ...
100 views

### Fast 1D BinCounts Alternative

I have lots of data which looks like this example: ...
85 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 ...
147 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: ...
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 ...
306 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 ...