# 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.

60 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. ...
44 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 ...
4k views

### Best way to create symmetric matrices

From time to time I need to generate symmetric matrices with relatively expensive cost of element evaluation. Most frequently these are Gram matrices where elements are $L_2$ dot products. Here are ...
857 views

### Remove linear trend from data

I have a large data set with 150k lines and two data columns. I noticed that there is a linear trend, which I want to remove. So, I do the following: First, fit with a linear model: ...
188 views

### How to find the derivative value at $(\pi,0)$ for this implicit function $n$ times?

I am trying to take the implicit derivative at $\sin(x+y)+\sin(x)=y$ and substitute $x=\pi$ and $y=0$ at least 6-7 times since I need to find the Taylor series for this function. Since I barely ...
286 views

### Speed up Select on large list

I am running this on a very large list, it is important to notice that some times the dates in v occure several times, and I want the selected list to show the same amount. This produces the right ...
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, ...
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 ...
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, ...
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: ...
3k views

### What is a Mathematica packed array?

A simple sounding question with a few sub questions: What is the difference between unpacked vs packed array? Are packed arrays more space efficent, how much so? Are packed arrays more time ...
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 ...
971 views

### Are there guidelines for avoiding the unpacking of a packed array?

Packed arrays are very useful because they save memory and generally allow speedier and more efficient calculation times. If a list of data currently stored as a packed array is unpacked, it can slow ...
381 views

61 views

...
1k views

### How to speed up text recognition

I have a large corpus of text to analyse. I've managed to automate splitting it into individual lines because I've found that each line in this relatively old scanned document needs to be dealt with ...
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 ...
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, ...
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 ...
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 ...
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: ...
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, ...
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 ...
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. ...
599 views

### Why is my solution to PE #5 so slow

I'm new to Mathematica and it was suggested to me to go through the Project Euler problems in order to learn it. However, I can't quite figure out why my solution to #5 is so slow. The problem: ...
173 views

### Randomly generate points on a van der Waals surface

I'm looking to randomly place an atom $\mathbf{A}$ onto a van der Waals surface formed by atoms $\mathbf{B}$, such that the distance between the randomly-generated atom $\mathbf{A}$ and the nearest ...
273 views

### Histograms of gray scale images

I have a large set of subsequent 8bit gray scale png images (50 Hz). They show the noise of a CMOS camera, with the lens covered. A subset of 50 images is available here: https://goo.gl/Sa3P9P I ...
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. ...
24 views

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

I am attempting to complete the following quadruple sum: ...
2k views

### How to improve the performance of solutions to Project Euler (#39)?

This is the problem 39 of Project Euler, which I asked in the chat room two days ago. My original code runs as slowly as snails, and finally I got two answers from JM and Rojo. Unfortunately, both of ...
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 ...
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 ...
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 ...
252 views

### Law of Cosines to determine angle change along spiral

The Spiral I'm trying to place circles along the outside of an Archimedean spiral. Shown below: ...
175 views

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

I have some very old code for generating a Shepp-Logan phantom: ...
5k views

### Fastest way to calculate matrix of pairwise distances

It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
66 views

### Estimating processing time for commands [closed]

I am trying to evaluate some equations by using Taylor series of expansion (Series[], ExpandAll[], and Normal[] command), and using n equation and n unknown (Solve). Following is not full command (if ...
163 views

### How to optimize my own BezierFunction?

A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail. I also know that BezierFunction[] is built-in ...
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: ...
414 views

### Mathematica9: NDSolve slows down after repeated calls

Bug introduced in 9.0 or earlier and persisting through 10.4.1 or later I have noted that in Mathematica 9 my code, which involves a lot of calls to NDSolve, ...
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 ...
240 views

### How to boost the performance of my own BSplineFunction

In my CAGD package, I implemented a CAGDBSplineFunction[] like built-in BSplineFunction[]. ...
108 views

### Speeding iterative computation

I want to get the following iterative sequence ...