# 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.

2,908 questions
Filter by
Sorted by
Tagged with
57 views

### Speed up this computation involving NSolve many times?

Can you think of a way of speeding up this computation ? I don't. ...
42 views

### Is it possible to improve the timing of multiple for loops? [closed]

I'm working on a project to describe thermal lensing in a cylindrical crystal. The current code has a complete working calculation that calculates the temperature distribution of a cylindrical crystal,...
209 views
+50

### Optimizing an ODE fitting algorithm with interpolated data

Given data, I want to find parameters $p_1,p_2,k_1,k_2>0$ that fit the following ODE system \begin{align} b'(t)&=p_1 a(t)-k_1b(t)\\ c'(t)&=p_2b(t)-k_2c(t) \end{align} where $a(t)$ is ...
66 views

### Performance of multiplying two identity matrices

I am running Mathematica 13.3.1.0 on a M1 Mac, and I ran the following codes to check on the time spent on matrix multiplication. ...
69 views

### How to most responsively manipulate time intervals in ParametricPlot?

I often met with the case where I want to show the past trajectory of a object. A way of demonstrating this is to plot the trajectory using ParametricPlot, and then ...
26 views

### NMaximize simple function

I am trying to solve a maximisation using Mathematica. The objective function, though involved, can be broken down into many simpler terms. One of these terms is ...
281 views

### Is there a faster way to compose a large number of random Gaussians?

I'm looking for a more efficient way to generate an image with a large number of randomly coloured Gaussians. Here's the code I'm using: ...
501 views

### How to use Compile to optimize the performance of a function calculating the distance between two points?

I want to create a function that finds the real space distance between two three-dimensional points. Each point is a list of three real numbers. I can create functions ...
1 vote
98 views

### Optimize grouping of list of lists by elements

I have a sorted list of lists of size ~200,000 x 3. The data are such that the first element of each triplet loops through i = 1, 1.1, 1.2, ..., 199.9, 200, and for every value of i, the second ...
91 views

...
104 views

### How to improve the speed of tables in Mathematica?

As shown in the figure, I want to assign values to the defined very big function ff one by one, where ff has variables [t, x, v1, v2]. The speed of this Table operation is very slow, how can I improve ...
391 views

### Why Does Part Work Much Slower on Modified List?

Consider the following list: tabb = RandomReal[{0.0000001, 10^5}, {10^6, 80}]; I want to extract, e.g., the columns from 1 to 20. It is reasonably fast: ...
103 views

### Fast multivariate Cauchy sampling?

I've been using the code below to efficiently sample from multivariate Gaussian with diagonal covariance matrix. Now I want to try the same for Cauchy samples, however replacing ...
1 vote
86 views

### Attempt to find a solution (out of potentially many) to a system of equations with FindInstance runs forever or crashes

I have a system of equations that in principle should have a solution (I would think not a unique one), which I want to solve. I am not interested in all solutions; I just want to locate one, assuming ...
1 vote
62 views

### Weird slowdown on data returned by compiled function (bug?)

Mathematica 13.1 - I was cleaning up some computations and I got a x3 time increase when I reduced things to loop over. Full context is a bit convoluted, I stripped the most I could but the problem ...
43 views

### FindMinimum with many Sums and NIntegrates is very slow

I want to calculate the global minimum of an equation which has several hundred Sums (I used 300 in this code), but the calculation is very slow. My code is as ...
115 views

### Kernel Crash Using Solve

The following code crashes the Kernel with no error message. ...
66 views

### Efficient ways to generate a matrix from multiplying two elements of some matrix

I am working on the single particle entanglement entropy and in the process I have something like ...
87 views

### Speed Up Plotting of Mathieu Equations

I am trying to plot Mathieu Functions, running for an hour without a result. Here is my code: First define the relevant physical constant: ...
631 views

### Better code for Ramsey partitions

Ramsey partitions for parameters $a$ and $b$ are certain integer partition of $a+b$ developed by McAvaney, Robertson, and Webb (Combinatorica 1992) for applications in fair division problems where two ...
252 views

### How can I optimise the creation of subsets?

I have a list of 21 elements from which I have obtained possible combinations of minimum 3 and up to 10 elements using the Subsets function as follows: ...
81 views

### Is there a way to optimize it for larger n?

This is Domen's code from my previous thread here. I think it covers all the cases that I mentioned there and works well for small values of n. However, for large ...
100 views

### Why can't NSolve find values that FindInstance can?

I am trying to solve for \[Epsilon], given three input paramters n, x and ...
1 vote
155 views

### Performance of polynomial functions in Mathematica vs Python [closed]

I am trying to compare the performance of Mathematica vs Python for vectorized operations involving polynomials. The data is floatMatrix which has dimensions (...
158 views

### Quickly seeking an entry in a table

I have a table: ...
181 views

### Joining constant arrays determined by a subsequence of contiguous block of ones

I have the following: data = {15, 25, 35, 45, 55, 65, 75, 85, 95, 105}; selector = {0, 1, 1, 0, 1, 1, 1, 0, 0, 0}; I want to create the following list from ...
1 vote
41 views

### CUDADot (CUDA) taking longer than indicated by //AbsoluteTiming (~500x)

I'm using MMA 13.3 with a fresh install of cuda toolkit version 12.2. CUDADot is not as fast as indicated by absolute timing. Running the commands found here (https://reference.wolfram.com/language/...
102 views

### Optimization of a Markov сhain with symbolic transition rate

I am trying to work on 1D random walk that can move to left, right or stay with probabilities $p_i$,$q_i$,$r_i$ that changes with the site $i$. I am trying to simulate this by using a recurrence ...
1 vote
53 views

### Alternative to simplification speed-up by replacing an integer with its "non-exact" counterpart

This is a safe setting which assured that all of the equations I want to simplify are actually fully simplified: ...
192 views

### Improve performance of Linear Optimization

EDIT I am reframing the question here by pulling out the relevant part about linear optimization, you can find the original question and the entire code down below. I am trying to increase the ...
674 views

### How can I make Manipulate faster?

I'm happy with the result of the graph I made, but it runs very slowly. How can I make it lighter and faster? ...
57 views

### Using compile with indexed variables

I have the following piece of code which I made faster by using compile. I make the following definitions ...
1 vote
58 views

### Complicated expressions involving hypergeometric functions

This is in relation to my last post which was unanswered but I think I may have found somewhat of a workaround. I have the following preliminary definitions ...
1 vote
85 views

### Trying to use Linear Optimization to solve inequalities

I am trying to use Mathematica to get bounds on some quantities using a certain procedure which is called conformal bootstrap. For the users who don't come with a background in HEP, I am basically ...
1 vote
65 views

### Implement function over lists efficiently, instead of per-element

I have a function, which takes the numeric values d1,d2,p1,p2,s as input, and should return: {d1,d2} if ...
54 views

### NMinimze cant find points that satisfy constraints

NMinimize cant find solutions for a function which clearly has one. Setting a working precision resulted in some output, however with error messages about tolerance and precision. Heres my code. The ...
469 views

### How to find the most repeating row?

Consider the following table: tab={{1,0,0,1},{1,0,0,1},{0,1,0,1},{1,0,0,1},{0,0,0,1},{1,0,0,0},{0,1,0,1}} Could you please tell me whether there is a command which ...
51 views

### How to compile a code with a table having varying number of columns?

Consider the following table: ...
1 vote
164 views

### How to show the limit of two functions in a code approach zero?

I don't know how to shorten the program, the entire code is required to understand everything: ...
1 vote
65 views

### Numerical Error using compile

I'm trying to compile a function and I'm running into the following error CompiledFunction::cfne : Numerical error encountered; proceeding with uncompiled evaluation. I think I have succeeded in ...
50 views

### Defining a function using just compilable functions

I need to define a function that takes an input and if and only if its a positive real, outputs the input. If not, the output should be 0. The input could be complex valued or indeterminate. Heres ...
110 views

### Performance improvements using Table and Compile

I'm converting a code from MatLab to Mathematica. It takes MatLab less than a second to compute it while its more than ten minutes in Mathematica. I was hoping to improve the performance. Here's a ...