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
1
vote
0answers
53 views

Is there a better way to build a matrix with position coordinates conditions?

Suppose that I have a list of coordinates {x,y} following some geometry in space, for example ...
0
votes
0answers
32 views

My Differential evolution algorithm does not minimise

So far I have implemented the Differential evolution but my output does not show me any minimization is it possible to solve it ...
0
votes
1answer
50 views

Faster PowersRepresentation using IntegerPartitions

Earlier I posted a question about taking fast integer square roots of known integer perfect squares. The reason this came up is I was trying to find a faster way of mimicking the PowersRepresentations[...
2
votes
1answer
243 views

Fast Integer Square Roots of known perfect squares?

A bit of a generic question perhaps - say I have a list of non-negative integers and I know each are perfect squares - what is a fast way of finding their square roots? I have very long lists (...
1
vote
3answers
91 views

Optimizing operations between vectors

Basically I am generating a grid in space (so a vector where v[[1]]=position 1 in x) and a random number of particles in space (so a vector where p[[1]]= position of particle 1 on space). Afterwards, ...
6
votes
2answers
188 views

Fastest way to create multiple lists in a do loop

I do not think my explicit code will be helpful to illustrate it so here is the "barebones" silly example: ...
1
vote
0answers
60 views

Dividing list into smaller list using a set of rules?

Suppose we have the list for $n\in\mathbb{N}$ Range[1,n] We choose the number in the list where $x=1$, $x=n$ and $x=1+(n-1)/2$ round closest to and the numbers ...
3
votes
0answers
105 views
+50

Speeding up Fourier transform and eigenvector calculation

I have a matrix $M$ in Bloch basis (momentum space). Then I have to take Fourier transform of $M$ to go to real space. The size of this lattice in real space can be fixed to some value $N_{unit}$. ...
4
votes
4answers
64 views

How to create a function that merges the first $n$-digits of each value in a list?

Suppose we have a list of numbers. For example, A={1231,1232,1233,1241,1236} Using a function f[x,A], I want to rearrange this ...
-1
votes
0answers
39 views

A general question about speed of working with interpolating functions

Consider a grid {x,y,z,f(x,y,z)} Here, x,y,z are real numbers, and f is a function that first monotonically increases with its argument $z$, and then quickly ...
11
votes
2answers
405 views

NIntegrate: the order of singular points matters!

Consider the following integral: $$I = \int_{-5}^5 \frac{1}{(x(x-2))^{1/3}} dx.$$ The exact value is 6.30249 - 2.2405 I. I will perform ...
11
votes
3answers
165 views

Faster searching for subsets with pairwise conditions

I am looking for a faster way of finding large subsets of lists that obey pairwise conditions. In particular, I'm looking for a large (over 10k) set of quaternary words (i.e. ordered lists) of length ...
1
vote
1answer
34 views

NIntegrate With Singularity: Experiment With Various Parameters

I want to numerically evaluate the integral $$I = \int_{\mathbb R^2} dxdy f^*(x) f(y) K(x-y)dxdy,$$ where $$f(x) = \sqrt{\frac 2 \pi} e^{ikx} e^{-x^2}, \quad k\in\mathbb R$$ is an exponentially ...
0
votes
1answer
69 views

How to analyse the performance of Mathematica on this function?

Using f[n_] := Sum[1/(Sqrt[k] + Sqrt[k + 1]), {k, 1, n}] to analyze the well-know series... I noticed a sudden performance drop (on my outdated PC hardware ) ...
1
vote
1answer
41 views

Strange behavior of NIntegrate: small change of integration range give tremendous running time difference!

I have an integrand: integrand = E^((6*I)*x - x^2 - (6*I)*y - y^2)/(2 Pi (-I (I/100 + x - y))^(1/3)) This function decays as $\sim e^{-x^2-y^2}$ for $x,y \to \...
1
vote
1answer
45 views

Why each iteration takes longer than previous one when using VariationalD in this loop?

I have a function $f$, and I would like to modify it iteratively to approach another one called $a$ (not because I think this is the best way to do anything, but for experimentation). For this, I use <...
0
votes
0answers
43 views

Alternative for PowerRepresentations[n, x, 1]

I am looking for numbers $n$ that can be written as the sum of other numbers. So: PowersRepresentations[n, x, 1]. But is there a faster way of finding these numbers?...
1
vote
1answer
123 views

Explicit integration of PDE running very slowly

I would like to solve the PDE $\frac{\partial u}{\partial t}=(1-x)\frac{\partial u}{\partial x}$, in the interval $[0,1]$, with initial condition $u(0,x)=e^{-218(\frac{-2}{3}-ln(1-x))^2}$, by manually ...
3
votes
0answers
83 views

Solving or Minimizing the Norm of the matrix equation $M^TAM - M^TB - B^TM =C$

I am trying to solve the matrix equation $M^TAM - M^TB - B^TM=C$ where I know A, B and C. My unknown matrix is M which has the special form that all the rows and columns sum to zero. i.e. I have four ...
5
votes
2answers
145 views

ListDensityPlot with RegionFunction takes too long?

I am using ListDensityPlot with RegionFunction (MMA12.3 on Win 64) but it takes too long ...
0
votes
2answers
88 views

How can I exclude specific region in ListDensityPlot

I would like to exclude the region outside the yellow Polygon in this plot, how can I do that? ...
4
votes
1answer
147 views

How can I speed up processing with DeleteCases?

I would like to get points that are only inside a region. Here are the region and unfiltered points: ...
5
votes
2answers
129 views

How to guide Eliminate or GroebnerBasis to reduce a set of simple odes to a single ode (which can be done by Laplace Transform)

Recently, I am trying to use Eliminate or GroebnerBasis to simplify a system of ODEs. I don't want the solution of ODEs. What I ...
7
votes
1answer
128 views

Pick with Unitize vs Pick with Clip vs Compiled Select speed - anything faster?

Given a large list of $n$ dimensional sublists where each sublist has integer elements I am trying to find the quickest way of finding all sublists that satisfy some constraint on their elements. A ...
4
votes
1answer
59 views

How to accelerate numerial inverse laplace transform for pdes of Euler-Bernoulli beam problem

Happy new year! :) Recently, I am practicing laplace transform technique for solving pdes. In this extemely helpful post, @xzczd mentioned that "The last step is to transform the solution back, ...
0
votes
1answer
67 views

Trying to speed up finding solutions of quadratic form related to the weight of a matrix

Say I have an integer matrix of size $5 \times 5$ - I am trying to find the solutions to the equation $n^4 wtM = n w^2 + x1^2 + x2^2 +x3^2 +x4^2 + x5^2$ subject to the constraints $x1+x2+x3+x4+x5 = 0$ ...
27
votes
8answers
1k views

Speed up Do loops in MMA 13.0

How to speed up Do loop in MMA 13. We consider the following Benchmark test (4 kernels, i7, win10): In MMA 13: ...
0
votes
0answers
39 views
2
votes
0answers
90 views

Finding the sum of the product of factorials of the digits of numbers

I want to calculate the sum of the product of factorials of the digits of numbers. So for example, when $n=467$ I get: $$n=467\space\to\space\left(4!\right)\cdot\left(6!\right)\cdot\left(7!\right)=...
-3
votes
1answer
92 views

How to find the distances to all buildings quickly?

I would like to create an association by mapping the function GeoDistance[Here,#]& over all buildings without missing locations in a reasonable amount of time less than 30 minutes. I have the ...
13
votes
0answers
226 views

3D stable fluids algorithm to simulate transition from laminar to turbulent flow

This algorithm is 3D extension of our 2D algorithm published on this page and here. We suppose that with this code we can simulate transition from laminar to turbulent flow. In this example we compute ...
5
votes
2answers
242 views

Optimizing sequential computation

The following question came up in reading group discussion of paper -- imagine taking two vectors, multiplying each by a random matrix, then taking tanh pointwise. If you repeat this process forever, ...
0
votes
0answers
52 views

How to speedup the following evaluation?

Consider the following function: ...
4
votes
0answers
50 views

A WolframKernel (with PID) is created by a LocalSubmit. After the LocalSubmit finishes its job, the kernel remains. How to kill it within Mathematica?

When defining a task with LocalSubmit, a new subkernel is created. When you remove the task after the task is done, the task is removed but the subkernel remains ...
2
votes
2answers
77 views

Speeding up ComplexExpand

I have a code where I have to take the dot product of two lists, that contain some symbols, and then use ComplexExpand. For a long list it take a very long time and ...
3
votes
4answers
125 views

How more effectively solve problems with "FindInstance" when number of variables is significantly greater then number of equations

Can you help me with solving the following problem: There are 16 variables and 3 equations (constraints) on them; is it possible to effectively solve such problems in Mathematica? What is more, there ...
7
votes
4answers
296 views

How to join two tables column-wise simply and quickly?

Consider the following tables: ival = 10^6; Tab1 = Table[{x, y}, {x, 1, ival, 1}, {y, 1, 6, 1}]; Tab2 = Table[{x, y1}, {x, 1, ival, 1}, {y1, 7, 8, 1}]; The values ...
9
votes
2answers
344 views

How to parallelize and speedup AppendTo? [duplicate]

Say I have a list of original data (for now generating random list as follows): ...
1
vote
0answers
57 views

DSolve for large nearly sparse matrix

The following code creates a system of first order linear homogeneous differential equations and attempts to solve them. The time needed scales as the 4th power of the matrix size. Is there an ...
10
votes
2answers
189 views

How to compile matrix product?

Consider the following matrices: ...
1
vote
0answers
66 views

How to compile the following evaluation?

I have the following question. I want to generate three vectors p1Unrotated,p2Unrotated,p3Unrotated at some reference frame, then rotate them by some random angles $...
1
vote
1answer
74 views

Parallel Mathematica-code that runs too slow when running PowerRepresentations[] function

Well, I am a student in elementary number theory and trying to find natural numbers that can be written as the sum of integers to the power of an integer. The code I am using now is the following: <...
1
vote
1answer
72 views

I need to speed up this summation

I tried solving this problem on my own but I cant find a proper solution. I need to evaluate the following equation: $\sum\limits_{m=1\\m\neq i}^n{\left(\dfrac{v_m~(\lambda_i\cdot B-A)~u_i}{(\lambda_m-...
2
votes
0answers
58 views

use of small functions

I was wondering if it will slow down my code if I have a bunch of small functions like isNewRound[currentMove_] := Return[Mod[currentMove, 4] == 0]; which are ...
8
votes
1answer
268 views

How to compute RandomReal faster?

I have variables $E_{1},E_{3}$ that are bounded in the following way: $$ \tag 1 E_{1}>m_{1}, \quad E_{3}>m_{3}, E_{2}\equiv m-E_{1}-E_{3}>m_{2}, \\ -1 < \frac{E_{2}^{2}-m_{2}^{2}-(E_{1}^{2}...
6
votes
1answer
199 views

Producing a random Wang Tile tiling image more efficiently

I'm following along with this SIGGRAPH 2006 paper Recursive Wang Tiles for Real-Time Blue Noise - there's a video here too. Eventually I want to try to produce the blue noise results in the paper, and ...
0
votes
0answers
79 views

Import website "Source" slows down after a few iterations

I am using Import[link, "Source"] to import the source of several hundreds of thousands of webpages in a while loop to process them. Each iteration has ...
2
votes
2answers
252 views

Optimization for numerical integration of Airy function and using NIntegrate inside NDSolve

Sorry for the long post. I need to integrate a function which uses the trajectory data given by the Lorentz force equation. We have the electromagnetic field: $$ \vec{E}=E_0 \cos{\omega(t+\bar{z})}\...
3
votes
3answers
237 views

Solving for a unique set of solutions

I have the following code: ...

1
2 3 4 5
52