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

Is it possible to improve the timing of multiple for loops?

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
2 votes
1 answer
84 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 ...
sam wolfe's user avatar
  • 4,157
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
280 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.7k
5 votes
5 answers
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 ...
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
87 views

How to speed up compilation of some functions?

...
Yilin Cheng's user avatar
0 votes
1 answer
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 ...
Yilin Cheng's user avatar
6 votes
2 answers
389 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,642
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
114 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
65 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
86 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
630 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
  • 414
1 vote
1 answer
153 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
157 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
101 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
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 ...
Dotman's user avatar
  • 414
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
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 ...
QFTheorist's user avatar
1 vote
0 answers
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 ...
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
  • 414
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,642
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,642
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
  • 414
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
  • 414
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
  • 414
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? ...
valar morghulis's user avatar
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
703 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 vote
0 answers
46 views

Make a recursive function for computing a matrix faster

I have a function below called inverseKostkaHelper (see belos) which I want to make faster. It takes two integer partitions as arguments, (both with the same total ...
Per Alexandersson's user avatar
3 votes
2 answers
782 views

How to speed up this small 2D graphics code?

The following code is very slow, with Mathematica 13.2 on a Mac Silicon M2 Pro: ...
Cham's user avatar
  • 3,959
4 votes
2 answers
170 views

How to create an Xlookup function (similair to Excel)

Edit: I have added table3, which is closer to my real life use case and timings of the code Edit 2: I have added table4, which ...
IntroductionToProbability's user avatar
4 votes
1 answer
97 views

Building projection operators efficiently

The projection operator $P$ is defined in quantum mechanics as $$ P=\sum_i^n \vert\psi_i\rangle \langle \psi_i\vert, $$ where $\vert\psi_i\rangle$ is a column vector and $(\langle \psi_i\vert=(\...
wooohooo's user avatar
  • 279

1
2 3 4 5
59