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.
11
votes
2answers
443 views
Google Code Jam: Mountain View code review
After participating in Google Code Jam 2012 Round 2, it occurred to me that the Mountain View problem boiled down to solving a set of linear inequalities, which could be done in Mathematica. I've only ...
11
votes
2answers
123 views
Triggering actions when a variable is set
Some built-in variables trigger actions when their values are changed:
...
11
votes
1answer
142 views
How to implement FittedModel like objects
In the course of making some RLink wrappers I want to have some richer containers like Mathematica does with its FittedModel ...
11
votes
3answers
451 views
Big-Oh Notation
Is there a way to have Mathematica understand Big-Oh notation?
For example, I want something like:
MinBigOh[...]
where
...
11
votes
2answers
195 views
Listing subgraphs of G isomorphic to SubG
If I have an undirected graph G, how could I write a function in Mathematica to obtain a list of subgraphs of G that are isomorphic to some other undirected graph SubG?
I'd like to learn how to ...
10
votes
3answers
385 views
What is Mathematica's equivalent to MATLAB's filter function?
The MATLAB code
filter(0.5,[1, -0.5], [1:10])
is equivalent to
Rest@FoldList[(#1 + #2)/2. &, 0, Range[10]]
I don't ...
10
votes
4answers
490 views
How to write this without For loop
Suppose I have a few lists of numbers and want to exponentiate element-wise, then sum up everything into a polynomial.
For example, if I have
...
10
votes
3answers
339 views
How to modify function argument?
Usually in programming languages, function arguments are normal local variables, which can be modified.
Is this not true in Mathematica?
...
10
votes
3answers
376 views
1D Random Walk variant
I am making a notebook that is a variation to the traditional 1d random walk problem.
The normal 1D random walk can be simulated easily by
...
10
votes
3answers
226 views
How can I hold UpValues but evaluate other expressions?
Consider these definitions:
own = "OwnValue";
down[_] = "DownValue";
sub[_][_] = "SubValue";
N[n] = 3.14;
_[___, up, ___] ^= "UpValue";
The attribute ...
10
votes
2answers
226 views
ShearingTransform and Dynamic
Background: I have a geometric transformation composed of a RotationTransform, ScalingTransform and ...
10
votes
3answers
784 views
Programmatically generate packages from notebook files?
Currently, there are two ways I know of to generate a package (.m) file from a notebook file; one is to set the AutoGeneratedPackage option in the Option Inspector, ...
10
votes
1answer
220 views
Is it possible to use Begin and End inside a Manipulate?
May be someone can explain why I can't use Begin["context`"] and End[] inside a Manipulate ...
10
votes
3answers
267 views
Generating Linear Extensions of a Partial Order
Given a set $S$ and a partial order $\prec$ over $S$, I'm looking for a way to "efficiently" generate a list of linear extensions of $\prec$. Suppose the partial order is given by a ...
10
votes
1answer
89 views
Are formal characters like \[FormalA] to be used differently than other symbols?
I noticed that Mathematica has a set of special 'Formal' characters such as \[FormalA], \[FormalB] , etc.. In the front end, it ...
10
votes
3answers
145 views
Emulating Sequence with my own function
I just considered if/how one could implement Sequence in Mathematica if it were not predefined. It turned out that the following simple definition has in all my ...
10
votes
1answer
153 views
Modules that initialize themselves on first call
I use a lot of functions that extract a specific data item from a file with many data items. I want these functions to load data (slow) and return the item (fast) on first call, but just return the ...
10
votes
1answer
227 views
Using Apply inside Compile
In this great answer a compiled version of the Nelder-Mead algorithm is presented.
Since it works on arbitrary dimensions (i.e. arbitrary number of arguments), it has to use apply on the objective ...
10
votes
1answer
132 views
Evaluation indicator for a notebook
I have a GUI with a number of TabView and other Manipulate controls. Sometimes clicking from one Tabview to the other can take a while, and I would like to have a global "Please wait" indicator.
So ...
10
votes
1answer
117 views
Figuring out how AbsoluteOptions works with Graphs
I am puzzled by how AbsoluteOptions works with Graph objects. I would have expected that one could use it to obtain all the ...
9
votes
4answers
622 views
9
votes
3answers
148 views
Custom functions by delegating options in a specific way and using core functions
I'd like to create a custom function that does essentially the same as a core function of mathematica but uses different default settings.
Example: I want a Plot function that uses Mathematica's core ...
9
votes
4answers
260 views
Can a function be made to accept a variable amount of inputs?
I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
9
votes
3answers
366 views
Improve speed for calculating a recursive sequence
I want to calculate following recursive sequence:
$\alpha_{0}=0,\\
\cos(\alpha_{i})=\cos(\alpha_{i-1})\cdot\cos(\beta_{i})+\sin(\alpha_{i-1})\cdot\sin(\beta_{i})\cdot\cos(\gamma_{i}).$
In ...
9
votes
3answers
272 views
Dealing with nested options
OptionValue allows for recent versions of Mathematica (I think as from 7) to easily access optional parameters if they are explicitely given to a function or their default values otherwise.
For big ...
9
votes
5answers
339 views
Incrementing a number where each digit has a different base
Let's say I have a list, for instance {10,5,3}, indicating the bases for each digit of my 3-digit number. Using this basis, if I wanted to increment {8,4,1} a couple of times, here's what I would get:
...
9
votes
3answers
208 views
Comparing Mathematica expressions like diff
I am looking for a way to compare (or "diff") two Mathematica expressions, similarly to how to diff utility can compare two text files and report the differences.
Has anyone already written such a ...
9
votes
2answers
144 views
How can I build an inline documentation utility?
I often have a large function to which I add inline comments, but then I can't see the forest for the trees. How can I make a tool that extracts the comments and tokens within them to generate an ...
9
votes
2answers
130 views
How to make TraditionalForm display the same in the Manipulate output as in a notebook?
I noticed that TraditionalForm does not display as nice in the Manipulate output as in normal notebook. Is there a way to make it look the same?
Here is an example,
...
9
votes
3answers
382 views
How can I speed up SQL queries in Mathematica?
I have an application that queries a MySQL database many times for data. At the moment, Mathematica and MySQL are running on the same box and yet it takes over 1.6 seconds for the query to run and ...
9
votes
1answer
213 views
How can I add row and column header images to my TableForm output?
I am experimenting with the Eigenfaces algorithm and have my notes and experimental data collected in a Mathematica notebook. The result of an experimental run is a table of scores, where the smallest ...
9
votes
1answer
275 views
Modifying a List in a function in place
An example will be most specific:
func[list_, column_] := list[[All, column]] = Map[#*2 &, list[[All, column]]];
This throws errors.
I want to avoid doing ...
9
votes
2answers
267 views
Visualizing several long lists of numerical information to see relative frequency
Mathematica has very powerful visualization techniques. However, I'm at a loss at how to best make the following chart readable.
...
9
votes
1answer
400 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) ...
8
votes
7answers
280 views
How to efficiently Append a result of an operation on each element of a list to itself
I'm looking for the best function to apply the product of the last two elements of sublist elements to each element:
Example:
...
8
votes
4answers
470 views
Reproducing Image Patterns with Mathematica
Surfing on the net I stared at this pattern. It´s a bamboo steam, and it´s awesome. I'm new to Mathematica so I'm a little lost, I'd like to try to reproduce this pattern, of course in a very ...
8
votes
4answers
291 views
Passing large list by reference
I have the following problem: I would like to control evaluation of a variable that points to a list. For example, frequently in the code I have functions of the form that are supposed to work on ...
8
votes
3answers
201 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
2answers
211 views
How do I automatically evaluate a cell when a notebook is opened?
I'm trying to put together a GUI in Mathematica and need to evaluate one cell to kick that off. Is there a way to automatically evaluate that cell when the notebook is opened? Here is an example of ...
8
votes
3answers
105 views
What does `: Hold[$IterationLimit]` mean?
In this answer, what does the : Hold[$IterationLimit] part of the following construct do?
...
8
votes
2answers
176 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
373 views
shortcut key for traverse command history in a Mathematica session in a terminal?
I wonder what is the shortcut key for traverse command history (i.e. retrieve last, last last, ..., commands) in a Mathematica session in a terminal?
If I hit the up/down arrow or pageup/pagedown, it ...
8
votes
4answers
272 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
1answer
448 views
Poisson solver using Mathematica
I am looking for some help with a Poisson solver I am writing in Mathematica. The code is quite long with Arrays plugged in, so the full details can be found at http://pastebin.com/uSrSDcW6
I am ...
8
votes
1answer
283 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
375 views
GeoDirection and GeoDistance Memory Leaks: How to Recover the Memory?
The functions GeoDirection and GeoDistance have memory leaks. To see this, run the example functions below and watch as the Physical Memory Available in the Windows Task Manager, Performance tab, ...
8
votes
2answers
425 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 ...
8
votes
1answer
70 views
Notebook[] vs. DocumentNotebook[]; display a Notebook[] inline, like a DocumentNotebook[]
If you evaluate a DocumentNotebook[] expression in the front-end, it nicely displays inline, inside of an output cell in the current notebook:
For my purposes, ...
7
votes
5answers
310 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. ...
7
votes
3answers
308 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 ...


