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

11
votes
3answers
178 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 ...
14
votes
4answers
705 views

Implementing a function which generalizes the merging step in merge sort

One of the key steps in merge sort is the merging step. Given two sorted lists sorted1={2,6,10,13,16,17,19}; sorted2={1,3,4,5,7,8,9,11,12,14,15,18,20}; of ...
5
votes
3answers
289 views

HoldFirst and inserting additional options into a Grid of Graphics

This is related to my earlier question, but is specific to an issue I have encountered with the use of the HoldFirst First, let's create some fake data for ...
26
votes
2answers
1k views

Do I have to code each case of this Grid full of plots separately?

I have written some custom functions to draw multi-panel graphs like this one: It's done by passing a matrix of (custom) plotting functions to a MultiPanelGraph ...
5
votes
5answers
556 views

How can I use nested conditionals inside my functions?

I'm a big fan of using conditionals inside my functions to deal with cases, that is, to pattern match in stages and possibly leave a function unevaluated. ...
30
votes
1answer
529 views

What can I use as the second argument to Return in my own functions?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in ...
2
votes
4answers
477 views

Using the result of Solve in subsequent calculations

I'd like to know how to use the results of Solve in later calculations. Here's what I'm doing now: This is my expression ...
2
votes
2answers
979 views

optimization problem with NDSolve

I want to minimize the function fcc. When fcc is calculated for a specified point the answer is correct: ...
2
votes
1answer
777 views

Optimizing a function involving NDSolve results in error messages

I want to minimize a function f with NMinimize but an error occurs that says: ...
36
votes
2answers
2k views

Performance tuning for game solving (peg solitaire | senku)

There's a game I saw at a friend's yesterday, that I often see at people's homes, but never for enough time to think on it too hard. It's called peg solitaire (thanks @R.M). So I came home and I ...
7
votes
2answers
261 views

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

Consider the following snippet as a reference. ...
6
votes
1answer
161 views

How can I make sure all InputFields have values before processing a nb form?

This is a two part problem: I have a form that accepts both numeric and text inputs, then runs a function using a "process" Button. The issue I'm having is users that forget to fill out all of the ...
26
votes
4answers
990 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 ...
0
votes
1answer
250 views

Graphics copy paste

Background. I have a function ( stored in a package ) that creates 2D graphic images, its prototype looks like this: ...
6
votes
1answer
2k views

How can I implement object oriented programming in Mathematica?

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.
21
votes
3answers
1k views

Suitability of Mathematica as platform for engineering calculations and programs

I am considering using Mathematica with Wolfram Workbench as a standard platform for calculations and programs in a large engineering department. I am looking for a solution that would provide better ...
12
votes
2answers
650 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
261 views

ShearingTransform and Dynamic

Background: I have a geometric transformation composed of a RotationTransform, ScalingTransform and ...
2
votes
1answer
93 views

PaneSelector and options in a Module

Consider the following snippet of code: ...
24
votes
2answers
2k views

Debugging memory leaks

I've written my incredibly complex, incredibly elegant analysis function, that works great on small test data. But when I run it on my real (bigger) data set it keeps running out of memory. It turns ...
12
votes
5answers
596 views

Mathematica quine

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. There are many trivial quines in Mathematica: ...
6
votes
1answer
284 views

LocatorPane and multiple EventHandlers, PassEventsDown option

Consider the following piece of code from Heike as an ( accepted ) answer on LocatorPane, selecting multiple Locators - Basically the code implements dragging polygons on a LocatorPane. ...
9
votes
3answers
709 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 ...
19
votes
3answers
731 views

LocatorPane and PlotRange

Consider the following snippet from the documentation on LocatorPane ...
36
votes
3answers
4k views

How to create a progress bar?

I would like to create a progress bar tool that allows me to see how my computations are going. I found answers to this question on many sites, I even found a package for it ( ...
23
votes
3answers
763 views

Is using undocumented functionality a Bad Idea™?

Mathematica has a lot of very useful undocumented features. For example a hash table, a built-in list of compilable functions, additional options to CurrentValue, ...
23
votes
1answer
559 views

On drilling holes with minimal redundancy (and with colors!)

The old Mathematica package Graphics`Shapes` featured the function PerforatePolygons[], which drilled a hole in any ...
3
votes
2answers
262 views

Question about MapThread and Dynamic

I don't understand the following: f[a_, b_] := a + b ls = {1, 2, 3}; MapThread[f, {ls, {10, 20, 30}}] This yields ( as expected ) {11,22,33} If I change ...
6
votes
2answers
111 views

How to define and work with temporary graphics data?

Background: I am working on a program that produces design patterns ( using wallpaper- and frieze-group theory ). This is for example a 'generating region' for a frieze or a wallpaper. ...
7
votes
2answers
444 views
6
votes
3answers
327 views

Question about modifying a Slider2D control

Background: I want to develop a custom control, based on a 2D slider. I currently have this ( working ) example. ...
6
votes
2answers
136 views

How do I access the name of a list in a function?

Background: bar := {1, 1, 1}; foo[var_] := {Hold[var], 2 var} SetAttributes[foo, HoldAll] foo[bar] Result, as expected: ...
30
votes
4answers
2k views

Finding a percolation path

I would like to examine percolation on a random lattice. To be exact, I wish to find the minimum length of a 'bond' needed such that the leftmost site can be connected to the rightmost site. Here is ...
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 ...
27
votes
4answers
1k views

Question about collections of custom GUI controls for Mathematica

Background: I have only recently begun programming GUIs in Mathematica, so I have a continuous need for custom controls. I needed a scrollable list control and with the help of Google I found a ...
11
votes
1answer
325 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 ...
4
votes
1answer
207 views

How to avoid conflicts between local variable names and symbolic arguments in Block constructs?

I am using Block inside the definition of some recursive functions. If the Block definitions use short variable names, like ...
1
vote
1answer
853 views

Iteration of a function

I have a function $f(x)=x^7+k$ I want to iterate $xn+1=g(xn)$, 50 times starting with $x0=1$ and keep the last 10 values I want to assign these values to a function ...
3
votes
3answers
404 views

How can I suppress Print in parallel evaluation?

When using a function that includes Print statements, one can suppress the output by ...
16
votes
1answer
339 views

Is pure pattern matching without PatternTest and Condition Turing-complete?

Note that this question is not a duplicate of that one. It is specifically about the pattern-matching engine, and explicitly excluding those patterns which call back into the full evaluation (i.e. ...
14
votes
2answers
1k views

Is Mathematica a Turing-complete language?

Is Mathematica a Turing-complete language? If so, how can that be proved? If not, why?
21
votes
2answers
372 views

What is the equivalent of a prototypical Manipulate in lower level functions?

Background: In the Mathematica tutorial 'Dynamic Interactivity' I read that there is a way of developing GUIs in Mathematica that do not use Manipulate. I want to ...
9
votes
1answer
299 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 ...
7
votes
2answers
200 views

Speed up Fourier for Booleans

I'm calculating a bit of the power spectrum of a two color cellular automaton using: ...
9
votes
3answers
429 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 ...
14
votes
3answers
780 views

Mathematica usage (success stories) for financial back-ends

I've been working for about 5 years in Java, developing financial back-offices (web-services, business logic, report generation etc.). I think Mathematica is very suitable for such calculations and ...
6
votes
2answers
504 views

Developing domain specific languages and computational knowledge engines using Mathematica

In one of Leonid Shifrin's excellent summaries, he mentioned that MMA capabilities include developing Domain Specific Languages (DSL). I'd like to develop a Health care IT application that can ...
29
votes
5answers
8k views

How to use Mathematica functions in Python programs?

I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function Prime. I had search about MathLink but how to use it in Python ...
0
votes
1answer
404 views

How to solve a problem in relative motion?

I have a project due tomorrow that I have been struggling with for a month. I am utterly stumped, any help would be appreciated. The problem is: There is a ferris wheel, 30m in radius, set 80m ...
17
votes
2answers
2k views

Open Excel file with Mathematica

I would like to open an Excel file and manipulate it as a COM object. While I'm able to open an instance of excel with ...