Essential Mathematica for Students of Science

Tutorial Approach to Mastery of Mathematica

James J. Kelly
Department of Physics
University of Maryland
College Park, MD 20742

    Mathematica is a fully integrated system for technical computing.  Among the capabilities it offers are:

Within a Mathematica notebook you can develop solutions to complex problems that combine symbolic derivations, numerical calculations, and graphical displays in an interactive document.  The tools provided by Mathematica will help you focus more on conceptual development and visualization than on details of algebra or procedural programming.  Your solution can be documented and presented in a very appealing format using the typesetting tools provided by the front end interface.

    The materials provided here are based upon a course, PHYS426, that I have taught at the University of Maryland several times during the last few years.  The purpose of this course is to provide mastery of the Mathematica tools and techniques most relevant to scientists and engineers.  No prior familiarity with Mathematica is needed.  The course consists of a collection of tutorials that present concepts and practical techniques in a systematic fashion.  Many people, including many faculty, attempt to learn Mathematica in a very haphazard fashion, learning just enough of the basic syntax to evaluate a few integrals, perform simple numerical calculations, and make some basic graphs, without ever understanding how the system works.  Unfortunately, this approach often leads to frustration because it provides no basis for interpreting errors or unexpected output.  It also tends to produce rather inefficient and clumsy code.  Effective use of Mathematica requires training the mind to formulate problems in new ways, not just to apply new syntax to old methods.  If you take the time to work through the tutorials and exercises, you will understand the system well enough to use it both efficiently and creatively.  You will be amazed at how much you can accomplish with so little code, especially if you are a veteran programmer in traditional languages.  I now find Mathematica indispensable to my research productivity and am confident that you soon will also.

    The materials for this course consist of two types of notebooks.  Language notebooks present the basic concepts and techniques of the Mathematica system using relatively simple exercises.  Application notebooks present solutions to more interesting problems at considerably greater depth.  These notebooks are intended to illustrate the use of Mathematica for research in the form of polished documents which introduce a problem, outline the strategy for its solution, implement that solution, discuss interesting examples, and draw conclusions.  The language notebooks are designed to present Mathematica in a nearly linear fashion, building an edifice one block at a time, whereas application notebooks use whatever tools are needed to solve a particular problem or class of problems.  Therefore, applications may use features of Mathematica before they are covered in the course, but links to related course materials or to on-line documentation are provided where appropriate.  After all, in research one does not choose problems according to the tools at hand, but rather acquires the tools needed for a problem as those needs are recognized!  You are encouraged to jump back and forth between application and language notebooks.  The style of reading from page 1 to the end is passé.

    The notebooks may be accessed using the hyperlinks below.  To view the files directly, you must configure your web browser to launch either Mathematica or MathReader for files with the nb extension.  MathReader is a free program that will display or print a Mathematica notebook, but it cannot evaluate or edit notebooks.  Alternatively, you may download files to your computer and launch the application manually.  To ensure that the hyperlinks between notebook files work correctly, you must reproduce my file structure for the course.  

  1. Create a top directory for the course, such as c:\My Notebooks\tutorial course.  Save the file contents here.

  2. Create the subdirectories Primary topics, Additional topics, Applications, and Solutions.

  3. Save files below in the indicated directories.

The entire directory tree can be downloaded from EssentialMathematicaArchive or individual files can be obtained using the links tabulated below.  After downloading, the table of contents provides the simplest means of accessing course materials.  I recommend creating a shortcut to this file on your desktop.  If you open this file first and then use its hyperlinks to open other notebooks, the hyperlinks between notebooks should work properly.  Although you can open notebooks directly, hyperlinks between notebooks may not work properly that way.  Nor will these hyperlinks work if you open files from your browser without downloading them.  Nevertheless, you should be able to view and evaluate these notebooks if your browser has been configured properly.

    Most of the course materials originated in 1997, but undergo frequent revision as both Mathematica and the course evolve.  Dates for the last revision of each notebook are included in the listings for your convenience.  The most recent major revision was in January 2006, updating the notebooks for Version 5.2. 

Primary language concepts and techniques

Store these files in subdirectory Primary topics.

notebook description last revision
getting started Introduces the front end, help sources, input conventions, and some important functions. Jan., 2006
functions Basic programming tools and techniques.  Includes implicit and explicit functions, recursive techniques, scoping and loop commands, conditionals, etc. Jan., 2006
expressions Central concepts of the Mathematica language and its internal representation of expressions. Jan., 2006
lists Manipulation of the basic data structure and efficient programming. Jan., 2006
plotting Basic visualization tools and embellishments. Jan., 2006
algebra Manipulation and simplification of algebraic expressions, solutions to equations, eigensystems, etc. Jan., 2006
calculus Differentiation, integration, Taylor series Jan., 2006
diffeq Symbolic and numerical solutions to ordinary differential equations. Jan., 2006

Additional language topics and tools

Store these files in subdirectory Additional topics.

notebook description last revision
dimensional analysis Symbolic and numerical computations involving dimensioned quantities and their units. Jan., 2006
files Storing and retrieving information from files.  Uses sample data types, popclock, worldpop, worldhis, jjk Jan., 2006
complex Subtleties of algebra with complex variables. Jan., 2006
recurrence relations Recursive functions, dynamic programming, and stability of recurrence relations. Jan., 2006
InPolygonQ Develops a query to determine whether a point is within a closed polygon. Jan., 2007
packaging The strategy and mechanics of developing packages is illustrated with a specific example based upon earlier exercises about fractals.  Uses FractalsPrototype and Fractals. Jan., 2006


The files in this category should all be saved in the subdirectory Applications.  The tables below classify the notebooks further by topic or technique.


notebook description last revision
cicada A model describing the synchronized emergence of some insect populations. Jan., 2006
collisions Studies kinematics of nonrelativistic binary collisions, including inelasticity and mass transfer, and makes useful vector diagrams. Jan., 2006
Paschen Investigates the effects of magnetic interactions between the electron and proton in hydrogen and their interactions with an external magnetic field, known as the Zeeman effect for weak fields or Paschen-Back effect for strong fields. Jan., 2006
Markov A program for computing the equilibrium state of Markov processes in which the evolution of a system is governed by a transition probability matrix. Jan., 2006

Fractals and deterministic chaos

notebook description last revision
logistic map A nonlinear discrete model for the population of species with nonoverlapping generations that illustrates the phenomena of stable cycles, chaos, and order within chaos.  Introduces entropy and Lyapunov exponents. Jan., 2006
Functional programming is used to produce cobwebbing diagrams for iterated function systems, such as the logistic map. Jan., 2006
Koch Fractal properties of Koch curves. Jan., 2006
Henon The two-dimensional Hénon map produces a strange attractor. Jan., 2006
Julia Escape-time algorithm for Julia and Mandelbrot sets. Jan., 2006
JuliaIIM Inverse iteration methods for Julia sets. Jan., 2006
frequency analysis Discrete Fourier analysis of time series. General properties are discussed and applications are made to the van der Pol oscillator and to the logistic map. Jan., 2006

Differential equations

notebook description last revision
home run Uses numerical integration of a differential equation to investigate projectile motion with air resistance. Jan., 2006
pendulum Phase diagrams for driven pendulum with nonlinear restoring force and linear damping. Jan., 2006
Duffing Phase diagrams for driven anharmonic oscillator with linear damping.  The Poincaré map is used to study patterns within chaos. Jan., 2006
Volterra Uses predator-prey models to introduce linear stability analysis and limit cycles. Jan., 2006
van der Pol Limit cycle oscillation in nonlinear differential equation using linear stability analysis. Jan., 2006
FN model for BZ reaction Belousov-Zhabotinskii reaction, the prototypical chemical oscillator. Jan., 2006

Data analysis

The following files should be saved in the subdirectory Data analysis and constitute a minicourse in data analysis using Mathematica.  The MathLite notebook provides a very brief introduction to some of the features needed to use Mathematica in an introductory physics laboratory that can be covered in one lab period of about 3 hours.  The DataAnalysis notebook presents methods of linear and nonlinear least-squares and develops some simple programs that should be useful for such a course.  Improved versions of these programs are supplied in the package Curfit.

Store these files in subdirectory Data analysis.

notebook description last revision
MathLite Brief Mathematica introduction for physics laboratory. Jan., 2006
DataAnalysis Methods and code development for linear and nonlinear least-squares fitting. Jan., 2006
gep.dat A sample data file. Jan., 2006
Curfit.m Package containing improved versions of Linfit and Curfit for least-squares fitting. Jan., 2006

Physics problems

This is a small collection of solutions to assorted physics problems that illustrate a variety of numerical methods implemented within Mathematica.  A few more are under development but are not ready for posting.

Store these files in subdirectory Physics problems.

notebook description last revision
pde relaxation Relaxation method used for electrostatic potential near systems of electrodes in two dimensions. Major example: fringe fields, surface charge density, and capacitance for parallel-plate capacitor. Jan., 2007
bswf Shooting methods are used to find bound-state energies and wave functions for Schrödinger equation. Jan., 2007


Advice for students

The notebooks which comprise this book are intended to teach Mathematica by example and by practice. Ideally the course should be studied in a tutorial format in which an instructor guides students through a progression of exercises which develop skill and understanding through practice. However, if you are studying Mathematica independently, please work the exercises — do not just read the text and skip the exercises. Do not be discouraged if you have had negative experiences in the past with an instructor in one of your courses who expected you to learn Mathematica after just one or two lectures. It is only through practice that one can train the mind to approach problem solving in new ways and this takes time and patience. Mathematica provides many tools which will help you to solve and visualize problems in new ways, and these tools are well worth the effort needed to master them. The notebooks in this book will guide you toward mastery of the most important tools in Mathematica slowly, with exercises you can work at your own pace. By the time you complete the two core notebooks, getting started and functions, you will have acquired a solid foundation that will allow you to easily learn and apply the particular tools most appropriate to your needs. Take the time needed to understand the material presented in these notebooks well.

Advice for instructors

    This book arose from a course that I teach at the University of Maryland. Although I am a professor of physics, the course is intended for advanced undergraduate and beginning graduate students in any field of science, engineering, or mathematics. Thus, although many of the examples are naturally from physics, many examples are also drawn from mathematics (iterated functions and fractals), biology (population dynamics), and chemistry (chemical oscillators). The prerequisites are calculus and introductory physics.

    Too often students receive their first introduction to Mathematica in just one or two class periods of a course which uses Mathematica as one of the tools employed in the presentation of its primary subject. The unfortunate student is then expected to master new concepts, syntax, and programming techniques in a couple of hours. This impossible burden often alienates the student so completely that he or she abandons Mathematica once that course is finished. If any of your students have suffered through that experience, please reassure them that the tools provided by Mathematica are worth a considerable investment of effort and that your course will offer sufficient time and practice to acquire mastery of them. Mastery of Mathematica is like mastery of a second language — it requires time, patience, practice, immersion, repetition, and more patience. Any second language becomes much easier when a person begins to think in that language without having to translate every thought. Languages cannot be learned by passively listening to lectures, but require active immersion and practice.

    My course was taught in a teaching theater using a tutorial format. The teaching theater provides each student with a computer and the instructor with equipment to project the instructor's monitor, transmit the instructor's screen to each student monitor, and to view and/or project any monitor in the room. Networking software permits communication or collaboration between students and the instructor. Assignments were distributed and collected electronically. All materials for the course were presented in the form of Mathematica notebooks.  Most classes began with a brief introduction to the lesson of the day, with the instructor's monitor transmitted to the students. I would work through and discuss the appropriate section of a notebook, and then the students would work some of the exercises in that notebook as I circulated through the room offering help and suggestions where needed. If several students were experiencing similar problems, I might give hints to the entire class or might return to my computer and show how a particular problem might be solved. Occasionally, I would project the solution produced by a student and comment on it or allow the student to present it. After students have completed the exercises for one topic, a new topic would be introduced by the instructor and then the students would perform the exercises for that section.

    I found that it was very important to allow students to work through the materials for themselves as much as possible. Students are very anxious to place their hands on the keyboard and to dive right in; students tend to have relatively little patience for dry lectures. Most students learn relatively little from listening, but learn a lot from working the embedded exercises and discussing strategies for the solution of specific problems. The tutorial format requires more time than lecturing, but is much more effective. Do not try to go too fast! It is more important for students to begin to think in Mathematica style than to hear or read the syntax for thousands of functions.

    The essential core of an introductory course in Mathematica is contained within the two notebooks getting started and functions, each of which requires approximately three weeks to cover. The student who has mastered these lessons is already quite proficient in the use of Mathematica and should be able to identify and learn the additional tools needed for his/her purposes with relatively little help from the instructor. Therefore, the selection of topics for the remainder of a standard one semester course permits flexibility to meet the needs of the class. A sample curriculum is given below with estimated times.

notebook weeks comments
getting started 3  
functions 3 examples: cicada, logistic map, cobweb, Julia
plotting 1 can be homework instead of in class
expressions 1  
algebra 2  
calculus 1   
differential equations 2.5 examples: Volterra and van der Pol take 2 classes, a problem on the BZ reaction takes 1 class
frequency analysis 1  

    The notebook on dimensional analysis, or parts of it, should be assigned as homework soon after completion of getting started. Within functions is a problem on Julia sets that is easy and fun; I assigned it between two classes and then presented julia.nb as an example of modular programming after the students turned in their solutions. Depending upon the pace of the class, plotting can either be covered in class or parts of it assigned as homework; I used the diffraction problem as a homework assignment that reinforced techniques of modular programming as well as covering plotting features. I chose to omit lists to permit more time for differential equations. I also used frequency analysis to shed additional insight upon limit cycles (van der Pol oscillator) and the logistic map. A miniproject based upon Koch was also a lot of fun.

Style sheet

    If  you would like to prepare notebooks with the style used for these course materials, you will need the style sheet TutorialJJK.nb.

Solutions to exercises

    Detailed solutions to all of the exercises in getting started and functions and to many of the exercises in other notebooks are available to qualified instructors upon request.  These solutions have not been made public so that instructors can assign homework without the solutions being in general circulation.


    Please notify me of any errors you find.  Comments and suggestions are welcome.  My e-mail address is