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.

learn more… | top users | synonyms (4)

0
votes
1answer
58 views

Improve speed of Nested Matrix exponential

I have a short Code example and I want to know whether it is possible to improve the speed. The L matrix in my code is a SparseMatrix, but for this question I just use something similiar. ...
0
votes
0answers
43 views

averaging over large number of random realizations

I want to run following for few hundreds of a random variable set. This calculates: generate normal random variable find gain with squaring calculate performance metric find ...
0
votes
0answers
35 views

Optimization of the process of obtaining a global stiffness matrix

I created this code in a detailed manner so that i can understand. However it is not optimized. I think that may be a bit confusing. Anyone who is interested in analyzing and understanding my ...
0
votes
1answer
40 views

Mean brightness and the standard deviation of columns in a gray scale image

I want to calculate the mean brightness and the standard deviation of columns in a gray scale image (8bit). Can the following calculation code be made faster or/and shorter: ...
2
votes
3answers
75 views

Getting directly a packed array of repeated packed arrays

Consider this code: Needs["Developer`"]; N@Range[5]; PackedArrayQ@% Table[%%, 5]; PackedArrayQ@% which prints True, ...
12
votes
2answers
265 views

Fractal basins of attraction in a Magnetic Pendulum

I am trying to write a Mathematica program that realizes a graphical approximation of the basins of attraction in a Magnetic pendulum subject to friction and gravity, in which the three magnets are ...
3
votes
0answers
61 views
7
votes
4answers
179 views

How to avoid repetitive calculation when doing numerical integral?

Suppose I have a function f[x] which is very complicated, together with a function g[f[x]]+h[x] to integrate. That is: ...
0
votes
1answer
31 views

Iterating certain variables in a predefined function [closed]

I have a function which is dependent on a number of variables. I need to evaluate this function at the particular locations given by, ...
1
vote
1answer
68 views

Efficient method to calculate green's function between points

I am working on an analytical model for sound radiation from a cylinder. As part of this work I am using the boundary element method to predict the sound pressure at a particular location away from a ...
0
votes
1answer
73 views

How to increase the evaluation speed of this numerical integral?

I have a three dimensional integration, which takes about 30s using LocalAdaptive and "GaussKronrodRule". Using ...
15
votes
8answers
2k views

How to avoid procedural loops in this example?

I want to iterate over a list, and return the index as long as I found the first element satisfying my condition. Written in a for loop: ...
10
votes
0answers
82 views

Why does GreaterEqual take a long time to evaluate with arrays?

Take the following example: big = RandomReal[1, 10000000]; Head[big >= 0.66] // AbsoluteTiming (* {0.53489, GreaterEqual} *) Why does this take a long time ...
2
votes
3answers
131 views

Independent manipulate controls for part of list data

I have a graphic that consists of a ListPlot3D and a ListPointPlot3D. I want to only display part of the data for the second plot up to an nth index. That data is in ...
3
votes
1answer
64 views

How To Improve Mathematica StarData Performance When Compared To AstronomicalData

My tests of using AstronomicalData versus StarData show that StarData requests are 15 times ...
1
vote
0answers
24 views

Error with Parallel Calculation on Large Multiple Sums [closed]

I am attempting to complete the following quadruple sum: ...
1
vote
1answer
79 views

How to speed up this code with NMaximize?

I want to maximize the expected exponential growth rate of the portfolio, which contains 3 stocks. I get the adjusted stock price for General Electric, Du Pont, and IBM. ...
0
votes
0answers
37 views

Fast way to export large amount of data in “Table” format

I have about a million 3D points, say data = Table[{1. x, 1. y, 0.}, {x, 1000}, {y, 10^3}]~Flatten~1; I want to visualize them, but ...
1
vote
0answers
55 views

Improve speed of RK4 algorithm for solving ODE

For anyone with interests in dynamical system, i'm trying to plot the phase space of a given hamiltonian. My code is this: ...
0
votes
0answers
42 views

More efficient way of filling in a specific entry in a list of lists [duplicate]

"coords" is a list of coordinates in the 2D plane ordered in a specific way, with the 3rd (z-axis) positions left empty to be filled in with specific values, like temperature or concentration at the ...
3
votes
1answer
175 views

Quick way to generate the Shepp-Logan phantom

I have some very old code for generating a Shepp-Logan phantom: ...
6
votes
2answers
332 views

Cross product between two lists of vectors

I'm trying to create a function that does the cross product between two lists of the same dimensions, element by element. Each entry of the list is a 3D vector. Something like this: ...
10
votes
1answer
161 views

Memory leak with NDSolve

Edit The technical team confirms the memory leak in NDSolve and has forwarded an incident report to the developers. This is not the first time the question in ...
2
votes
2answers
75 views

Slow evaluation of Recurrence plot data from NDSolve: Performance Tuning

I am trying to use a recurrence plot to pinpoint the location when a system re-visits a previous point in its phase portrait. The system (a thin liquid film) is governed by a non-linear differential ...
0
votes
0answers
38 views

Data structures in mathematica for choosing permutations

I am trying to classify permutations of n, in this case n=6, elements depending on the cycles that contian the points 1 and 2, since these are considered to be special points. So for example, I will ...
1
vote
1answer
58 views

Control data type (or precison?) to limit memory usage

I couldn't find the answer to my question, so here it is: I have quite a large table, which I generate in Matlab (for some reasons i use both Matlab and Mathematica, I'd like to use only one of them, ...
2
votes
2answers
128 views

Multiple object detection and tracking in images

The code below: reads in a number of png images, where the background is dark and objects of interest (here 3) are bright dots determines in each image the coordinates and other information ...
2
votes
1answer
108 views

Speeding iterative computation

I want to get the following iterative sequence ...
3
votes
1answer
195 views

Alternatives to For/Do Loop to optimize indexing Matrix

I am trying to optimize my code that searches for elements in the rows of matrix that are greater than 0. Then use that position to grab the element from other matrix. I use the do loop to iterate ...
3
votes
1answer
102 views

Efficiently compute this Table of NullSpace

I have two $(2n,2n)$ matrices, $A_1$ and $A_2$, and I would like to compute $$\ker(A_1^p A_2^q -I)$$ for $p,q\leq 2n$. Both matrices are orthogonal and have exactly four non-zeros values on each ...
2
votes
0answers
64 views

How to use Compile? Bivariate Gibbs Sampler

I am trying to use compile to speed up my Gibbs sampler. I know I can use Reap and Sow to speed up tremendously. I have a more complicated Bayesian posterior that I want to speed up with compile so I ...
7
votes
2answers
512 views

How to speed up interpreting numbers from strings?

In processing a large text file I have batches from ReadList of 100,000 Records of the form. ...
0
votes
1answer
47 views

Speeding up WhenEvent + NDSolve (Performance tuning and handling instabilities)

I am solving a non-linear partial differential equation using NDSolve. The equation models a liquid film on an isothermal solid substrate. As a result of various fluid physics mechanisms such as ...
1
vote
1answer
69 views

Keeping determine digits in Append to process

The end of my code is written as below. Ignoring the inefficient role of Append, I want to have very simple set of values as for example: ...
1
vote
2answers
228 views

MatrixPower performs slower than Do loop

I have two almost identical pieces of code: one with MatrixPower responsible for matrix multiplication and another with Do loop. Why the latter performs much faster? It looks counterintuitive... <...
2
votes
1answer
179 views

Compiling in mathematica

I'm trying to compile what I think is a pretty simple function that does matrix multilplications in a loop (see below). But Mathematica issues the message: Could not complete external evaluation ...
1
vote
0answers
78 views

Speed differences between Table, Replace, Array, Map, and AssociationMap

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for ...
12
votes
3answers
294 views

Efficiently generating samples from an urn with maximum per element constraint?

I need to sample from a distribution that is a hybrid of uniform and hypergeometric in the sense that all elements are sampled uniformly until an element reaches some specified maximum observations, ...
1
vote
0answers
70 views

Build basic Adobe Kuler-type construction: improving performance / speed

Adobe Kuler is a useful web tool to create colour palettes, but it is limited to 5 colours. I am trying to make a basic Kuler-type construction, but it is very slow, and crashes on my computer for > ...
5
votes
3answers
186 views

Delete all strings that are prefixes of another string

I have a long list of strings and I'm trying to find a more efficient way of removing those elements that are prefixes of another: ...
17
votes
3answers
551 views

How to speed up estimation of Mean and Gaussian curvatures on triangular meshes?

I am trying to estimate curvatures on a triangulated surface/manifold using the algorithm of : Meyer, M., Desbrun, M., Schröder, P., & Barr, A. H. (2003). Discrete differential-geometry operators ...
2
votes
0answers
43 views

Is there a way to figure out the “upper limit” of my PC's computational ability in Mathematica?

I am doing some simulations with Finite Element Analysis (FEA) and part of it is forming a mesh in 3D and then using NDSolveValue to solve a differential equation on that mesh. For some meshes, my ...
1
vote
1answer
99 views

How to read a part of huge matrix saved in a TXT file as single expression?

I saved a huge matrix of numbers with dimensions {400, 4001, 2} using Put and got a TXT file formatted in the following way: <...
0
votes
1answer
115 views

How to speed up my code for plotting purposes?

Below is my code in order to produce a numerical expression for the final function that needs to be plotted. I have tried to see the output of each successive expression by running the code and ...
2
votes
1answer
54 views

how to use Expand command efficiently

Recently I got in a problem and I will try to explain with a simple example. I have an expression which reads : y = (10 + 2*x )/x; Now I want to substitute 1/x ->...
6
votes
2answers
152 views

How to save the caching produced in processing

As my this previous post.I get a custom function which can help me got some function contain a certain option.And I have put it in my "init.m" file. ...
0
votes
0answers
47 views

How to get ContourPlot3D to run involving elliptic functions?

I need to plot zeroes of a function of three variables that involves elliptic functions. For example, I have ...
15
votes
0answers
164 views

FindMinimum doesn't increase step size when necessary

I've spent much time finding a minimal example demonstrating this problem with FindMinimum. Normally one faces this problem when fitting very large and complicated ...
1
vote
1answer
52 views

Fastest way for data input into StreamPlot function

I'm interested in looking at graphing the phase portraits of 2x2 autonomous ODEs, and I'm using the StreamPlot function. Here is one simple example: ...
3
votes
3answers
110 views

Finding negative sequences in a large list: optimization

I ran across an interesting challenge recently, and I was thinking this community would know how to optimize it. I have several data sets which have (currently) about 50k-100k points. The sets ...