Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

learn more… | top users | synonyms

9
votes
1answer
179 views

How can I make CurrentValue for font characteristics pick up the font of the output not the input cell?

The command CurrentValue (documentation) allows you to access various properties of fonts, such as x-height, line height, and various measures of width such as ...
9
votes
1answer
878 views

Multi-objective genetic algorithm in Mathematica?

Is there any implementation of a multi-objective genetic algorithm for Mathematica?
9
votes
2answers
916 views

How to calculate mix of 4 colors defined in CIELAB L*a*b* model?

I have 4 colors that I converted from RGB to CIELAB L*a*b* model. How can I calculate mix of these 4 colors when I have (L,a,b) for each such color? How can I ...
9
votes
1answer
398 views

Mathematica implementation of Earth Movers Distance?

Has anyone implemented in Mathematica the Earth Mover's Distance (EMD)? A concept dating back to Monge 1871, used to compare histograms and images, e.g., the CIEDE2000 Color Difference algorithm. ...
9
votes
1answer
125 views

How to get control over DepthFirstScan?

Is there a way to conditionally take control the flow during a depth-first scan against a TreeGraph? I have a tree graph whose nodes are constructed as object, and there's a method ...
9
votes
0answers
151 views

Can code optimize code?

Are there functions, programs or packages that deal with optimizing mathematica code i.e. re-writing ineffecive or convoluted code. -This question has haunted me since I joined SE. The background for ...
8
votes
5answers
360 views

How to distinguish between lists and values?

I have a (hopefully small) problem with some numerical integration algorithm, more specifically I want to integrate the imaginary part of a complex valued function, e.g. ...
8
votes
7answers
633 views

Populate an upper triangular matrix from a vector of elements

What is the best way to populate an upper triangular (or alternatively: lower triangular or symmetric) matrix from a vector of elements? This example input: ...
8
votes
4answers
498 views

Efficient code for the Ten True Sentences puzzle

I am trying to solve Ten True Sentences Puzzle. Take a look at the following sentences: The number of times the digit 0 appears in this puzzle is _. The number of times the digit 1 ...
8
votes
2answers
1k views

Dynamic graph visualisation using JLink/Java and GraphStream

Visualising the addition of new nodes and edges to a graph to 'watch it grow' is to something Mathematica is not suited to by default. However this type of animation really helps convey the emergence ...
8
votes
3answers
269 views

Pairwise distances of points and classification using GraphDistanceMatrix

The challenge Given $n$ points in $\mathbf{R}^3$ and a cutoff distance, $d$, I would like to determine all pairs of points that are separated by less than the given cutoff distance, $d$, and all ...
8
votes
3answers
305 views

Find the best parallel lines to a given data set

I have a set of data in an uptrend. I would like to find two BEST parallel lines to contain all the data but I don't know how to approach it, anyone can help ? Thanks.
8
votes
1answer
3k views

Mathematica Bifurcation

Continuing with the same question I have posted earlier I would like to find the equation of the stable fixed point curve using my graph, i.e. from the curve somehow find the equation for $x=f(x)$. I ...
8
votes
2answers
1k views

ParallelTable and Table do not give same result

I have a question regarding the use of Parallelize. In the help one can read that “Parallelize[Table[expr,iter, …]] (which is ...
8
votes
3answers
209 views
8
votes
2answers
294 views

Recursive partitioning: Is there a better way to do this?

Consider the following function, which recursively splits a list into equal length sublists (the length of the list is assumed to be a power of the second argument): ...
8
votes
3answers
255 views

Grid without lines, but with dots

I want to build a grid to look like the top-left table shown below, but without an outside frame. Here is what I've tried to do: ...
8
votes
1answer
116 views

CSS Selectors for Symbolic XML

Symbolic XML is a convenient way of managing XML in Mathematica, at least for casual use or small tasks. Here and elsewhere you can find examples of XML handling in Mathematica, including XSLT/XPath ...
8
votes
3answers
322 views

Patternmatching sets

How to match set-patterns against sets? A set (in the mathematical sense) is a list of elements without repetition and order of elements does not matter. For example, we have a pattern set ...
8
votes
2answers
251 views

Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery

Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing. Using Rule as ...
8
votes
2answers
302 views

Get rational and irrational parts

Consider an expression of the form $a + b \sqrt{2}$, where $a,b \in \mathbb{Q}$. How can I extract $b$ (or equivalently $a$) from this expression?
8
votes
4answers
432 views

Best way to modify values in a list of rules?

Recently I had to solve a problem similar to this: Let's say I have a list of list of rules ...
8
votes
2answers
300 views

Restrict Sensitivity of Locators in LocatorPane

We can restrict the movement of locators in a LocatorPane as follows: In the following example, the first locator's movement is confined to the x-axis and the ...
8
votes
1answer
322 views

What is a good coding style for setting and changing application level constants?

Background: Every application has user-definable constants. The Java language has the Properties class to handle them. Question: What is a good and re-usable coding style for setting and changing ...
8
votes
1answer
304 views

Why does Mathematica choose the second function definition?

While working on a solution to this question I've come across a case where I simply don't understand Mathematica's behaviour. I've got the following definitions: ...
8
votes
1answer
124 views

Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?

Consider the following expression: Block[{Print = CopyToClipboard}, doSomething[]] Now all calls to Print from ...
8
votes
1answer
83 views

Aborting from inside a Dialog

Suppose I got in a Dialog and wanted to not Return but Abort the computation. How could I do ...
8
votes
1answer
142 views

Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
8
votes
1answer
393 views

Using NETLink.MathKernel.Compute() for graphics results fails with GraphPlot[]

I'm using MMA 8.0 to provide backend on a .NET application I'm writing. I am trying to use the high-level Wolfram.NETLink.MathKernel interface to export an image ...
8
votes
1answer
829 views

(Non-Convex) Polygon Union and Intersection Functions [duplicate]

Possible Duplicate: Intersecting graphics Back in 2009 I posted a question in comp.soft-sys.math.mathematica looking for a function which generates the union of two (not necessarily convex) ...
7
votes
3answers
295 views

Unencoding encoded URLs in a function

Is there a built-in function for decoding encoded URLs in Mathematica? I would like to convert an encoded URL, for example ...
7
votes
6answers
419 views

How to build a list of functions

Having said that I'm no expert, I have some problems in generating a list of functions inside a loop. The functions in the list should depend on the elements of a parameters list, that are read in ...
7
votes
4answers
438 views

How to set Block local variables by code?

I need to create a user-defined Block function where the Block variables' values are defined by code. For example, imagine I ...
7
votes
3answers
759 views

Filtering elements from a list

Suppose that I have a list {{{2, 1}, {4, 3}, {2, 4}}, {{2, 1}, {4, 3}, {3, 1}}, {{2, 1}, {2, 4}, {3, 1}}, {{4, 3}, {2, 4}, {1, 2}}} I want to make a new list ...
7
votes
5answers
399 views

Computing the average over the values of the boxes surrounding a box in a grid

Recenty,I encounter a problem described as below: I have a table that owns many boxes,and each box has a sequence like 1,2,3,4,etc.In addition,every box has a value. Now I want to make the ...
7
votes
2answers
280 views

What's the purpose of the Unique function?

As the title says: What's the purpose of Unique? I understand that it generates some unique symbol, but when and for what is it to be used? Are there applications ...
7
votes
3answers
753 views

Programming Mathematica in plaintext, i.e. no formatting, non-notebook

I'm new to Mathematica and I've just begun reading Paul Wellin's Programming in Mathematica. The book, like many other books and online tutorials, revolves around using the notebook, with all its ...
7
votes
2answers
2k views

How to define a differential operator?

I have a linear differential operator, for instance, $L\left (\partial _{t} \right )=\partial _{tt} - 3\partial _{t} + 2$. I use it in 2 different ways: apply the operator to a function: $L\left ...
7
votes
3answers
383 views

how to read in a file in the same directory?

Now I am writing a small package. I have written several files and put them in the same directory. And some files need to read in or include another file in the same directory. But when I simply write ...
7
votes
3answers
467 views

Rewriting For loop to FoldList or similar

In CrossValidated, the answer to a question on prediction of number of viewers of Gangnam Style is given in R. I have mapped the answer directly to Mathematica: ...
7
votes
2answers
341 views

find subsequences of constant increase

A list like l = {0, 1, 2, 3, 4, 5, 7, 9, 12, 13, 18, 19} may have subsequences of constant increase, $a_{n+1} = a_n + k$. For example: ...
7
votes
2answers
415 views
7
votes
2answers
1k views

Easier program for period of Fibonacci sequence modulo p

For a little project I need to calculate the period of a Fibonacci sequence modulo p, for which p is a prime number. For example, the Fibonacci sequence modulo 19 would be: $$0, 1, 1, 2, 3, 5, 8, 13, ...
7
votes
3answers
491 views

Threading a compiled function over multiple arguments of different lengths

I am interested in threading a compiled function over multiple argument lists of different lengths. I will explain this in two steps: Suppose f is some function. Then one can define another ...
7
votes
2answers
230 views

Moving controls from Manipulate to a Palette ( or similar GUI object )

Consider the following snippet as a reference. ...
7
votes
2answers
192 views

Speed up Fourier for Booleans

I'm calculating a bit of the power spectrum of a two color cellular automaton using: ...
7
votes
1answer
804 views

Handling failed FindRoot calls

I want to handle FindRoot calls which did not converge (e.g "thrown" error message FindRoot::cvmit) ...
7
votes
3answers
415 views

RecurrenceTable not evaluated: mathematica just echoes input

Forgive the newbie question... I am trying to create a table of the following system, following the Stirling example in the documentation, but Mathematica just echoes my input. What am I doing wrong? ...
7
votes
1answer
296 views

Find a word's linguistic pronunciation

Is there a way to get a word's linguistic pronunciation given the word as a string? I would like a function LingusticPronunciation such that, for example, ...
7
votes
3answers
491 views

NDSolve and {C, K, Slot} and other built-ins as a variable name

The following problem is an exploration of what causes the error "Input is not an ordinary differential equation" in Mathematica as it seems to have changed from version 8 to version 9. Specifically ...