We changed our privacy policy. Read more.

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
4
votes
1answer
130 views

Determining Mean Path Length

I'm interested in working out the average path length in a square. Assume at a single point within the square, photons are released in every direction. I'm interested in determining the average path ...
1
vote
3answers
117 views

How can I more quickly get the interchangeable variables in a function?

Let's say I have an expression like a b + c d e. This is equal to: a b + c d e, a b + c e d, ...
0
votes
1answer
60 views
0
votes
1answer
61 views

Efficient way of iterating over satisfiability instances

I am working on a problem that involves searching through solutions to a boolean equation, to see if any have a specific property. As the computations are not particularly fast, I would like to ...
3
votes
2answers
265 views

Optimize molecule distance analyzing code

I have a very large dataset (31552000 lines) of xyz coordinates in the following format 1 2 3 4 5 6 7 8 9 . . . I have to take a distance using the special ...
2
votes
1answer
200 views

How to increase the speed of Collocation method to solve System of differential equations

all. Kindly suggest me a ways to improve the speed of computations. I recently came to know about collocation methods and their application to find solution for system of differential equations. Here ...
4
votes
1answer
46 views

Why is extracting values from an Association with 1 level slower than extracting values from a list of depth 1?

I am not looking for a solution or work-around, but an explanation. Here are six examples of doing a trivial operation on an association and a list. Initially, I was curious about the cost of calling ...
3
votes
0answers
76 views

Module inside With, With inside Module, or Just Module?

In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume ...
3
votes
0answers
98 views

Sowing Once into Each of Many Lists – Any Better than Append?

In general I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
3
votes
0answers
64 views

What's the time / space complexity of pattern matching?

For example, in ReplaceAll[expression, pattern], what are the main algorithms used internally? How does the asymptotic time / space complexity scale with the length ...
0
votes
0answers
29 views

Keep Mathematica kernel for a script alive without having to initialize every time (Windows 10 .bat file)

I have a Mathematica script (ChristMetric.wls) that is plugged in to a python code which exports a list of geometrical data in .txt file. I plugged the script into the python by making a .bat file in ...
2
votes
0answers
54 views

How to find the regions for which the derivative of my function changes sign?

I have an energy function of the angles of the electrons' spins. th1 is vector with (2l+2) elements and each element represents the angle of an individual electron spin. I need to eventually find the ...
1
vote
0answers
70 views

What is the best optimization method for the following function?

I have calculated the energy of the electrons as a function of their angles. and I want to find the angles for which my function (energy) is minimized. I have used NMinimize, but the angles I get from ...
3
votes
1answer
76 views

Speeding a function that given a matrix, returns a close by Positive Definite Matrix

I'm dealing with several matrices, that due to machine-precision considerations, they are supposed to be symmetric Positive definite (SPD), but aren't. From matrix $X$, we proceed as: Find $Y=\frac12 ...
0
votes
1answer
84 views

What has DiscreteAsymptotic been thinking about for so long?

The command of 12.2 (This code is related to that question.) ...
2
votes
0answers
55 views

Speeding up this function?

Is there a way to speed this function? ...
1
vote
1answer
54 views

Speeding up Table of a Table

Here's my code: ...
3
votes
1answer
133 views

How can I plot (and compare) the efficiency in executing 2 functions?

I have two functions as follows, ...
3
votes
3answers
263 views

Finding all Latin Squares of order 5

A Latin Square is a square of size n × n containing numbers 1 to n inclusive. Each number occurs once in each row and column. An example of a 3 × 3 Latin Square is: $$ \left( \begin{array}{ccc} 1 &...
14
votes
1answer
274 views

Stable fluids code for electromagnetic mixture application

This code has been translated from the original Jos Stam code and improved with some Mathematica functions. It solves problem of viscous incompressible flow with electromagnetic force in a rectangle ...
0
votes
1answer
80 views

Differences in Mathematica's behaviour with identical functions

I have three functions whose identity was verified, but WM doesn't behave itself equally with them. The code is: ...
0
votes
1answer
129 views

_?NumericQ inside NDSolve to speed up code

I've seen some people using _?NumericQ to prevent symbolic calculation and speed up NDSolve. Why in this simple code is not ...
1
vote
1answer
82 views

How to speed up (or parallelize) NDSolve?

Is there a way to speed up the following code: ...
1
vote
1answer
85 views

Is Parts faster than Apply?

Consider a function that accepts a coordinate f[x,y,z]. Our aim is to apply this function to a list of coordinates, at scale, as fast as possible. Here are the ...
1
vote
1answer
113 views

Why is ComplexPlot So Slow?

I'm plotting the spherical harmonics on $\phi\in(-\pi,+\pi)$ and $x=\cos\theta\in(-1,+1)$, ...
1
vote
1answer
65 views

NDSolve needs multiple executions to work and is very slow

I just simulate a system and use an Extended Kalman Filter to estimate the state. Everything works, but I don't understand why I need to execute the Ndsolve command two times before it can run without ...
0
votes
1answer
65 views

Code Blocks versus Module when refactoring code

As I get more familiar JavaScript & Typescript, I noticed the need in my Wolfram code to continually pass big arrays into my functions. I guess this leads me to two questions I haven't been able ...
1
vote
0answers
53 views

Parallelizing construction of sparsearray

I'm constructing sparse arrays where blocks of each array are results of the integral defined in integralList ...
5
votes
0answers
117 views

NestList in 12.1/12.2 is 10x slower than 11.3/12.0

Are there any configurations to fix it? Test code: ...
0
votes
2answers
109 views

Quick way to numerically cancel exponentials

I have a problem with exponentials and the use of the commands N and Collect. I am trying to write a code that generates a very ...
1
vote
0answers
40 views

Determine if intersection of Polygon and HalfLine is non-empty

I have a concrete example: ...
1
vote
2answers
104 views

Improving large array manipulation

I am doing an iterative program, which uses large arrays/vectors and where the output of one round is used as an input for the next steps but works slowly when dimensions are bigger. In brief, we ...
0
votes
0answers
51 views

Force WhenEvent and NDSolve to numerical evaluation and Best Practice

I'm trying to perform an hybrid kalman filter for a nonlinear system. The following code works but it is very slow due to the fact that it does symbolic evaluation. What I wish is that for the filter ...
1
vote
1answer
105 views

NSolve V12.1.1 much slower than V6.0 for the same polynomial system [closed]

We are solving polynomial systems with real coefficients using NSolve. A typical system is attached below. The problem we have is that Mathematica V12.1.1 solves it 17 times slower than V6.0, see the ...
1
vote
0answers
76 views

Symbolic add of 32Bit Registers

I would like to perform multiple 32bit word register additions (mod 32 add. with variables of Boolean type shuffled with symbolic type). For this task I implemented a ripple adder function: ...
18
votes
2answers
1k views

How do the functions Reap and Sow actually work behind the scenes?

I have read that using Reap and Sow to generate a list of unknown length is much more efficient than using AppendTo over and over. I believe AppendTo works by creating a new list that is one element ...
1
vote
0answers
25 views

Fastest way to do repeated subsample/Intersection calls over large set of vectors

In this answer I found I needed to calculate a bunch of intersections of subsets of vectors, like ...
0
votes
0answers
44 views

sparse matrix multiplication

Say I have a sparse matrix $M$ with $\sim 50.000 .000$ non zero elements. What is the fastest way to make operations such as : $$M^k X$$ where $X$ is a given vector. Is the operation $MX$ ...
3
votes
2answers
83 views

Avoiding duplicates after integer insertions

This is related to Splitting balls over sized bins but a simplified subproblem I've got a list of lists of numbers, e.g. ...
2
votes
1answer
87 views

Splitting balls over sized bins

This is strongly related to Splitting a set of integers over a set of bins, but a much simpler case. If we have $N$ indistinguishable balls and $k$ arbitrarily large distinguishable bins, we know the ...
1
vote
2answers
61 views

WhenEvent inside Ndsolve how to evaluate actions numerically every time the event happens

I need to force a whenevent action to be evaluated numerically all the times the event happens. The fact is that I use very complicated matrices and I need to invert them so the system requires a lot ...
1
vote
1answer
60 views

How to flatten the given table?

Consider a table Table1 = Flatten[Table[{x, y, {f1[x,y],f2[x,y],f3[x,y]}}, {x, 1, 2, 0.001}, {y, 2, 3, 0.001}],{1,2}]; Could you please tell me whether it is ...
1
vote
0answers
39 views

How to speedup RegionIntersection?

Consider a circle circle located at the origin of a coordinate frame and with a radius ROffAxisArb (it is parametrized by two ...
3
votes
1answer
51 views

Significant slowdown in a generalised implementation

Consider the following code: ...
0
votes
0answers
45 views

How to resolve these errors that pop up when using 'Compile' for a large function? [duplicate]

The problem I have been wanting to make my code which solves an optimisation problem faster. This led to this question on here and I realised from there that the root of the problem is the very slow <...
1
vote
1answer
57 views

Using With[] vs. Using a Pure Function for Constants

There are many cases where I am conflicted over using With[] versus using pure functions when dealing with constants, knowing the output is the same either way. For ...
3
votes
4answers
194 views

Code to solve quadratically constrained quadratic optimisation problem using FindMinimum is very slow. How do I make it faster?

The problem I have a quadratically constrained quadratic optimisation problem (QCQP) which takes about 13 seconds to find the optimal solution. I want to iteratively optimise a large number of times (...
0
votes
0answers
69 views

How to make the following table compiled?

This is the continuation of the two previous questions 1, 2. The task In short, I computed the Lorentz boost of some 3-vector $\mathbf p = \mathbf{p}(E,\theta,\phi) \to \mathbf{p}'$ having the 3-...
5
votes
2answers
173 views

BreadthFirstScan for implicit Graph

Many algorithms on graphs require only local knowledge at each step, e.g. for BFS at any point we only need to know the AdjacencyList of the vertex we are currently ...

1
2
3 4 5
51