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
1 answer
80 views

Parallel Mathematica-code that runs too slow when running PowerRepresentations[] function

Well, I am a student in elementary number theory and trying to find natural numbers that can be written as the sum of integers to the power of an integer. The code I am using now is the following: <...
user avatar
  • 1,723
1 vote
1 answer
84 views

I need to speed up this summation

I tried solving this problem on my own but I cant find a proper solution. I need to evaluate the following equation: $\sum\limits_{m=1\\m\neq i}^n{\left(\dfrac{v_m~(\lambda_i\cdot B-A)~u_i}{(\lambda_m-...
user avatar
2 votes
0 answers
58 views

use of small functions

I was wondering if it will slow down my code if I have a bunch of small functions like isNewRound[currentMove_] := Return[Mod[currentMove, 4] == 0]; which are ...
user avatar
8 votes
1 answer
270 views

How to compute RandomReal faster?

I have variables $E_{1},E_{3}$ that are bounded in the following way: $$ \tag 1 E_{1}>m_{1}, \quad E_{3}>m_{3}, E_{2}\equiv m-E_{1}-E_{3}>m_{2}, \\ -1 < \frac{E_{2}^{2}-m_{2}^{2}-(E_{1}^{2}...
user avatar
  • 3,544
6 votes
1 answer
213 views

Producing a random Wang Tile tiling image more efficiently

I'm following along with this SIGGRAPH 2006 paper Recursive Wang Tiles for Real-Time Blue Noise - there's a video here too. Eventually I want to try to produce the blue noise results in the paper, and ...
user avatar
  • 20.4k
0 votes
0 answers
80 views

Import website "Source" slows down after a few iterations

I am using Import[link, "Source"] to import the source of several hundreds of thousands of webpages in a while loop to process them. Each iteration has ...
user avatar
  • 11.5k
3 votes
2 answers
266 views

Optimization for numerical integration of Airy function and using NIntegrate inside NDSolve

Sorry for the long post. I need to integrate a function which uses the trajectory data given by the Lorentz force equation. We have the electromagnetic field: $$ \vec{E}=E_0 \cos{\omega(t+\bar{z})}\...
user avatar
  • 320
3 votes
3 answers
243 views

Solving for a unique set of solutions

I have the following code: ...
user avatar
  • 1,723
3 votes
1 answer
128 views

Is it possible to improve a code related with iterative closest point (ICP) algorithm?

I am trying to write a code related with ICP algorithm. The purpose of the code is matching a target data with a reference data by translational operation in XYZ axes (3-degree-of-freedom (DOF) ...
user avatar
  • 147
4 votes
0 answers
61 views

Accelerate the retrieval time for Entity data

I like to use Mathematica to answer questions related to cities such as how many cities in the United States have a population greater than 100,000 and what the distribution of them would look like on ...
user avatar
5 votes
2 answers
313 views

How can I speed up RandomVariate in the following case?

I would like to generate random values of some parameter with the weight being the Poisson distribution. An important point is that each time I generate the random number I need to consider the ...
user avatar
  • 3,544
1 vote
0 answers
45 views

How to optimize Code for Wolfram Challenges?

I am wondering if anyone who has knowledge of optimizing programs in the Wolfram language has any advice on how to optimize the following quantities of programs written to solve Wolfram Challenges. I ...
user avatar
9 votes
1 answer
178 views

How to sort lines into continous paths efficiently

As part of my work I get a bunch of lines from my co-worker. (Background: I do electromagnetic designs, my co-worker does the mechanical design). These lines are in random order, but I need them in ...
user avatar
  • 923
0 votes
0 answers
28 views

Optimizing an 2D-NIntegrate in terms of speed

I am trying to optimize the following function further in terms of speed while maintaining the given Precision and correctness. The function decribes the two dimensional convolution of a sum of Bessel ...
user avatar
0 votes
0 answers
51 views

Why is Clip so slow and how can I improve its performance?

The built-in function Clip is defined as a way to clip a value between a specified minimum and maximum. Another way to do this, is simply by utilizing ...
user avatar
  • 789
0 votes
2 answers
64 views

How do I optimize a simulation containing both a While loop and a Do loop?

I have written a simulation of a rotating molecule that I was hoping to get help to optimize. Below you see the main function in the simulation. The function FlatPart calculates the angle θ and the ...
user avatar
  • 1
5 votes
1 answer
473 views

Generating a list of integers that sums to zero

Given a pair of integers n and k, I want to generate all lists of integers of length n, ...
user avatar
8 votes
0 answers
99 views

Why is WeightedData slow?

I have been using WeightedData with Histogram, HistogramList, ...
user avatar
  • 245
0 votes
0 answers
42 views

NMinimize too slow with non-linear constraints. Help to speed it up

First, let me introduce some parameters: ...
user avatar
  • 1
1 vote
0 answers
29 views

Repeated calculation with neural network measurement slows down

I have a list of 200 neural nets nets0. I have to measure the output of several layers of each of them on a list of 1000 associations ...
user avatar
  • 195
18 votes
3 answers
488 views

Difference between HashTable datastructure and Association datastructure

Is there a difference in the runtimes between CreateDataStructure["HashTable"] and <||> in terms of inserting, ...
user avatar
  • 558
2 votes
1 answer
65 views

How to manipulate functions?

This is probably a simple question, I have matrix a , and I construct b from a by adding a variable to the first column. b is a function of variable d, and now I need to do mathematical calculation on ...
user avatar
0 votes
0 answers
90 views

Solving a system of equations as part of maximizing a multivariable function

This is my code ...
user avatar
  • 270
1 vote
0 answers
67 views

How to work with structured data using graphs

Given that the functions for not only creating but also modifying Graph are functional programming creating copies it seems to me that it is a good idea to keep the vertices small, such as sticking to ...
user avatar
27 votes
1 answer
730 views

Efficient multidimensional optimization while constraining some coordinates

I have a function f[x] with a high-dimensional vector input and a scalar output. I am looking to minimize this function while constraining some of the components of ...
user avatar
  • 224k
0 votes
0 answers
34 views

Tips to help FindInstance with a lot of complicated inequalities

I'm trying to find a numerical instance (I don't need arbitrarily high precision) of solution to 7 relatively complicated inequalities (plus the region specification) involving 8 variables. The ...
user avatar
  • 353
0 votes
0 answers
81 views

Summing `Piecewise` function with many cases efficiently

Schematics of the question: I have two piecewise functions $f_1$ and $f_2$ as $$f_1 = \begin{cases} \textrm{value 1}, & \textrm{case 1}, \\ \vdots & \vdots \\ \textrm{value 1024}, & \...
user avatar
1 vote
2 answers
99 views

Simplifying expressions with `Sign` functions to a single piecewise format

I have the following expression with many Sign functions: ...
user avatar
0 votes
1 answer
57 views

Single computation is fast, but 6 computations are extremely slow

I have an expression that involves many Sign functions. I want to expand this in the piecewise format. My function is: ...
user avatar
2 votes
0 answers
96 views

Building a Matrix as a piecewise-function of the indices without for loops [closed]

I'm very new to Mathematica and this site. I've read that building matrices with For loops is slow, and I have experienced this myself on the current project. I'm trying to wrap my head around ...
user avatar
1 vote
1 answer
114 views

Equation solving with magnitude constraints incredibly slow

Somewhat complicated question and sorry in advance if it is presented poorly. I'm running Mathematica 12.0 (haven't updated to 12.1 yet). I'm trying to solve a set of linear complex equations with ...
user avatar
2 votes
3 answers
149 views

What is the limit of the sum as `t` approaches infinity?

I am unable to find the limit of the following sum as t appraoches infinity ...
user avatar
  • 199
4 votes
0 answers
63 views

Why is EstimatedProcess so slow for a vector ARProcess?

I'm trying to fit some 4 x N data to a vector auto-regressive model. However, EstimatedProcess is very slow for this. For a 4-th order vector AR process, it takes more than 10 seconds (for N approx. ...
user avatar
  • 176
2 votes
1 answer
73 views

select the right numbers based on a condition

I want to optimize my stock portfolio based on three components: the price of the different stocks the number to buy of each of the stocks the expected return of each stock (after 12 months) For ...
user avatar
2 votes
2 answers
123 views

Really slow evaluation of a simple? list expression

I believe this is a standard problem, but I could not find a solution anywhere. Possibly because I don't know what to look for. I define a subset of some numbers and I want to count how many are less ...
user avatar
12 votes
8 answers
1k views

Checking if two line segments intersect

What is the fastest way of checking whether two line segments of the form Line[{p1,p2}] intersect at a point? I don't need to know what the point of intersection is,...
user avatar
  • 4,138
0 votes
0 answers
41 views

NMinimize with elimination returns strange results

I have a parameter vectors pars, par1, and a matrix data1 together with a vector result <...
user avatar
  • 125
3 votes
1 answer
55 views

Converting Association to Matrix

Imagine I have the following association, where the keys are given as pairs of natural numbers ...
user avatar
  • 4,138
0 votes
0 answers
127 views

How to use Equal for close arbitrary precision numbers to be considered the same?

I am trying to add a comparator function in a larger piece of code which can equate two arbitrary precision numbers and yields True if they are approximately close. ...
user avatar
  • 8,528
1 vote
0 answers
76 views

Fail to inverse the Piecewise function embedded in a NDSolveValue

I am trying to estimate a function consisting of a Piecewise function that included in a FEM solver. I firstly developed my mesh for the FEM model based on @Tim Laska's work. The code is shown as <...
user avatar
  • 331
9 votes
2 answers
203 views

Looking for a Compilable Form of DeleteDuplicates

Union is Compilable but DeleteDuplicates Isn't?! First, DeleteDuplicates is not compilable ...
user avatar
0 votes
0 answers
76 views

Plot is fast, solve is slow - what optimizations can be made?

I'm trying to solve a 3D geometric problem in terms of 3 variables (rotational angles), and I think the end is finally in sight - quite literally, I can see on a 3D plot where my solution exists. ...
user avatar
  • 101
1 vote
1 answer
80 views

Speed up FindRoot

I need to calculate Sv[zm,zs,zh] for a given range of zm and zs with fixed ...
user avatar
4 votes
1 answer
178 views

Why is a function of two functions that use memoization still slow?

I have two functions that I both use memoization for. My goal is to plot the ratio of these two functions. Since I already plot the functions by themselves, and I use memoization, it would seem to me ...
user avatar
6 votes
3 answers
805 views

Multiplication with zero

So I have a function $f(x) = g(x) h(x)$ that I want to evaluate on a large discrete set $\Lambda$ expressed as a list. I have that $g$ is complicated and takes time to evaluate at each point in the ...
user avatar
  • 313
2 votes
1 answer
70 views

Is there an efficent way to rearange lists of lists where transposing the whole list is no option?

I have a list of lists of lists, listing pairs of pairings. {{{a,b},{c,d}},{{a,e},{f,g}},....} I want to apply a function to this list that gives me a 4 level list where each first level element ...
user avatar
  • 23
7 votes
4 answers
377 views

AnyTrue is too good (compared to MemberQ)

Let L be a list of integers, and ⓝ denote an explicit integer. I've thought the most natural way to tell whether ⓝ belongs to L is In[1] MemberQ[L, ⓝ] But there ...
user avatar
  • 2,451
2 votes
1 answer
106 views

Faster way to generate a sequence of numbers

There is a sequence of Numbers that satisfies (1) $a_1+p\geq 0, a_2+p=0, p\in R$ (2) $a_{4n}>a_{4 n-1}, (n=1,2,...)$ (3) $a_{m+n}\in\{a_m+a_n+p, a_m+a_n+p+1\}, (m,n=1,2...)$ I tried to list the ...
user avatar
  • 4,910
3 votes
1 answer
305 views

Why ParallelTable is even slower than Table for large tensor construction?

I would like to create a large rank-4 tensor by using both Table and ParallelTable. What is actually constructed is given below: ...
user avatar
  • 425
4 votes
0 answers
72 views

How to efficiently build a large sparse matrix and overloading a compiled function?

I would like to construct a large sparse matrix folding from rank-4 tensor given by the following: $\mathcal{L}_{1L}^{00}(i,j)=\mathcal{L}_{1L}^{00}(m_1,m_2;M_1,M_2)$ The indices of matrix $(i,j)$ are ...
user avatar
  • 425

1 2
3
4 5
53