Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [performance-tuning]

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.

5
votes
1answer
525 views

How to plot the eigenvalues of a parametric matrix efficiently?

I was wondering how can I set the variable type of matrix elements to be real. The problem is, I creat a variable-dependent matrix as follows and I get the eigenvalues now I want to plot the ...
5
votes
1answer
1k views

Computing elements of a 1000 x 60 matrix exhausts RAM

I am trying to compute a 1000 x 60 matrix or list of lists (and ideally this should go up to 1000 x 500 or 1000 x 1000). Each element is the result of a FindRoot ...
8
votes
2answers
1k views

Why does a table with a defined constant in its index compute 10X slower?

I need to do some iterative summations. Here is a minimum working example: ...
1
vote
1answer
97 views

How to make these operations occur faster?

How can I get this section of the code to solve this integration faster. I have rather large values but I don't need it to be too specific. However if I lower the precision it says the integration is ...
0
votes
0answers
16 views

Any way to accelerate `SessionSubmit`?

I want to write my program in continuation-passing style, but it is too slow compared to the normal code pattern. The following expression took around 1 second to finish in 11.3. ...
2
votes
2answers
80 views

Finding extremes in discrete data by the fastest code

everybody! I'm new and that's my first post. I have such a problem: need to extract from a matrix (with dimensions n x 2) such points which have second coordinate smaller than -500 or higher than 500....
5
votes
1answer
128 views

Speed up selecting positive eigenvalues repeatedly

I have a smallish (e.g. 2x2 or 4x4, but ideally up to 10x10) non-symmetric square matrix $\mathbf{A}(x)$. I need to define a function $f(x)$ which is the sum of the eigenvalues with positive real part ...
8
votes
1answer
150 views

Most efficient method for export/import of non-traditional tensor-style dimensions of matrices/tables/lists-of-lists-of-lists(-of lists)?

Hello World! (I did it for my first answer, so it only feels proper...I'm not nostalgic, you are!) OKAY, here we go! Let's start off with the good-stuff, here's my code, made relatively arbitrary, ...
0
votes
0answers
25 views

What is the fastest way to get all the titles of emails in a folder?

I am using the function MailSearch[] to get the titles of all the relevant emails in one of my folders in Gmail. What I am currently doing works, but it takes a few ...
11
votes
1answer
664 views

Is there a faster way to calculate Abs[z]^2 numerically?

Here I'm not interested in accuracy (see 13614) but rather in raw speed. You'd think that for a complex machine-precision number z, calculating ...
1
vote
1answer
44 views

How to disable symbolic preprocessing in NMinimize without performance loss?

I want to find a global minimum of a function which is defined only numerically and cannot be evaluated with symbolic arguments. For example, this could be a minimum of a compiled function. ...
8
votes
1answer
644 views

Replacement of Do loops

Here is an example code (to calculate the so called structure factor, please see the comment below the question) for a small data set of 2d coordinates. In reality I have a factor of up to 100 times ...
3
votes
3answers
85 views

Efficient manipulation of Associations passed to functions, how-to? [duplicate]

I have some data wrapped into a MyData[data_Association] "structure". My Association contains some big arrays and I do not want ...
4
votes
3answers
785 views

How to speed up large double sums in a table?

I am calculating a 3-by-3 matrix whose elements are given as follows: $$ M_{mn} = \frac{1}{N}\sum_{i=1}^N \sum_{j=1}^N (r^i_m - r^j_m)(r^i_n - r^j_n) \tag{1} $$ where $N$ is the total number of ...
6
votes
0answers
237 views

Butter side up?

I've written a piece of code that determines if a piece toast with butter lands on the butter-side or not, depending on its initial velocity and the table height. If you are interested in the physics ...
3
votes
2answers
442 views

Speed up this NIntegrate

Is there any trick to speed up this numerical integral: ...
6
votes
0answers
46 views

Graphics Primitive Selector

Goal and motivation I want to build something that would intuitively work like: Graphics @ PaneSelector[{True -> something, False -> {}}, Dynamic @ show] ...
0
votes
0answers
73 views
2
votes
1answer
61 views

How to import only a small part from a large data file?

Let's assume that the data: are arranged in a table of $n$ rows by $m$ columns, are stored in a *.dat file or other textual format, number of rows is very large, say $n=10^7$. Suppose we need to ...
1
vote
1answer
80 views

Efficiently define a function as the numerical result of infinite sums

I want to approximate the solution to the following sum, in such a way that I can plot the function for the variable $\phi$, for a fixed value of $\mu$. \begin{equation} f(r(\phi), \mu)=4 e^{-\mu ...
1
vote
0answers
25 views

A newbie question about the use of the FourierSeries functions

Although I have had no previous experience with the Mathematica Fourier Series functions ( or package ), I am writing a tutorial on Fourier Analysis and Transformations in a Mathematica Notebook, ...
21
votes
1answer
214 views

Why is FreeQ so much faster for some specific variable names?

It seems that performance of FreeQ depends on the names of symbols which appear in its arguments. Here is an example of two large expressions which do not contain ...
2
votes
1answer
54 views

Efficient computation of matrices involving large sums of KroneckerDelta's

I was wondering if one could benefit from Mathematica's rich linear algebra methods for diagonalizing 2nd rank tensors. Namely, in the context of systems (fluids) comprised of capsule-like particles, ...
0
votes
1answer
29 views

Resultant running too slow

I have a system of equations all linear in one variable X with many parameters. I am trying to separate the variable in these equations by taking the pairwise resultants of one of the equation with ...
0
votes
0answers
40 views

Why is this iterative process with matrix calculation so slow?

I am trying something similar to the following code with Ntime as large as 100 or so. Now it's very slow as shown by the Ntime=3 ...
0
votes
0answers
74 views

How to speed up FindRoot?

How can I speed up my FindRoot time, for the below code? It takes 25 seconds on my machine to find one single root for a set of $g$, $mx$, $m\psi$ values, I need to ...
0
votes
1answer
58 views

Memoization (or otherwise) for a recurrent definition of a (double) sequence of functions

Beside I've found answers to similar questions (e.g. this), I can't adapt them to my case. I am interested in the following sequence of functions $p_{m,n}(t)$, where $m$ and $n$ are integer: $$ \...
43
votes
0answers
511 views

New Compiler Technology in V12

I am wondering whether the speed of compilation for the new compiler can be improved. Here are the results from my test. Consider the following function for generating a random draw from a gamma ...
1
vote
0answers
34 views

Speeding up solving many coupled non-linear differential equations

I am currently working on a project that involves solving many coupled non-linear ODEs$^*$ I am using NDSolveValue and the time it takes to solve everything is (understandably) slow. But I was ...
2
votes
1answer
62 views

How to speed up summations with many list callings?

I am trying something similar to the following code with NN as large as a few hundred (at least 100). Now it's very slow and most time is spent on calculating the ...
6
votes
1answer
1k views

What computer would be fastest for Mathematica Home Edition?

I am planning the purchase of a new computer for use with Mathematica Home Edition, which is limited, as far as I understand, to two simultaneous kernels. Can anyone recommend particular hardware?
9
votes
2answers
214 views

Finding the path in a graph from A to B then back to A with a minimum of shared edges

the problem is to find cycle from A to B back to A, so that the path B-A would use minimum edges from path A-B. The graph is undirected and can have cycles. The paths don't have to be shortest, they ...
0
votes
0answers
31 views

Reading a chunk of data from a stream using Parallelization

I am trying to read a stream and perform some operations in parallel. Here is the logic of the code inside the ParallelDo: 1- Open stream 2- Read chunk of data 3- Close stream 4- Process the data ...
1
vote
0answers
67 views

Memory leak in simple program

I am trying to solve a simple optimization problem on the sphere, and for some reason, I got some memory leak that I am not able to solve. To decompose the problem in step, what I wan to do is Take ...
4
votes
1answer
557 views

Limit the amount of RAM Mathematica may access?

Trying to solve a differential equation numerically, I noticed that Mathematica used up all RAM to the extent that my operating system (Windows 10) lost responsiveness and hung up. As a result I had ...
3
votes
2answers
91 views

Efficiently find all values of parameter such that any of the eigenvalues of a matrix is equal to 1

I wish to find all values for a parameter such that my matrix has an eigenvalue of 1. Here is an example 16-by-16 matrix with elements depending on the parameter x ...
5
votes
0answers
98 views

Optimize Use of PeakDetect in Mathematica

I am quite new to Mathematica and I am looking for some advice in order to improve and optimize my code. Here is what I am trying to do: Open a stream Read the stream line by line and store it in "...
0
votes
0answers
44 views

How can I speed up my code finding the parameter which yields zero determinant for increasingly larger matrices?

I build a square matrix with matrix elements dependent on the parameter x. I need to find all values of x within a reasonable ...
1
vote
0answers
61 views

Fourier transform calculation never stops [closed]

I'm trying to calculate a Fourier transform and plot it, however the calculation is running for several hours now. I suspect that there is a mistake in my script. Or am I just not patient enough? Is ...
-1
votes
1answer
51 views

Plot of complicated expression takes very long time

I have some long expressions that I got from multiplication and addition of matrices and vectors of order 4: ...
3
votes
1answer
59 views

How to improve the rendering time of a plot

The following is a link my original question: I need List Plot points to have different color based on amount of neighbours? The question was answered, and I used the first answer with ...
12
votes
1answer
377 views

ls Ordering[Ordering[list]] optimal?

Given a list list with unique elements, the task is to replace each element by its position in Sort[list]. For example, ...
2
votes
1answer
95 views

Why won't nominally compilable function compile? (err Compile::cpintlt)

Context: I have millisecond timestamped sample data that I want to convert to a uniformly sampled series. This I do by padding each interval with repeated values (pbp ~ 'pad by position'}. The ...
8
votes
1answer
428 views

Ways to speed up user implemented RK4

So, I've implemented RK4, and I'm wondering what I can do to make it more efficient? What I've got so far is below. I wish to still record all steps. I think ...
2
votes
0answers
37 views

GeoRegionalValuePlot optimization

I have the following piece of code that plots a colormap by zipcode. Zips is an array of zip codes (All in the US mainland) and testscore is just some made up data for testing purposes. The list of ...
0
votes
1answer
40 views

DeleteDuplicates in FindRoot with more than one variable

I'm solving a system of 3 non-linear equations with FindRoot for the variables x, y and <...
12
votes
2answers
325 views

Terse Method to Swap Lowest for Highest?

I have built a solution to swap the lowest values with the highest values in a list. With ...
7
votes
2answers
317 views

How to diminish computation time when nonlinearity appears in 2D heat conduction equation?

I am trying to simulate heating and melting of the steel plate by means of FEM.The model is based on nonlinear heat conduction equation in axial symmetry case. The problem statement is the next: $$ \...
4
votes
2answers
63 views

Element-wise multiplication of matrices with different dimension

I am interested in efficient element-wise multiplication of matrices with different dimension. Here is my solution: Matrix 1 with dim = {3, 4, 4} ...