Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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.

Filter by
Sorted by
Tagged with
0
votes
0answers
23 views

How to speed up this code(Jordan Normal Form)

I want to calculate the number of unrepeated Jordan canonical forms of n * n matrices consisting of 0 and 1 How to speed up this code ...
2
votes
1answer
42 views

Rewriting a large product of 42 (13x13) matrices with MatrixExp

I am trying to perform a product of a large number of terms of the form MaxtrixExp[...], for example, something like this ...
4
votes
2answers
391 views

Speeding up sums involving 16x16 matrices and 16x16x16x16 antisymmetric tensor

I need to perform the following contraction involving four 16x16 matrices and a tensor $\theta$ that is 16x16x16x16. ...
2
votes
0answers
32 views

Speeding up Integration over Implicit Region

Similar to my previous question, running ...
5
votes
2answers
66 views

Efficient way of averaging over elements of one matrix based on another

Mathematical formulation of the problem with an example: Suppose we have the matrix $A$ given by $$A=\begin{pmatrix} 0 & 1 & 5\\ 1 & 0 & 5\\ 5 & 5 & 0 \end{pmatrix},$$...
1
vote
1answer
49 views

Hermite normal form and basis for the nullspace

Define the Hermite Normal form $H$ for a matrix $A\in Z^{n\times n}$ as following: $$H=UA$$ which in Mathematica is given as {u, h} = HermiteDecomposition[a] Then for a system of homogeneous ...
1
vote
0answers
40 views

Sampling pairs of nodes with given distance between them

For the purposes of this question we assume undirected and connected graphs. I am trying to learn how to efficiently find pairs of nodes in a graph that are separated by prescribed distance $d.$ One ...
7
votes
1answer
348 views

Speed up animation

For a project I need to make a little animation showing what happens when you put two hexagonal lattices on top of each other and rotate one of them(Moiré pattern), and my advisor sugested using ...
1
vote
1answer
95 views

How can I simplify my geometric calculation?

Here is a math problem I am dealing with right now: Given ellipse $C$: $x^2/a^2 + y^2/b^2=1$ ($a>b>0$). Ellipse $C$ passes through the point $P$: $(1,3/2)$, and has eccentricity $e=1/2$. ...
2
votes
1answer
69 views

Fastest way to compute determinants over (lists of) machine precision numbers

The below code is a code snippet of a larger project of mine. The project is mostly optimised but this part is not. I'm struggling to improve it, the code takes a really long time to evaluate for what ...
0
votes
0answers
30 views

Mathematica UI slow on Surface Go

Anyone else using Mathematica 12 on a Surface Go? On my Go 8GB/128GB, Mathematica responds slowly to typing, scrolling through notebooks, and rotating 3D graphics. Wolfram support had me disable ...
1
vote
0answers
25 views

any way to study the number of CPU cycles used for a computation?

I do speed comparisons for various functions and algorithms, and ultimately, the speed of some section of program code depends on the number of CPU cycles. This can vary wildly across operating ...
0
votes
0answers
34 views

Is there a feasible computation?

I have to find the values of $p_1$ and $p_2$ which minimizes the expression $G$. However, when I took the partial differentiation of $G$ with respect to $p_1$ and $p_2$, the equations I obtained were ...
0
votes
0answers
52 views

Speed up Computation on Mac Pro

I recently got the opportunity to switch my licence from a macbook laptop to a Mac Pro. Although being very ignorant on the topic, I know that the Mac Pro should perform computations much faster than ...
3
votes
1answer
78 views

Efficiently computing current flow betweenness centrality for graphs

Definitions: Given a graph $G=(V,E),$ the current flow betweenness is a node-wise measure that captures the fraction of current through a given node with a unit source (s) sink (t) supply $b_{st}$ (1 ...
1
vote
2answers
52 views

Speeding up exact evaluation of an integral with non-constant limits?

I am working on a problem that has as part of its result an integral of the form $\text{Integrate}\left[c,\left\{x_1,0,m_1\right\},\left\{x_2,x_1,m_2\right\},\text{...},\left\{x_n,x_{n-1},m_n\right\...
2
votes
1answer
57 views

Tuples with more criteria

I have seen that there is question here which does almost what I wanted to ask but it's not quite what I wanted. Efficiently generating tuples with Outer What I would like to have is a Tuples of a ...
7
votes
3answers
244 views

Faster way to solve android lock valid patterns

With the password grid shown in the Android home screen, how many valid passwords are possible? The rules for creating a pattern is as follows. We must use four nodes or more to make a pattern at ...
0
votes
1answer
67 views

Generalization of code is slower than particular case

I wrote the following Mathematica module: ...
1
vote
1answer
83 views

Correct use of Reap/Sow to optimize the code

I am trying to compare two functions on the end points of an interval. For instance, $f_1(t)=t^3$ and $f_2(t)=t^4$. From my code below I check whether $f_1(t)\leq f_2(t)$ when $t=50$ on $[50, 51]$ ...
10
votes
1answer
291 views

Numerically solving a system of many coupled non-linear ODEs efficiently?

I'm studying a fairly typical problem: a chain of $n$ coupled, non-linear oscillators. Since I want to look at open boundary conditions, the equations of motion for the position of the first and the ...
3
votes
2answers
82 views

Replace the diagonal of a list of matrices

I want to replace the diagonal of a square list of matrices with another list of matrices. What is the fastest and most efficient way to do so. (I will need to do this for very large arrays) Small ...
7
votes
2answers
200 views

Fastest way to update rows of an array of SparseArrays

I have an array of sparse arrays (check update 3 below for a concrete example that has the same qualitative features as what I use in my real code) , say ...
1
vote
2answers
55 views

Delete pre-existing output under EvaluationCell[] from CellProlog

We know that there is an efficient way to delete all output from the EvaluationNotebook[]: ...
2
votes
0answers
42 views

Speeding up the process of NDSolve[] when a user-defined function is involved?

I am trying to tackle a (1+4 dimensional PDE) model at which the solution of the first PDE (with some interpolations and changing the domain) would be used in the second PDE. In fact, I must choose ...
45
votes
2answers
5k views

Is there any algorithm that runs faster in Mathematica than in C or Fortran?

I'm just curious. My friend just told me that Mathematica is mostly for symbolic calculation and not efficient for Numerical computations. He told me that's the reason most of the people don't use ...
3
votes
2answers
291 views

How can I better manage memory usage when defining functions?

Suppose I have defined a numerical function F[x] that for each entry x, it takes a long time to calculate. Suppose that now I ...
0
votes
0answers
43 views

Evaluation control inside Compile

I have the following function ...
4
votes
2answers
317 views

Siginificant speed difference of Integrate between 9.0 and 12.0

I just upgraded from 9.0 to 12.0, and I found some strange difference in timings for the following expressions: a. Integrate[Exp[-a*x^8],{x,-Infinity,Infinity}] b....
0
votes
0answers
47 views

Derivative operator w.r.t a vector index and change of variables

Description and code lines: Define a scalar product to represent $A_i·A_j$ , $A_i ·B_j$ and $B_i ·B_j$, such that $A_i · A_i$ = 0. This is implemented in the following way: ...
5
votes
1answer
62 views
7
votes
6answers
579 views

How do I count the number of elements in a list which are between two determined values?

I have a long list (apprx. 10000 elements) of numbers. I want to count the number of elements between two determined vallues a and ...
4
votes
1answer
67 views

Reduce memory cost with three matrices multiplication

My program is eating up all my RAM and the operation is related to 3 matrices multiplication, as the code shown below. example code: ...
1
vote
0answers
48 views

Performance Optimizing ParametricFunction

Setting up the system: ...
6
votes
1answer
141 views

How can I accelerate repeated interpolation of a very large dataset?

I am solving a 4D time-dependent PDE using a discretization method. My query is not about solving this; because I am doing it in the following code. The code is OK and it works fine. My main problem ...
4
votes
1answer
89 views

Efficiently calculating matrix exponential of a recursively generated matrix

Given a matrix $A$ of size $N \times N$, I want to evaluate the function \begin{equation} F(t) = |Tr(\exp^{-i A t})|^2 \end{equation} as a function of $t$. Here, $A[n]$ is constructed recursively ...
1
vote
0answers
45 views

Script aborts when I try to build a very large list

I am running the code below ...
1
vote
0answers
47 views
+200

Speeding my code and correctly calculating a density which uses Folner Sequences?

I created a code which calculates $$D(S\cap[a,b])=\lim_{n\to\infty}\frac{\left|S\cap{F_n\cap[a,b]}\right|}{\left|F_n\cap[a,b]\right|}$$ where $D$ is the density of $S\cap[a,b]$ (in $A\cap[a,b]$), $[...
1
vote
2answers
206 views

Approximating the density of $S\cap[a,b]$ using a Folner Sequence of $A$, where $S \subseteq A$?

Edit: I redid my code but it's still not working. How do we use Mathematica to approximate $$D(S\cap[a,b])=\lim_{n\to\infty}\frac{\left|S\cap{F_n\cap[a,b]}\right|}{\left|F_n\cap[a,b]\right|}$$ ...
1
vote
1answer
124 views

Help speeding up solution of system of differential equations using Laplace transform

I'm trying to speed up this code that seems to take forever to evaluate. I'm solving a system of 9 coupled differential equations using a Laplace transform (a version of this code that works perfectly ...
0
votes
0answers
60 views

Reduce taking long time on six equations

I have a system of equations, 4 linear and 2 quadratic, of the following form: $$L_{i,j}(x_1, \cdots, x_{12}) = \sum_{k=1}^{12} x_k c_{k,i,j}$$ for $i, j = 1, 2$, i.e. the $L_{i,j}$ are the ...
5
votes
3answers
217 views

Number of list elements less than a given integer

I'm trying to make a function whose input is a list, and that outputs a list for which the nth element is the number of elements in the input less than n. So far, I have ...
6
votes
4answers
644 views

MaxDetect speed

What's the fastest way to find the local maxima of a 2D list? E.g. ...
1
vote
0answers
36 views

Can LearnDistribution Train and Generate Images Without Defaulting To 256x256?

In spite of anything I try it seems the ConformImages[] function nested in the LearnDistribution[] function resizes images to 256x256. If I convert an image into its "Data" representation before ...
2
votes
1answer
43 views

Efficient Linear Operators on SparseArrays

I have a rank four SparseArray of dimension {40, 40, 40, 40}. I wish to apply a linear operator to it, whose form I know abstractly. That is, I have a simple closed form for the action of the operator ...
5
votes
2answers
123 views

Building Truncatable Primes using Nest(List), While, Fold

Here is a video on Truncatable Primes. I tried to build it myself. Here is what I have tried using the method in the video for left Truncatable Primes. ...
2
votes
2answers
86 views

Optimising Table iteration

I've asked a question here which was resolved by tweaking my code a little. So I shall reiterate, for the following list, ...
8
votes
1answer
302 views

Optimization of the following code

Consider the function $$ h:[-1,1]\times I_{\sigma}\to I_{\sigma} $$ $$ (\omega, x)\mapsto \sqrt[3]{x + \sigma \omega} $$ where $ \sigma > \frac{2}{3\sqrt{3}}, I_{\sigma} = [x_-(\sigma), x_+(\sigma)]...
1
vote
1answer
78 views

Speed of Manipulate with Plot3D & ParametricPlot3D [closed]

I am trying to generate a 3d animation showing two ripples interfering at a point which can be chosen. In my 3d modelling, I want to show the cross-section of the ripple towards that point. I wrote ...
1
vote
1answer
67 views

What is the most efficient way to use the fitted models?

I'm generating a simple linear model ($y=mx+b$) by fitting to the background of some data, and then trying to plug in the x-values of the data I'm actually interested in. I'm a bit surprised that <...