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

5
votes
1answer
345 views

How to create FORTRAN Cell?

I want to create a FORTRAN cell in Mathematica. ...
12
votes
1answer
611 views

How to monitor the progress of Map?

I have a function doSomethingComplicated[...] that takes about 10s on average to evaluate. My list, listOfArgs has about 10000 ...
4
votes
2answers
2k views

Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual ...
6
votes
0answers
115 views

What are some general strategies to avoid using For loops? [duplicate]

Possible Duplicate: Iterating over lists in Mathematica While there are some cases where a For loop might be reasonable, it's a general mantra – one I ...
4
votes
1answer
239 views

Symbolic bit vectors

I'd like to see how addition and xoring bitvectors mix together. To do this, I implemented (a primitive) vec_add and vec_xor: ...
7
votes
1answer
374 views

How to create a multi-selectable setterbar with colored buttons

Background: consider the following code-snippet. ...
7
votes
1answer
951 views

Efficient backtracking with Mathematica

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ...
22
votes
1answer
2k views

Programmatically retrieving e-mails from a remote server

Mathematica has a function for sending mail (SendMail) and can import the MBOX format. But what I'd like to do is ...
9
votes
2answers
911 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 ...
16
votes
5answers
667 views

Is this the most efficient way to round approximate integers to integers while leaving other Reals untouched?

This might seem like an overly simple question, but I need to specify custom plot tick marks as integers (no trailing decimal point) if they are approximately integers, but not if they are not. Using ...
19
votes
4answers
3k views

K-means clustering

In MATLAB, there is a command kmeans() that divides an array into $k$ clusters and calculates the centroid of each cluster. Is there any command in Mathematica to ...
1
vote
1answer
213 views

How do I slice an image of size “width × height” in n² pieces of size “width / n × height / n”?

Background: What I want is to make a jigsaw from an image. (A simple one where the pieces are polygons.) I have the following strategy in mind. Create a set of polygons and assign images (or just the ...
5
votes
2answers
232 views

Applying different color to result of a geometric transformation

Background: consider the following two snippets. ...
9
votes
2answers
970 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
1answer
828 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) ...
2
votes
3answers
169 views

Using Nest inside NestList

I need results like this: {Cos[Cos[x]], Sin[Cos[Cos[x]]],Cos[Cos[Sin[Cos[Cos[x]]]]], Sin[Cos[Cos[Sin[Cos[Cos[x]]]]]], ... } I've tried to use ...
13
votes
3answers
297 views

How to keep some of the results of the NestList

I'm using some iterative arithmetics to calculate wave propagation with the help of NestList. I have to use a small step size for iteration to guarantee the accuracy, which lead to too much data (e.g, ...
4
votes
1answer
134 views

What it is the best way to enforce that only one CreateDialog window can be created?

Background. See question Moving controls from Manipulate to a Palette ( or similar GUI object ). As suggested in the answer to this question I use a CreateDialog window to group and handle controls ...
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 ...
2
votes
1answer
271 views

Can Mathematica help a theorem to be alive?

We are used to do limits by means of $\epsilon, \delta$. This is the first step an student encounters limits. Using $\epsilon$ and $\delta$ leads him to be familiar to Logic. I have taught limits and ...
7
votes
1answer
304 views

Is it possible to construct a function to make a poor man's Mathematica database?

I have a function that is set up to write to a database with 10-20 standard variables with 10 fields each, but the application is going to a place where database access is not available. Can ...
11
votes
3answers
174 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
628 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
252 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 ...
24
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
479 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. ...
28
votes
1answer
477 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
423 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
895 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
671 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
229 views

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

Consider the following snippet as a reference. ...
6
votes
1answer
158 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 ...
21
votes
4answers
794 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
230 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
1k 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
944 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 ...
11
votes
2answers
602 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
258 views

ShearingTransform and Dynamic

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

PaneSelector and options in a Module

Consider the following snippet of code: ...
23
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
561 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
265 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
637 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
686 views

LocatorPane and PlotRange

Consider the following snippet from the documentation on LocatorPane ...
35
votes
3answers
3k 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
718 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
528 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 ...
2
votes
2answers
244 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
109 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. ...