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

Alternative to overloading Set

In the ideas shared in my answer to this post Struct equivalent in Mathematica? at the end I propose a solution that changes the way Set works in a particular case that can be expressed in plain words ...
3
votes
2answers
179 views

Cleaning up a List of HTML Data to Render Usable Information

I am using Mathematica to scrape information from webpages. To get file information, I am gathering plain text that is enclosed by <tr> and ...
0
votes
1answer
136 views

FE`symbols that remain in notebook internals even after removing them and SaveDefinitions->True issue

How does one clear the notebook from symbols that remain in it after an edit session?
13
votes
2answers
788 views

Suppressing negative roots in Mathematica

Problem Using Mathematica's Solve operator can sometimes lead to an output involving a positive and negative root (say when solving for a variable such as ...
4
votes
2answers
215 views

How to Text justify string that includes SubScriptBox in it?

I am using Grid to document a demo I have. i.e. I am writing the documentation of the demo as a help option, which will display information when clicked on. Everything is working well. I am using the ...
72
votes
7answers
6k views

Struct equivalent in Mathematica?

I really miss having something like a struct in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a ...
9
votes
2answers
145 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, ...
3
votes
1answer
505 views

How to make GraphicsGrid with content tight inside it?

I am trying to use GraphicsGrid to typeset some labels for my plots. I found the labels look little better when I use GrapicsGrid vs Grid. The labels have equations in them and not just plain labels. ...
9
votes
3answers
490 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 ...
42
votes
6answers
2k views

Functions vs. patterns

Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
6
votes
3answers
301 views

How to eliminate the need to double evaluate a Manipulate so that a Module in its Initialization section works?

Using V 8.04 on windows. I think this issue might be related to the fact that Mathematica reads main body the Manipulate before evaluating or running the Initialization option. Or, might be ...
7
votes
1answer
366 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 ...
4
votes
2answers
257 views

How to close the front end so I can clear all Global variables?

I first thought that doing Quit[] in a cell, or Evaluation->Quit kernel, is supposed to remove all Global variables, but I have a case where this is not happening, then I read that there is a command ...
13
votes
1answer
358 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 ...
17
votes
4answers
377 views

Function that caches when it returns unevaluated

How would you go about implementing a function that caches not the result but the fact that it didn't match a pattern? So that it doesn't waste time recomputing a complex time-consuming pattern ...
6
votes
6answers
579 views

How can you give a Module a context and have its local variables and Modules belong to that context?

What would be the best way to give a module its own context and have its local variables and Modules belong to that context?
15
votes
2answers
375 views

Distributing PlusMinus consistently

I would like to give the built-in function PlusMinus, which is undefined by default, the intuitive meaning: considering all possible combinations of $+$ and $-$. ...
7
votes
2answers
265 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 ...
35
votes
4answers
2k views

How do I evaluate only one step of an expression?

I am looking for a simple, robust way to evaluate an expression only one step, and return the result in a held form. The definition of a single step is ambiguous, and this itself is probably worthy ...
39
votes
8answers
2k views

Updating Wagon's FindAllCrossings2D[] function

Stan Wagon's Mathematica in Action (second edition; I haven't read the third edition and I'm hoping to eventually see it), demonstrates a nifty function called ...
21
votes
3answers
1k views

Sum over n variables

What is the most painless way to sum over n variables, for example, if the range of summation is $i_1 < i_2 < i_3 < \dots < i_n$, where $n$ is an argument of the function in question? Is ...
53
votes
2answers
2k views

Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...
18
votes
4answers
551 views

Continuous evaluation of complex calculations

When having a first look at some system, it's often very useful to just play with the parameters and see how it develops. Therefore, I would like to let a certain evaluation run "until I cancel it". ...
34
votes
4answers
2k views

How can I implement dynamic programming for a function with more than one argument?

Dynamic programming is a technique for avoiding the repeated computation of the same values in a recursive program. Each value computed is immediately stored. If the value is needed again, it is ...
293
votes
12answers
52k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
39
votes
4answers
3k views

Creating Mathematica packages

I'm building a package to help me write packages and their documentation. In this post I explained how to make a package and its documentation. In the answer I provided I describe how to build a very ...
44
votes
2answers
1k views

What are the best practices / most common / idiomatic ways to report errors in Mathematica?

In particular, what are the best ways to report errors about incorrect arguments to a function? Checking for the correct arguments is relatively easy using patterns, but how to report an informative ...
85
votes
3answers
11k views

Alternatives to procedural loops and iterating over lists in Mathematica

While there are some cases where a For loop might be reasonable, it's a general mantra – one I subscribe to myself – that "if you are using a ...
38
votes
3answers
735 views

The clearest way to represent Mathematica's evaluation sequence

WReach has presented here a nice way to represent the Mathematica's evaluation sequence using OpenerView. It is much more clear way to go than using the standard ...
36
votes
4answers
3k views

How to change the default ColorData used in Mathematica's Plot?

This question leads on from the recent question What are the standard colors for plots in Mathematica? There it was determined that the default color palette used by ...
87
votes
3answers
3k views

Performance tuning in Mathematica?

What performance tuning tricks do you use to make a Mathematica application faster? MATLAB has an amazing profiler, but from what I can tell, Mathematica has no similar functionality.