# Tagged Questions

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.

53 views

### Make integration/ plot run faster? (takes hours)

I am using Mathematica 10.0.2.0. Here is the code I am working with: ...
67 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. ...
47 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 ...
37 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 ...
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: ...
76 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, ...
269 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 ...
61 views

...
180 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: ...
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, ...
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 ...
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 ...
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: ...
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 ...
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 ...
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 ...
25 views

### Error with Parallel Calculation on Large Multiple Sums [closed]

I am attempting to complete the following quadruple sum: ...
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. ...
38 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 ...
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: ...
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 ...
175 views

### Quick way to generate the Shepp-Logan phantom

I have some very old code for generating a Shepp-Logan phantom: ...
335 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: ...
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 ...
76 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 ...
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 ...
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, ...
129 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 ...
108 views

### Speeding iterative computation

I want to get the following iterative sequence ...
196 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 ...
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 ...
65 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 ...
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. ...
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 ...
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: ...
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... <...
180 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 ...
79 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 ...
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, ...
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 > ...
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: ...
552 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 ...
44 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 ...
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: <...
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 ...
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 ->...
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. ...
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 ...