A short mathematica course

This is a short course in Mathematica, aimed at people who know how to program, but don’t know Mathematica. The course is given to incoming physics graduate students, but it shouldn’t be thought of as being at a graduate level - I think it’s pretty accessible.

The course is aimed at physicists so the examples are drawn from physics, and the course is weighted towards things that are useful in and around the lab. Most of it should be comprehensible to non-physicists though. In particular the first and last worksheets (see below) are very general, and make no reference to physics.

The course is structured as four worksheets that are part lecture notes, part problem sheet. You’ll find the worksheets and my solutions below. The course picks up after the Mathematica tutorials finish. You should know how to evaluate simple expressions, plot simple graphs etc before you start, at the very least.

If you find these worksheets useful or interesting, or you have comments on how they could be made better, then I’d love to hear from you. Finally, you should bear in mind that I’m no kind of expert, and the course has parts that are far from perfect that I’m not so happy with. So don’t blame me if anything here totally corrupts your understanding of Mathematica. But hey, it’s free, so you can’t complain too much!

The worksheets are compatible with Mathematica 7.0 and higher. It was last revised quite a few years ago (roughly in the Mathematica 9.0 era), so there are probably neater ways to do some of the stuff now (associations, in particular come to mind!).

Worksheets

Worksheet one

This worksheet introduces Mathematica’s way of doing things, with a particular emphasis on how it differs from the programming languages that most scientists know. It introduces functional programming, higher order functions, and expressions. It assumes no knowledge of physics.

Download worksheet.

Download solutions.

Worksheet two

This worksheet looks at the use of functions to abstract program structure. We look at how programs are built through what people call bottom-up design. This is illustrated in the context of experimental data analysis: importing and fitting data, simple statistics, and less simple statistics! Non experimental-science types might find the second half of this sheet a bit hard going and tedious.

Download worksheet.

Download solutions.

Worksheet three

The third sheet focusses on techniques for structuring data. Abstract data types are considered, and then a couple of easy to use data structures are built. This is done in the context of simulating a simple experiment: the motion of ions in a Paul trap. This will be a bit opaque to non-physicists, but I suspect that it’s not too tricky to figure out what’s going on if you have the will.

Download worksheet.

Download solutions.

Worksheet four

The final worksheet is a bit of a beast. Here we look at what’s really going on inside Mathematica: we figure out what happens when you press shift+enter to evaluate an expression. This takes us on a whirlwind tour of: functional programming, expressions, values, term-rewriting, normal forms, and computer algebra. Along the way we’ll illustrate what’s going on by trying to build our own simplified version of Mathematica! Like worksheet one, no knowledge of physics is assumed.

Download worksheet.

Download solutions.