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)

1
vote
1answer
187 views

Performance of compiled functions (Project Euler No14)

I was playing around with the project euler problem 14. The solution I came up with is listed below as cf1. The solution works fine but I get the compiler warning: ...
0
votes
0answers
101 views

Speeding Up Image Processing Functions

I am working with stacks of 1024x1024 timelapse microscopy images that I am performing a series of image processing functions on to help segment each image. These functions include ...
7
votes
1answer
140 views

Speed up adding Poisson noise to an image

I'm simulating some images corrupted with Poisson noise, but I'm encountering a few problems with performance. According to the documentation on ImageEffect, one ...
5
votes
1answer
101 views

Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
0
votes
0answers
95 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 ...
8
votes
4answers
259 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
71 views

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

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
65 views

strange timing behavior

The following code is from a book about Mathematica. ...
2
votes
3answers
96 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 ...
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
50 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 ...
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 ...
15
votes
1answer
425 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. ...
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 ...
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 ...
2
votes
2answers
161 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
209 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 ...
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 ...
5
votes
1answer
215 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 ...
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 ...
1
vote
0answers
77 views
23
votes
3answers
632 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 ...
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 ...
0
votes
0answers
47 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
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 ...
0
votes
1answer
86 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 ...
3
votes
0answers
130 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, ...
6
votes
4answers
359 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 ...
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 ...
1
vote
0answers
35 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 ...
5
votes
2answers
83 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 ...
7
votes
3answers
326 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
103 views

Are there any plans to develop Wolfram OS? [closed]

Are there any plans to develop Wolfram OS? Google has developed Chrome OS/Chromium OS dedicated to easy and fast access to the web. Valve has developed Steam OS that created primarily for playing ...
1
vote
0answers
108 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. ...
13
votes
2answers
833 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 ...
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?
1
vote
1answer
92 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 ...
1
vote
0answers
38 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
0
votes
1answer
88 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, ...
1
vote
2answers
200 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: ...
0
votes
0answers
38 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 ...
10
votes
0answers
110 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: ...
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 : ...
1
vote
1answer
52 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)$ ...
10
votes
2answers
540 views

Faster “stuttering” accumulate?

Given some list of arbitrary precision numbers, e.g. (actual lists are 1M+ elements long): test={0, 2, 2, 47839283, 2, 0, 0, 2, 0, 1, 2, 0} I need to accumulate ...