Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

1
vote
1answer
33 views

Optimisation of a loop

I've opened a question here, which was answered. The code works totally fine for a small set of data. However, for a large set and over many iterations, it will take a long time (in order of 24 hours)....
1
vote
1answer
60 views

Toroidal metric in a random geometric graph

I have some code I've been using to generate some random geometric graphs as fast as possible. The boundary conditions on the rectangular domain I am using sometimes interferes with a clean ...
0
votes
0answers
65 views

Efficient way to make updates in a big List

I would like to know is there is a way to do this: ...
5
votes
2answers
84 views

Perfomance in Position

I need to find the position of elements in list that are present in close. These are both 2D lists. The code is simple but not ...
8
votes
3answers
91 views

Find positions of certain value in a big boolean list

I would like to know is it possible to find positions of False in t: ...
1
vote
1answer
116 views

Forming Kronecker products for “non-adjacent” vector spaces

In quantum mechanics, we often want to build operators acting on multiple particles by simply "Kronecker-ing" operators from the single-particle spaces. That is, if I have some matrix $A$ acting on ...
4
votes
0answers
129 views
+50

Loopy Belief Propagation

I look for an efficient way to implement a Belief Propagation in Pairwise Markov Random Field. Each node is a binary random variable, and the unary potential function is ...
0
votes
1answer
40 views

Table Creation Slow Performance

The following is a question in regards to the matrix $A$ (originally the zero $4n \times 4n$ matrix) below: ...
2
votes
1answer
53 views

Save a list as a value in the sparse matrix

I am interested in save a list (the size of the list is two) of numbers in the sparse matrix, but this is not supported. Maybe you familiar with some workarounds or any suggestion on another data ...
5
votes
2answers
254 views

Replace values in sparse matrix

I am interested in updating the values of the sparse matrix. I have a list of matrix element which I am interested in updating and a list of new values. Currently, I do it in the following manner: <...
7
votes
3answers
269 views

DFT for Helium atom

I'm trying to solve this problem I'm not a Mathematica expert, but my program works perfect when vhartree={0,0,..,0} This is the program I wrote: ...
3
votes
1answer
62 views

Find k smallest sum n-tuples

Given a collection of sorted lists {l1, l2, ...} I need to find the smallest k index tuples taken from these lists by summed ...
3
votes
2answers
123 views

Increase Performance of WhenEvent in NDSolve

I'm trying to reset the value of functions $u_{i}$ when they reach a threshold $θ$. Below the threshold, they evolve according to a simple differential equation. The $r_{i}$ resets the derivative to ...
4
votes
2answers
108 views

Get the number of specified elements from the SparseArray properties

In the sparse matrix, we have a list of properties: specified elements, dimension, default, and density. I am interested in getting this data without calculating them again. For an example, the ...
3
votes
1answer
60 views

Get the dimensions from the SparseArray properties

In the sparse matrix, we have a list of properties: specified elements, dimension, default, and density. I am interested in getting this data without calculating them again. For an example, the ...
0
votes
1answer
29 views

Simplifying a large expression (just for subtraction and addition) [closed]

Consider a large expression which contains terms like a/x+b/x^2+c x + d x^4 +...-b/x^2 +h x -a/x +... I want to find limit of the expression when x goes to zero....
0
votes
4answers
73 views

Fast way of finding diverging terms in a huge expressions

I have a huge expression called exp1 which is a function of rr. There are some terms in the huge expression which diverge when I put rr equal to zero. I want to find these terms. Does any one know an ...
8
votes
4answers
267 views

Replace diagonal elements in sparse matrix

I am interested in replacing all elements in a diagonal of a sparse matrix with zero. Currently, I do it in the following manner: ...
1
vote
1answer
81 views

Performance Tuning - How can I make Mathematica to use less than certain digits number?

I would like to know if there is a way to make Mathematica to use at most certain digit number. For example, Suppose I want to calculate 2*Pi. x=N[Pi] y=2*x ...
1
vote
2answers
45 views

VectorPlot3D not working as expected (but other functions for same input are)

This is a follow-up question from my previous question. What I was trying to do was to plot the contour plot of the following given scalar function. $$\Phi(x,y,z)=\int_{h=-a}^{a}\int_{k=-b}^{b}\int_{...
2
votes
1answer
116 views

How to increase performance of this code for plotting a contour plot?

I have an equation which I need to triple integrate over a unit cube. The equation is ...
6
votes
1answer
287 views

How to find k largest element and their position in a matrix?

I have a sparse matrix, and I am interested in find k largest elements and their positions in the matrix. I do it in the following manner: ...
1
vote
1answer
174 views

What is the fastest way to make this table?

Context: As a possible approach to Goldbach's Conjecture, we create two lists of least/greatest prime factors of the odd numbers. The lists are A090368 lpf and A076565 gpf. We get symmetric ...
3
votes
1answer
44 views

Predict[] Application Timing

I trained a Predict and when I look at PredictorInformation it says evaluation time is less than 1 millisecond per example. ...
2
votes
1answer
27 views

Just typing Import[] tries to list folders in a directory, and it is slow over sshfs

It appears that Mathematica tries to list the folder that you're typing into an Import[] statement. Since I'm working with folders mounted over sshfs and they ...
1
vote
2answers
51 views

How to increase the speed on opening and playing gif?

I have a gif Example.gif, and would like to play it in a presentation. I used the following code:- ...
1
vote
0answers
23 views

Accelerate import of table of numbers

I've been writing a ServiceConnection to the OEIS and one thing I need to do is import large sequences of numbers, like this one. My first though for this was to ...
0
votes
1answer
59 views

Speeding up Module

I am working on the Ising 2D model in Mathematica and this is currently my Metropolis sampling function: ...
3
votes
1answer
109 views

Cosine similarity calculation

I am interested in calculating the cosine distance between each pair of the element of a sparse matrix. I am using the built-in function DistanceMatrix with the ...
0
votes
1answer
62 views

Errors using FindRoot on slow numerical function

I would like to find the solution of an equation containing a slow function FindRoot[func[x, onsideS, hoppingS, 0.01] - (1/E) == 0, {x, 1,10}] for different ...
3
votes
0answers
37 views

PackedArray version of Chop

I'm a big fan of Chop. It's fast and useful in pre-rounding transforms and things Unfortunately it also necessarily unpacks a real ...
2
votes
0answers
27 views

Compile with “Listable” only on one argument

I would like to write a Compiled function which is listable only in the first argument, because this allow fast and easy parallelization. How is it possible to do it? In the following way it does not ...
3
votes
1answer
56 views

How can Distribution fitting be sped up?

The first line generates 1050 data points to fit. The second line fits this data to the same distribution. This takes about 100ms on my computer. Doing this with ...
1
vote
1answer
20 views

How to make the sliding of the Manipulate with GeoListPlot smoother?

I am working on some animations of geographic entities. I have a Manipulate with GeoListPlot as below: ...
1
vote
1answer
23 views

How to control `PerformanceGoal` at `ListContourPlot`

I am using ListContourPlot to plot a list of points. I am using the PerformanceGoal option inside of ...
0
votes
0answers
128 views

how to speed up this function?

in this code cumavg1,cumstd1,giuper1,gilower1 are compiled. however, i dont know how to compile ei and fi to further speed up the calculation. any help will be appreciated. ...
1
vote
1answer
72 views

Optimization of a slow function - reason to why it is slow

Edit: Okay, my question was viewed quite a few times but not answered so I assume I phrased/presented in a confusing way. I'll try to rephrase my problem to make it more accessible because luckily I ...
4
votes
1answer
38 views

performance / computing time optimization for dealing with huge tables

I'm currently coding a Finite Element Method (FEM) program in Mathematica. For the so called stiffness matrix I need a very large table preferably around the size of 10^6 x 10^6 cells that are all ...
0
votes
1answer
73 views

Loss of 1 to 1 mapping due to duplicate in Association

The main goal of this procedure is to first rotate an array of 3D coordinate leaving z untouched,finding the positions of tuples with z larger than some value, and then mapping those positions to the ...
5
votes
1answer
70 views

Efficiently fill sparse matrix involving BSpline

Context In order to implement regularised fitting in 2 or 3 dimensions (as is done say here) using BSplineBasis one needs to evaluate a basis over a set of data. ...
1
vote
2answers
109 views

How can I make this code simpler, readable and more efficient?

I am running an iterative routine that I want to export to a file while each iteration is computed, instead of storing everything in memory and then exporting to a file. My solution is to write to ...
4
votes
1answer
65 views

Speeding up a WolframLanguageData query

I've seen suggestions that speed up WL code by 1000s - I may not understand them... I noticed the WolframLanguageData function the other day and thought it would ...
4
votes
3answers
62 views

Efficiency in array element replacement

Suppose I have two lists: ...
7
votes
1answer
112 views

Speed up the generation of large Hadamard matrices

I need to generate a Hadamard matrix with dimensions of 4096 but it seems Mathematica is much slower than Matlab when generating such matrices. This program ...
6
votes
2answers
1k views

Can this code be changed to run faster?

I've worked for several days trying to get this code to run faster. The imported data is 15MB. ...
5
votes
3answers
996 views

Incresing efficiency of the code:

I have a set of points, representing location of events in a map, and I want to find the closest neighbour for each point. Variable xys is a 2D matrix containing ...
1
vote
0answers
40 views

FindRoot on a large system of equations

I need to solve, numerically, a very large system of equations (Logit-type). The system has one parameter $d$ which is numerically defined in order to find the solution. My code works, but it ...
10
votes
1answer
111 views

Quick QuickSort implementation

I am playing with julialang and loving it, but at the same time noticed that they have a benchmark comparison with Mathematica. I have already submited a better version of ...
1
vote
0answers
45 views

How to get mathematica online to operate at a normal speed?

I have a nice notebook related to the world cup. It works great and fast enough on my desktop machine. However, when I try to run it using Mathematica Online, it is painfully slow to the point where ...