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
25 views

Problems manipulating 3d Show[] output with multiple 3d objects

My situation is as follows. I have two 3d objects, one created inside Mathematica and the second an imported STL file, that I want to superimpose and view together inside Mathematica. I want to be ...
0
votes
0answers
38 views

A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those ...
3
votes
2answers
78 views

Passing Arguments or Passing a List and Referring to its Parts – Which Gives Better Performance?

Which is better for optimizing speed, memory, and coding "safety" – passing arguments to a function or passing a list to the function and call the list's parts? That is, which of the ...
0
votes
1answer
60 views

Highly oscillatory Integral over Airy function

I have to (numerically) integrate this function over all p from to get a function g(x): ...
2
votes
1answer
49 views

Efficient way to partition a list into equivalence classes given an equivalence class function (not an equivalence relation)?

Suppose I have a list of elements and a function f which maps each element of list to an ...
0
votes
2answers
92 views

Is there any way to speed up this Mathematica evaluation?

I am interested in evaluation of the following integral ...
2
votes
1answer
82 views

Parallelization of two procedures inside Module

I am new in parallel programming and I am trying to speed up an old code using parallelization when possible. So I am (re)writing a function that computes two lists with the same dimensions (called <...
1
vote
0answers
46 views

Reduce the time-complexity of an algorithm using BellY

The code below is critical for my computation. I have to evaluate it for n around 100 and 200...
2
votes
1answer
97 views

Slow Sum with Subscripts

Edit: My original question implicated D in the problem, but it seems unrelated, so I've removed that part of the question. I am writing a function that uses ...
0
votes
0answers
59 views

Calculating my code for higher values of `k`?

How do I calculate the mean of A for higher values of k ...
4
votes
1answer
149 views

How can I speed up this Monte Carlo integration for the Stieltjes constant $\gamma_n$?

Pre-requisite Definition Stieltjes constants ($\gamma_n$) are the constants that occur in the Laurent series expansion of the Riemann zeta function. $${\displaystyle \zeta (s)={\frac {1}{s-1}}+\sum _{...
7
votes
3answers
359 views

Speed up minimization of a high-degree polynomial

For fixed $s$ and $n$, I need to find $\alpha$ which minimizes the following expression $$h (I-2\alpha H + 2\alpha^2 H + \alpha^2 \mathcal{H})^s x0$$ where $$ \begin{array}{lll} h&=&(1,\frac{1}...
3
votes
1answer
124 views

Quickly compute inverse summation

I'd like to look at behavior of $f(n)$ for the following $f$ $$\begin{array}{lll} g(s,n)&=&\frac{1}{n}\sum_i^n \left(1-\frac{1}{i}\right)^s\\ f(n)&=&\text{smallest } s \text{ such that ...
2
votes
1answer
67 views

Why does the integration of this symbolic matrix slow down after compilation?

There's a symbolic matrix as the following. Why does the integration of the symbolic matrix slow down after compilation? How to eliminate the error information in red? Thanks. Note: The sample matrix ...
4
votes
0answers
61 views

Should I worry about concurrent access to LibraryLinked code?

According to these answers, when several heterogeneous results (say {MTensor, mint, double}) are needed to be returned from a LibraryLink ...
0
votes
0answers
63 views

Simplify a heavy calculation

I'm aware that this may be regarded as too non-specific and with too little information, but I hope that someone will be able to help me nonetheless or to request information which would be imperative ...
4
votes
1answer
134 views

How to speed up the calculation process of a symbolic matrix?

There are a symbolic matrix and a real number list. I'm going to replace the symbols of the matrix with all the elements of the list, and then to get the Eigenvalues...
20
votes
2answers
913 views

How to make Mathematica read in CSV as fast as Python's Pandas

I have many big CSV files for processing in Mathematica. And each time loading them into Mathematica takes a long time. Meanwhile, it takes much less time using Pandas under Python. For example, ...
0
votes
0answers
42 views

Two-dimensional numerical integration with multi-valued function

How can I compute two dimensional integral for the function f[x,y], which is multi-valued? This function appears as follows: For a given pair ...
4
votes
1answer
125 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
57 views
0
votes
1answer
60 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
262 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
189 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
43 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
75 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
95 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
62 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
28 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
53 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
69 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
75 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
83 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
54 views

Speeding up this function?

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

Speeding up Table of a Table

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

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

I have two functions as follows, ...
3
votes
3answers
259 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
265 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
128 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
74 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
110 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
64 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
52 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
116 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
107 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
2 3 4 5
50