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
0 answers
31 views

why N is slower when setting precision

Column[{ N[Sin[1] + Cos[1], 5] // AbsoluteTiming, N[Sin[1] + Cos[1]] // AbsoluteTiming }] {0.000073,1.3818} {0.000015,1.38177} ...
AsukaMinato's user avatar
  • 8,940
3 votes
1 answer
152 views

How to quickly sample points from the given PDF data?

Consider some data (distr.dat). It is a tabulated PDF: x, y, z, PDF[x,y,z], where x is some parameter (and the integral of ...
John Taylor's user avatar
  • 4,701
2 votes
0 answers
37 views

How can I cap calculation speed?

Sorry if I wasn't able to find an existing answer! I'm trying out Mathematica, and was running through some sample problems at night. My roommate is sleeping, and my computer fan can get decently loud....
L Lord's user avatar
  • 21
3 votes
1 answer
63 views

Is there a non-allocating way to modify elements of single-reference packed arrays?

I need to repeatedly increment cuboidal chunks of a 3D image. The image is large - on the order of 1G elements. The only way I know of doing it using built-in Image functions is: ...
Kuba hasn't forgotten Monica's user avatar
8 votes
3 answers
138 views

Speed up this computation involving NSolve many times?

Can you think of a way of speeding up this computation ? I don't. ...
anderstood's user avatar
  • 14.2k
0 votes
0 answers
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,...
Adam's user avatar
  • 11
4 votes
2 answers
243 views

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 ...
sam wolfe's user avatar
  • 4,179
2 votes
0 answers
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. ...
Lelouch's user avatar
  • 513
5 votes
1 answer
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 ...
Wjx's user avatar
  • 9,518
0 votes
0 answers
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 ...
Sid's user avatar
  • 977
9 votes
3 answers
282 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: ...
flinty's user avatar
  • 23.9k
5 votes
5 answers
502 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 ...
Andrew's user avatar
  • 10.4k
1 vote
0 answers
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 ...
TradeMark's user avatar
2 votes
0 answers
91 views

How to speed up compilation of some functions?

...
Yilin Cheng's user avatar
0 votes
1 answer
105 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 ...
Yilin Cheng's user avatar
6 votes
2 answers
392 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: ...
John Taylor's user avatar
  • 4,701
3 votes
1 answer
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 ...
Yaroslav Bulatov's user avatar
1 vote
0 answers
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 ...
AG1123's user avatar
  • 561
1 vote
0 answers
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 ...
Domenico Modica's user avatar
0 votes
0 answers
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 ...
user43830's user avatar
  • 101
0 votes
1 answer
115 views

Kernel Crash Using Solve

The following code crashes the Kernel with no error message. ...
Just Some Old Man's user avatar
2 votes
1 answer
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 ...
wooohooo's user avatar
  • 279
0 votes
1 answer
88 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: ...
ZHENGYAO HUANG's user avatar
8 votes
2 answers
632 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 ...
Brian Hopkins's user avatar
2 votes
3 answers
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: ...
LNah's user avatar
  • 189
0 votes
0 answers
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 ...
emnha's user avatar
  • 2,411
0 votes
2 answers
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 ...
Dotman's user avatar
  • 424
1 vote
1 answer
156 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 (...
mmen's user avatar
  • 163
7 votes
2 answers
158 views

Quickly seeking an entry in a table

I have a table: ...
apg's user avatar
  • 2,027
5 votes
4 answers
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 ...
IntroductionToProbability's user avatar
1 vote
0 answers
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/...
josh's user avatar
  • 11
2 votes
2 answers
104 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 ...
Hugo Andrade's user avatar
1 vote
0 answers
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: ...
scriptfoo's user avatar
  • 201
3 votes
1 answer
193 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 ...
Dotman's user avatar
  • 424
7 votes
5 answers
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? ...
Vaggelis Dr77's user avatar
0 votes
0 answers
58 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 ...
QFTheorist's user avatar
1 vote
0 answers
59 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 ...
QFTheorist's user avatar
1 vote
0 answers
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 ...
QFTheorist's user avatar
1 vote
1 answer
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 ...
delivery101's user avatar
0 votes
1 answer
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 ...
Dotman's user avatar
  • 424
3 votes
5 answers
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 ...
John Taylor's user avatar
  • 4,701
0 votes
0 answers
51 views

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

Consider the following table: ...
John Taylor's user avatar
  • 4,701
1 vote
0 answers
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: ...
Arbuja's user avatar
  • 39
1 vote
0 answers
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 ...
Dotman's user avatar
  • 424
2 votes
1 answer
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 ...
Dotman's user avatar
  • 424
0 votes
1 answer
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 ...
Dotman's user avatar
  • 424
5 votes
1 answer
80 views

Is it possible to improve the speed where parallelization is not efficient?

I tried to use Parallelize but did not boost the speed. how can improve the speed? ...
MMA13's user avatar
  • 4,265
4 votes
0 answers
201 views

Defining a "pathway" from a list of points

1. Description of Pathway 1.1 Preliminary Definitions Let $A=[-2,2]^2$, where $\text{Area}(A)=16$ and $\lceil \cdot\rceil$ is the ceiling function. For $\varepsilon\in\mathbb{R}$, let $\left\{U_i\...
Arbuja's user avatar
  • 39
0 votes
0 answers
167 views

>100 GB of memory used by Reduce. Am I doing something wrong?

Newish to Mathematica here. I'm running some code to compute regions of the parameter space where the covariance between innovations is positive or negative. On my Windows PC, it's been running for ...
hipHopMetropolisHastings's user avatar
8 votes
4 answers
707 views

Design a function that gives all strict partitions of an integer

A strict partition of an integer has all distinct parts. There are no duplicates like 1 in {5,3,1,1} for 10. All the parts are unique. Sylvester created a bijection between the partitions of an ...
Peter Burbery's user avatar

1
2 3 4 5
59