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

1k views

### Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
165 views

### Warning and Errors during Compile

I defined a compiled function cf = Compile[{{x, _Integer}, {n, _Integer}}, z = (n^x); Binomial[n, #]* StirlingS2[x, #] *(#!)/z & /@ Range[x]]; and I ...
89 views

### Reduction of repetitive calculations in Table

If I generate two tables inside a function which are function[n_, x_, y_]:=( table1 = Table[i* x/n^x, {i,1,n}]; table2 = Table[i* y/n^y, {i,1,n}]; ) where ...
259 views

### Optimizing the front end on the Raspberry Pi

Using Mathematica's Front End on the Raspberry Pi is truly a test of one's patience. The most basic of notebooks become unresponsive after seemingly trivial additions to the notebook. Consider the ...
1k views

### Mma 10: Half the parallel power (Macs)?

Here is a comparison of the parallel kernels launched under Mathematica under v9 and v10, on the same identical current 2014 R2-D2 Mac Pro ... [ Update: Valerio has commented that the same issue ...
107 views

### Timing: how make a program to work faster using built in functions and tables

I want to improve my code to make it working faster even for very large numbers. ...
290 views

### Problems extending NelderMeadMinimize into 2D

Update The eventual route I followed was to adapt a version of the NM-simplex written in C and link to it with MathLink. Once I've tested this out fully I'll post it here. I've been playing around ...
530 views

### the more effective method to find 21 digits armstrong number

In recreational number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number(after Michael F. Armstrong) or a plus perfect number) is a number that is ...
112 views

### Complex Convolution

I am attempting to integrate a convolution variable using the following code. However, the program is taking too long to complete the integration. Does anybody have any coding tips that may make ...
212 views

### Alternative for MapThread in listable functions

How can I rewrite this more efficiently taking advantage of flo, dem, and Nsup being ...
124 views

### How can I speed up this multi-equation Solve problem?

I'm trying to solve a set of equations (chemical kinetics for a complex system, but don't worry about that). I ran it for 24 hours and I got no output. Here is the relatively simple code (I want to ...
34 views

### Speed up series expansion [duplicate]

I have a rather complicated function that I need to expand it in series, which is quite straightforward but takes a long time. I was wondering if there is a way to speed up such a calculation: ...
292 views

### Position of Subsets in a List

I have a particular list of integers and a matrix whose entries are lists. Say I know that my particular list is a subset of at least some of the elements in the matrix. I want to find an efficient ...
61 views

### Understanding Mathematica: How to write fast code? [duplicate]

I'm relatively new to Mathematica but have done a few projects using it so I'm quite comfortable with the syntax and the basic functions available. Since I've had programming experience in the past I ...
507 views

### How to speed up minimization of function

I have the fallowing code (the functions within that code are replaced by simpler ones, but the code structure is identical):  ...
128 views

### Speeding up the numerical integration of a certain function

I'm using the following function f[t_] := 3/4 t^-3 NIntegrate[(x^4*Csch[x/2]^2), {x, 0, t}, Method -> {Automatic, "SymbolicProcessing" -> 0}]; I ...
235 views

### More efficient Omnibus number determination?

Amusing myself with concepts from "Omnibus Sequences, Coupon Collection, and Missing Word Counts", in particular the sequences. To paraphrase the concept, a string is k-Omni over some alphabet a if ...
85 views

### Timing Differences

In More efficient implementation for comparing coefficient lists in a Do-loop link, george2079 posts in his first answer a piece of code that takes 352 seconds to compute. When I run this same piece ...
221 views

### More efficient implementation for comparing coefficient lists in a Do-loop

I'm wondering how to speed up the following code so it actually computes for $n=2$: ...
114 views

### Dramatic increase in memory consumption and performance drop with ParallelMap

Consider the following toy problem: ...
2k views

### Smooth Peter de Jong attractor

Today I was playing with Peter de Jong attractor. At the bottom of the page I've linked there are beautiful examples like: My attempts are not so great: It is around 10^5 points. For more than ...
371 views

### Alternative ways to AppendTo and Delete in a While loop

Is there an alternative way to do AppendTo and Delete and also replace k0 during every ...
472 views

### How would you efficiently implement BinListsBy?

Let's say I have a list like this: data = {{21, "Alice"}, {27, "Bob"}, {22, "Charles"}, {34, "Dora"}, {75, "Eliza"}} containing ages and names of persons. What I ...
134 views

### Help with Computation-heavy triple integration

I'm Trying to use Mathematica to symbolically integrate a function with respect to x, y, and z. For some reason, this computation either takes about, 60s and returns the input, or takes many hours ...
274 views

### Understanding performance: graph connected components

I need to analyze directed graphs with 10M edges, 1M vertices, and 300K strongly connected components, so that the largest one contains 400K vertices. I read some explanations of Leonid Shifrin here, ...
1k views

### Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
817 views

### Poor performance from Graphics3D

I wrote a game -- 2048，Some codes are from http://blog.wolfram.com/. My codes are in notebook downloads I added code so that the game can play in 3D form, but when I play it, I find that it is too ...
65 views

### A more efficient way of fitting a non-linear model that returns an entire list?

I have a function that takes two parameters, del and nu, and returns a list npoints long ...
448 views

### Finding all sets of elements with two common elements in a large dataset

I have a very large network of atoms ($\approx 10^6$ atoms) with fixed positions that resemble a cellular structure: I have two files including: fixed locations of each atom set of points which ...
132 views

### ReplaceAll performance problem: packed arrays on the LHS are unpacked when the RHS is too long

The following is one of the most mysterious performance problems I encountered and came up while extending the booleval function mentioned here. I am looking for a ...
168 views

### Usage of Block in Compile

When is there an advantage to using Block in Compile? For instance, if I have a multiple-step code, how do I decide which ...
664 views

### Speed up ContourPlot3D

I have two issues with the following code. (1) It executes too slowly. If I use "Speed" instead of "Quality" for PerformanceGoal, I get the speed but an undesirable delay in proper rendering of the ...
119 views

### How to tweak the following purely numerical code

I am using the following numerical function in my program and I would like to speed it up. ...
1k views

### Is this the most effective and efficient programming style for prototyping (a ray tracer) in Mathematica?

I am trying out Mathematica as a prototyping tool. As an initial exercise I have put together a brute force ray tracer, with a view to using Mathematica's built in probability distribution functions ...
1k views

### Faster way to compute the distance from a point to a surface in 3D

I am trying to compute the shortest distance between a point and a triangle in 3D ...
229 views

### Calculate the algebraic multiplicity of known eigenvalues of a large, sparse matrix

I have a large (and sparse) matrix with size 1000x1000 -- 10000x10000. I believe i know all eigenvalues for the matrices. All entries are integers and so are the eigenvalues. I want to check this by ...
181 views

### Replacing High Densities of 1.s in Very Large Binary Arrays

I am working with very large binary arrays on the order of {100,100000}. It may look something like this. ...
2k views

### Why won't Parallelize speed up my code?

What reasons are there that can cause parallelized Mathematica code not to run with full performance?
141 views

### Randomly generated polymer with certain spatial density

For simplicity's sake, let the polymer's composing particle be integer 3-tuples (on 3D Cartesian grid), such that: Polymer-ness -- for all particle there is an directly adjacent neighbor. i.e in ...
43 views

### can I evaluate multiple cells at the same time? [duplicate]

my laptop has 2 cores, can I assign a core to evaluate one code, and the other core for another code in parallel instead of evaluating in sequence? thanks
333 views

### Why do Tooltips slow down Dynamic so much? Is there a faster alternative?

I'm working on a Dynamic ListPlot with a few thousand plots, and it seems that wrapping the points with Tooltip slows the Dynamic responsiveness substantially. With the simple example below, dragging ...
251 views

### Plot a solid generated by a family of surfaces

I'm trying to graph a series of planes as a solid object in Mathematica. I first tried to use the Plot3D options as well as the fill options to plot a $3D$ volume, ...
256 views

### A fast way to compare interval

I have a list of intervall. Some of these intervals are disjoint, some are overlapped and some are included in others. To leave no ambiguity about my explanation, you can see the following examples: ...
63 views

### Hashing by Equals instead of SameQ

I have some numerical code involving complex numbers representing points on a plane. Some of these are equal but not identical, ie ...
212 views

### Exp is slower for some number ranges

I get a hit on performance with the Exp function depending on the range of my inputs. for example, with: ...
154 views

### Make an effective projection of matrix

To best explain my problem, I will take the following example: Consider the following matrix : ...
87 views

### Compose two special power series expansions

I have two functions $A(x), B(x)$, given in a special power series form: $A(x)=1-x^{2}\left(\frac{a}{10}-\sum_{k=1}^{9}b_{k}\left(\frac{(x^{2}-1)}{r}\right)^{k}\right)$ ...
306 views

### Module in numerical model for NonlinearModelFit is slow and leaks memory

I am trying to make a NonlinearModelFit where the model is the result of a numerical calculation. My code works, but it is very slow and also seems to have a memory ...