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 (2)

0
votes
0answers
73 views

Improving the speed of evaluating Table with nested functions

I am a Mathematica novice working with a stack of 1024 x 1024 WatershedComponents (or MorphologicalComponents) label matrices ...
4
votes
1answer
74 views

Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
8
votes
4answers
245 views

Fast method to select matrix elements based on a vector of positions

There is an operation for which I have long wanted to find a better solution. Let: a be a matrix of dimensions $m\times n$ ...
0
votes
0answers
70 views

Generate particals in a cube zone: Need code optimizion [on hold]

Problem description: Generation different sizes of particals in a cubic zone, of course, that particals must throw one by one in the zone and cannot intersect each other; the particals' coordinates ...
1
vote
1answer
60 views

A code deal with Lists operation ---Needs optimizion

I have written some code to deal with lists, But the speed of the code is slow, Could Someone help me to speed up it? Probably could rewrite it with Functional Programming! Give me some ideas! The ...
0
votes
0answers
63 views

strange timing behavior

The following code is from a book about Mathematica. ...
2
votes
3answers
94 views

Speeding Up Replacing of Labels in Large Matrix?

I am Mathematica novice and am trying to find a fast way to replace labels in some rather large matrices (512x512 or 1024x1024) that have resulted from segmenting images with WatershedComponents or ...
4
votes
1answer
119 views

Example from Mathematica documentation (ExtremeValueDistribution) seems to be evualting “forever”

I am referring to this example at the reference page for the extreme value distribution: http://reference.wolfram.com/mathematica/ref/ExtremeValueDistribution.html#6764486 The first three commands ...
1
vote
0answers
51 views

Speeding up NDSolve for system of differential equations

I am wondering if there is a way to speed up this function that solves a system of ordinary differential equations with NDSolve? Thus far I've tried specifying a few different methods such as LSODA, ...
0
votes
1answer
34 views

Timing enclosed by Manipulate not working [closed]

Manipulate[Timing[Show[somegraphs[[1 ;; i]]]], {i, 1, 500, 1}] (in Mathematica 8) This is the last line of my function f[x_]:= Module[....]. I am trying to combine a list of graphs into a single ...
6
votes
0answers
49 views

Issuing user-defined messages takes a long time (Message is slow)

Issuing messages takes a very long time in version 9 and version 10. Can others reproduce this? Is there a fix? Update: This is slow only when using the front end, but not when running the kernel ...
27
votes
5answers
1k views

How to efficiently find positions of duplicates?

Is there an efficient way to find the positions of the duplicates in a list? I would like the positions grouped according to duplicated elements. For instance, given ...
1
vote
1answer
48 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 ...
1
vote
3answers
67 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 ...
12
votes
1answer
211 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 ...
20
votes
5answers
454 views

Compiling ColorFunction for faster complex phase-amplitude plots

I have gotten into the habit of plotting complex-valued functions on a plane using a color-function along the lines of ...
4
votes
3answers
178 views

How to compile a diagonal array efficiently?

For example, if we use some functions defined prior to Compile, we usually have the main evaluators in the compiled codes, pointing to the definition of the ...
0
votes
0answers
82 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 ...
15
votes
1answer
422 views

Mma 10: Half the parallel power (Mac Pro)?

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 ... Under v9.01 ...
0
votes
0answers
84 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. ...
13
votes
2answers
832 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 ...
56
votes
2answers
3k views

Shaving the last 50 ms off NMinimize

The epilogue: A paper where the below answer is used was published. The answer below is cited among the references:) The background: I have to fit an objective function for ~10 000 datasets in near ...
6
votes
3answers
230 views

Riffle and Partition

At some point I noticed that I was using Riffle and Partition together a lot. I would do things like ...
5
votes
1answer
213 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 ...
3
votes
1answer
88 views

Speed up MinimalPolynomial

My Mathematica code runs slowly MinimalPolynomial[Sqrt[2] + Sqrt[3]+ Sqrt[5]+ Sqrt[7]+ Sqrt[11]+ Sqrt[13], x] runs slowly, but the Maple version ...
2
votes
2answers
159 views

Alternative for MapThread in listable functions

How can I rewrite this more efficiently taking advantage of flo, dem, and Nsup being ...
6
votes
4answers
208 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 ...
86
votes
3answers
3k views

Performance tuning in Mathematica?

What performance tuning tricks do you use to make a Mathematica application faster? MATLAB has an amazing profiler, but from what I can tell, Mathematica has no similar functionality.
1
vote
0answers
70 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 ...
16
votes
5answers
1k views

How to speed up the function DelaunayTriangulation?

First define a function meshGrid to generate some points: ...
23
votes
3answers
625 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 ...
0
votes
1answer
129 views

Speeding up a function

This is un updated version of a previous (now deleted) post of mine. I need to marginalize a distribution. I was suggested to use the code in this thread. This works just fine, but the problem is ...
19
votes
1answer
1k 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?
0
votes
0answers
66 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 ...
0
votes
2answers
120 views

Make an effective projection of matrix

To best explain my problem, I will take the following example: Consider the following matrix : ...
10
votes
5answers
424 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 ...
1
vote
0answers
76 views
3
votes
1answer
159 views

Optimization of power tower fractal generator [closed]

I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list. Here is my code : ...
2
votes
3answers
225 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 ...
3
votes
0answers
129 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, ...
0
votes
0answers
46 views

Expectation taking unusually long to evaluate

I am trying to evaluate an expectation, but it is taking an extremely long time although the expression itself should not be too complicated. My code is ...
10
votes
1answer
290 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 ...
0
votes
1answer
84 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 ...
6
votes
4answers
357 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 ...
7
votes
3answers
323 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 ...
1
vote
0answers
35 views
5
votes
2answers
82 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 ...
3
votes
1answer
71 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 ...
27
votes
3answers
584 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 ...