Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 encountered yet. Where (books, websites, etc.) do I look for examples of good (best?) practices of Mathematica programming?

share|improve this question

10 Answers

up vote 190 down vote accepted
+100

Here's a collection of resources that I started on Mathgroup (A collection of Mathematica learning resources ) and updated here at StackOverflow. As this site is dedicated to Mathematica it makes more sense to maintain it here. This represents a huge amount of information; of course it's not exhaustive so feel free to improve it! Also, don't hesitate to share it and suggest other interesting links! Remember, you can always search the online Documentation Center of Mathematica, that is identical to the built-in help of the latest software version.

Links to more advanced aspects of the program that you can start to appreciate once you understand the basics are provided in a separate answer (below) as this post became too large.
Tips and Tricks

Introduction

Basic advices for people new to Mathematica

Functional style

Avoid iterative programming using loops like For or Do, use instead functional programming functions Map, Scan, MapThread, Fold, FoldList, ... and pure functions. This makes the code cleaner and faster.

Transpose and dimensions

  • Something not easy to guess alone at the beginning: if you have x={1,2} and y={3,4}, doing Transpose[{x,y}] or {x,y}ESC tr ESC in the front end will produce {{1,3},{2,4}} (format compatible with ListPlot). This animation helps understand why.

  • You can also use the second argument of Transpose to reorder the indices of a multidimensional list.

  • Don't forget to regularly control the output of the lists you generate using Dimensions.

Get familiar with shorthand syntax (@, &, ##, /@, /., etc.)

Programming easily

  • Getting help: Execute ?Map for example for a short description of a function, or press F1 on a function name for more details and examples about it. You can solve many problems by adapting examples to your needs.

  • Auto-completion: Start typing the name of a function and (in Mathematica 9+) select from the pop-up auto-completion menu, or press Ctrl+k to get a list of functions which names start with what has already been entered. Once the name of the function is written completely press Ctrl+Shift+k (on Mac, Cmd+k) to get a list of its arguments.

  • Function templates: In Mathematica 9, after typing a function name, press Ctrl+Shift+k (on Mac, Cmd+Shift+k) and click on the desired form from the pop-up menu to insert a template with named placeholders for the arguments.

    Other useful shortcuts are described in the post Using the Mathematica front-end efficiently for editing notebooks.

  • Use palettes in the Palettes menu especially when you're beginning.

  • In Mathematica 8, use the natural input capability of Wolfram Alpha, for example type "= graph 2 x + 1 between 0 and 3" without the quotes and see the command associated with the result.

Tutorials

FAQ

Books

Wolfram Websites

Learn

Examples

Resources

Blogs

Other related sites

Virtual conferences

Mathematica one liner competition

Wolfram technology conferences

Blogs

Personal websites

Calculus

Resources on other languages

Forums

MathGroup

Stack... sites

Links to some packages

Packages for preparing publication-quality scientific figures

  • LevelScheme by Mark Caprio (latest version: 3.52, Sep 2011, for Mathematica 6 and higher)
  • Presentations and other packages by David Park (latest version: 25 Aug 2011)
  • A WorkLife Framework by Scientific Arts LLC (extendable and customizable toolset that broadens Mathematica's scope across many aspects of daily work)
  • FeynArts by Thomas Hahn (latest version: 3.7, 27 Mar 2012, package for generation and visualization of Feynman diagrams and amplitudes)
  • Writing and Publishing a Book with Mathematica by Paul R. Wellin (2005, available from the Wolfram Library Archive)

Useful non-free tools for development, deployment, distribution, linking, etc.

  • Workbench by WRI, current version: 2 (official Mathematica IDE based on Eclipse, great for projects involving several packages and generating integrated documentation)
  • webMathematica by WRI, current version: 3 ("Deploy high-powered applications as interactive websites")
  • gridMathematica by WRI, current version: 8 ("Easily control CPUs and GPUs to solve large problems fast")
  • SystemModeler by WRI, current version: 3. Integrated symbolic modelling platform.Some related links: MathModelicaPaper, ObjectMath, Modelica
  • Finance Platform by WRI, current version: 1. Includes option pricing, risk analysis, enterprise system development, and interactive reporting
  • Mathematica Applications and Add-Ons (all add-ons marketed via WRI, related to Mathematica)
  • Mathematica Link for Excel by Episoft, Inc., current version: 3.5 (links Microsoft Excel with Mathematica)
share|improve this answer
14  
Apparently, this is the most edited post by a single person across all of the SE network. You've really done a remarkable job at maintaining it! – rm -rf Jul 17 '12 at 19:36
Thanks, maintaining this list is a good way also to keep track of interesting posts on this site that summarize well some aspects of Mathematica. – Faysal Aberkane Jul 18 '12 at 11:50
Is there a way to download the videos from wolfram.com/broadcast? – becko Oct 18 '12 at 14:37
@becko it's not too hard - like downloading YouTube videos, there are various ways. On Mac Safari, I set the user-agent to iPad before going to the page, then Download Linked File: this gets the mp4 download link. (No Flash for me!) – cormullion Nov 7 '12 at 15:22
@cormullion Got any tricks that work on Windows? I usually download videos from Youtube using a little program called Free Youtube Download. But that doesn't work on wolfram.com/broadcast (except for a few videos at wolfram.com/broadcast that are actually hosted on Youtube). – becko Nov 7 '12 at 18:15
show 3 more comments

My original post above became too big so I'm splitting it in two posts. The tips and tricks section that I used to keep track of interesting new posts mostly on this site was big so here it is.

Note the tags at the end of each question on this site in order to read related questions.

Tips and tricks

General tricks

Tips for writing faster code

Reap and Sow

Compile

Using links to other languages

Packed arrays

Debugging

Data Structures

Traversal of an expression

Graphs

Optional Values

Accessing data in different ways

Rules and replacement (the backbone of Mathematica, more advanced)

Advanced evaluation of expressions

Getting ideas from Lisp

Pattern matching

A pattern is a way to quickly describe the structure of expressions and do computations on them, using /. or Cases for example.

Memoization/Caching

Undocumented features

Mathematica functions and environment

Manipulate

Palettes

Finance (but not only)

Correlation

Proba/Stats

Misc

Neat algorithms

share|improve this answer
3  
Now this is really useful, big +1. The better we categorize all these resources, the more effective this page will be. – Leonid Shifrin Jul 25 '12 at 10:55
1  
This could be the Table of Contents of Mathematica.SE. – István Zachar Mar 11 at 16:54
1  
This is such a fabulous resource, thank you for taking the time to compile it. – Keshav Saharia Jun 3 at 8:11
You welcome, this list is a way to remember posts I don't want to forget, and this can be useful to anyone also, from beginner to advanced. It's made possible thanks to StackExchange and the possibility to edit posts. – Faysal Aberkane Jun 3 at 14:00

I highly recommend examining the included packages under your Mathematica installation directory:

\AddOns\ExtraPackages

\AddOns\LegacyPackages

\AddOns\Packages

\AddOns\Applications

You can also find both examples of good practice, framework guidelines, and insider methods in the presentations from various Mathematica conferences. A mere sampling:

1999 Mathematica Developer Conference

2003 Mathematica Developer Conference

2007 Wolfram Technology Conference

Many, many more.

share|improve this answer

Besides the documentation, which I find very helpful, I also like the following resources:

  • The Wolfram Demonstrations Project is a fantastic resource, where you can draw up previously successful programs and learn some best practices. Their utility has varied, but I've certainly learned a lot by seeing great code in practice.
  • In a similar vein, I also follow the 'Wolfram Blog'. It's not all universally relevant for my own interests, but following it on Twitter is a good way to dip in here and there.
  • Finally, as a new user, I also draw on the Mathematica Cookbook for some nifty examples.

As noted above, however, I normally use the documentation and look through examples of uses, as that's my best way of learning.

share|improve this answer
4  
I find code on demonstrations web pages hard to read actually. There is almost no comments in most of the demos there, so it is hard to understand the algorithms, and the code formatting makes it very hard to read. Mathematica needs a pretty print type formatting for the code. This way one can download a demo, or any other code, and reformat the code so it is more easy to read. I like the code to be spread out a little, with some white space between things so I can more easily understand it. – Nasser Jan 18 '12 at 11:56
1  
+1 for the cookbook but I agree with @Nasser on the readability of the demonstrations (plus, doing everything in one giant code block as demonstrations seem to organize things is probably not going to scale very well for anything nontrivial) – acl Jan 19 '12 at 13:26

For neat tips and tricks, there is a daily tip posted to the MathematicaTip twitter page.

share|improve this answer
1  
This is a pretty good resource. It has lots of small, easy to digest snippets. – Mike Bantegui Jan 18 '12 at 4:44

Nobody's mentioned the packages that come with Mathematica. There's a heap of great coding examples in there, especially the later packages.

share|improve this answer

The Mathematica GuideBook by Michael Trott always gives me lots of inspirations. Beside of it (and other places been mentioned above), I like exploring the SystemFiles folder. Some interesting tricks (especially about interface and FrontEnd) are hiding there.

share|improve this answer
The SystemFiles suggestion is a good one. Do you have any particular examples to share? – Verbeia Jan 18 '12 at 2:28
@Verbeia Some undocumented things can be learned from the system files. such as "SyntaxColoringReasons" for CurrentValue which can be seen in WhyTheColoring.nb (Dynamic[CurrentValue[InputNotebook[], "SyntaxColoringReasons"]]), system fonts classification which can be seen in UnicodeFontMapping.tr, some inappropriate converting when import GBK encoded Chinese text can be corrected by manipulating CP936.m, etc. – Silvia Jan 18 '12 at 11:49

In my opinion, rules and pattern matching are central to mastering Mathematica. I strongly recommend Demystifying Rules by Nancy Blachman published in The Mathematica Journal, Volume 8, Issue 4, for a solid grounding in this area. It is available on-line at The Mathematica Journal

share|improve this answer

The 'Mathematica GuideBook' series by Michael Trott has tons of good examples that go much further than typical 'toy-examples'. I found it a very valuable and thorough ressource for learning the ins and outs of the Mathematica language.

share|improve this answer

Not strictly a Mathematica blog but Rip’s Applied Mathematics Blog is a very nice resource for advanced Mathematica problem solving. Rip makes regular weekly posts on whatever interests him that week and they usually include some neat implementation in Mathematica.

And another very good reference Mathematica blog by Kris Carlson with interesting methods and examples:

share|improve this answer
1  
+1, though not much about Mathematica. – Artes Apr 22 '12 at 13:49
1  
If bewildered one should look into examples rip94550.wordpress.com/2012/04/16/… – Artes Apr 24 '12 at 12:03
1  
Thanks this blog is very interesting. – Faysal Aberkane May 1 '12 at 14:17
Yes Artes the examples come out weekly and usually cover some foundational applied mathematics concepts. – R Hall Jun 9 '12 at 13:14

protected by rm -rf Dec 6 '12 at 4:56

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.