Tải bản đầy đủ (.pdf) (1,135 trang)

IT training mathematica navigator mathematics, statistics, and graphics (3rd ed ) ruskeepää 2009 03 20

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (18.67 MB, 1,135 trang )


Mathematica ® Navigator


This page intentionally left blank


Mathematica ® Navigator
Mathematics, Statistics, and Graphics

THIRD EDITION

Heikki Ruskeepää
Department of Mathematics
University of Turku, Finland

AMSTERDAM • BOSTON • HEIDELBERG • LONDON
NEW YORK • OXFORD • PARIS • SAN DIEGO
SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO
Academic Press is an imprint of Elsevier


The book is produced from PDF files prepared by the author with Mathematica®.
Academic Press is an imprint of Elsevier
30 Corporate Drive, Suite 400, Burlington, MA 01803, USA
525 B Street, Suite 1900, San Diego, California 92101-4495, USA
84 Theobald’s Road, London WC1X 8RR, UK
Copyright © 2009, Elsevier Inc. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopy, recording, or any information
storage and retrieval system, without permission in writing from the publisher.


Permissions may be sought directly from Elsevier’s Science & Technology Rights
Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333,
E-mail: You may also complete your request online
via the Elsevier homepage (), by selecting “Support & Contact”
then “Copyright and Permission” and then “Obtaining Permissions.”
Library of Congress Cataloging-in-Publication Data
Ruskeepää, Heikki.
Mathematic navigator : mathematics, statistics, and graphics / Heikki Ruskeepää. – 3rd ed.
p. cm.
Includes bibliographical references and index.
ISBN 978-0-12-374164-6 (pbk. : alk. paper) 1. Mathematics–Data processing. 2. Mathematica
(Computer file) I. Title.
QA76.95.R87 2009
510.285'5–dc22
2008044637
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
ISBN: 978-0-12-374164-6
For information on all Academic Press publications
visit our Web site at www.elsevierdirect.com

Printed in the United States of America
09 10 11 9 8 7 6 5 4 3 2

1


To Marjatta



This page intentionally left blank


Contents
Preface xi
1 Starting 1
1.1 What Is Mathematica 2
1.2 First Calculations 6
1.3 Important Conventions 12
1.4 Getting Help 15
1.5 Editing 22
2 Sightseeing 25
2.1 Graphics 26
2.2 Expressions 31
2.3 Mathematics 40
3 Notebooks 51
3.1 Working with Notebooks 52
3.2 Editing Notebooks 59
3.3 Inputs and Outputs 70
3.4 Writing Mathematical Documents 78
4 Files 93
4.1 Loading Packages 94
4.2 Exporting and Importing 100
4.3 Saving for Other Purposes 109
4.4 Managing Time and Memory 112
5 Graphics for Functions 115
5.1 Basic Plots for 2D Functions 116
5.2 Other Plots for 2D Functions 132
5.3 Plots for 3D Functions 139
5.4 Plots for 4D Functions 147

6 Graphics Primitives 151
6.1 Introduction to Graphics Primitives 152
6.2 Primitives and Directives 155


viii

Mathematica Navigator

7 Graphics Options 179
7.1 Introduction to Options 180
7.2 Options for Form, Ranges, and Fonts 189
7.3 Options for Axes, Frames, and Primitives 195
7.4 Options for the Curve 203
7.5 Options for Surface Plots 210
7.6 Options for Contour and Density Plots 226
8 Graphics for Data 231
8.1 Basic Plots 232
8.2 Scatter Plots 249
8.3 Bar Charts 253
8.4 Other Plots 260
8.5 Graph Plots 267
8.6 Plots for 3D Data 275
9 Data 283
9.1 Chemical and Physical Data 284
9.2 Geographical and Financial Data 293
9.3 Mathematical and Other Data 300
10 Manipulations 315
10.1 Basic Manipulation 316
10.2 Advanced Manipulation 338

11 Dynamics 357
11.1 Views and Animations 357
11.2 Advanced Dynamics 369
12 Numbers 395
12.1 Introduction to Numbers 396
12.2 Real Numbers 403
12.3 Options of Numerical Routines 409
13 Expressions 413
13.1 Basic Techniques 414
13.2 Manipulating Expressions 419
13.3 Manipulating Special Expressions 427
13.4 Mathematical Functions 435
14 Lists 443
14.1 Basic List Manipulation 444
14.2 Advanced List Manipulation 459


Contents
15 Tables 4670
15.1 Basic Tabulating 467
15.2 Advanced Tabulating 470
16 Patterns 4910
16.1 Patterns 491
16.2 String Patterns 505
17 Functions 5110
17.1 User-Defined Functions 512
17.2 More about Functions 523
17.3 Contexts and Packages 531
18 Programs 5410
18.1 Simple Programming 542

18.2 Procedural Programming 553
18.3 Functional Programming 568
18.4 Rule-Based Programming 584
18.5 Recursive Programming 596
19 Differential Calculus 6150
19.1 Derivatives 615
19.2 Taylor Series 624
19.3 Limits 630
20 Integral Calculus 6330
20.1 Integration 634
20.2 Numerical Quadrature 644
20.3 Sums and Products 666
20.4 Transforms 670
21 Matrices 6770
21.1 Vectors 677
21.2 Matrices 686
22 Equations 709
22.1 Linear Equations 710
22.2 Polynomial and Radical Equations 716
22.3 Transcendental Equations 730
23 Optimization 7410
23.1 Global Optimization 743
23.2 Linear Optimization 753
23.3 Local Optimization 759
23.4 Classical Optimization 768
23.5 Special Topics 777

ix



x

Mathematica Navigator

24 Interpolation 791
24.1 Usual Interpolation 792
24.2 Piecewise Interpolation 797
24.3 Splines 803
24.4 Interpolation of Functions 806
25 Approximation 811
25.1 Approximation of Data 812
25.2 Approximation of Functions 824
26 Differential Equations 829
26.1 Symbolic Solutions 830
26.2 More about Symbolic Solutions 841
26.3 Numerical Solutions 849
26.4 More about Numerical Solutions 865
27 Partial Differential Equations 885
27.1 Symbolic Solutions 886
27.2 Series Solutions 893
27.3 Numerical Solutions 909
28 Difference Equations 923
28.1 Solving Difference Equations 924
28.2 The Logistic Equation 935
28.3 More about Discrete Systems 950
29 Probability 961
29.1 Random Numbers and Sampling 962
29.2 Discrete Probability Distributions 966
29.3 Continuous Probability Distributions 976
29.4 Stochastic Processes 987

30 Statistics 1003
30.1 Descriptive Statistics 1004
30.2 Frequencies 1011
30.3 Confidence Intervals 1020
30.4 Hypothesis Testing 1024
30.5 Regression 1030
30.6 Smoothing 1041
30.7 Bayesian Statistics 1046
References 1063
Index 1067


Preface
What is the difference between an applied mathematician and a pure mathematician?
An applied mathematician has a solution for every problem,
while a pure mathematician has a problem for every solution.

Welcome
The goals of this book, the third edition of Mathematica Navigator: Mathematics, Statistics, Graphics, and
Programming, are as follows:
•to introduce the reader to Mathematica; and
•to emphasize mathematics (especially methods of applied mathematics), statistics, graphics,
programming, and writing mathematical documents.
Accordingly, we navigate the reader through Mathematica and give an overall introduction. Often we
slow down somewhat when an important or interesting topic of mathematics or statistics is encountered
to investigate it in more detail. We then often use both graphics and symbolic and numerical methods.
Here and there we write small programs to make the use of some procedures easier. One chapter is
devoted to Mathematica as an advanced environment of writing mathematical documents.
The online version of the book, which can be installed from the enclosed CD-ROM, makes the
material easily available when working with Mathematica.

Changes in this third edition are numerous and are explained later in the Preface. The current edition
is based on Mathematica 6. On the CD-ROM, there is material that describes the new properties of
Mathematica 7.
‡ Readership

The book may be useful in the following situations:
•for courses teaching Mathematica;
•for several mathematical and statistical courses (given in, for example, mathematics, engineering,
physics, and statistics); and
•for self-study.
Indeed, the book may serve as a tutorial and as a reference or handbook of Mathematica, and it may
also be useful as a companion in many mathematical and statistical courses, including the following:
differential and integral calculus • linear algebra • optimization • differential, partial differential,
and difference equations • engineering mathematics • mathematical methods of physics •
mathematical modeling • numerical methods • probability • stochastic processes • statistics •
regression analysis • Bayesian statistics


xii

Mathematica Navigator

‡ Previous Knowledge

No previous knowledge of Mathematica is assumed. On the other hand, we assume some knowledge of
various topics in pure and applied mathematics. We study, for example, partial differential equations
and statistics without giving detailed introductions to these topics. If you are not acquainted with a
topic, you can simply skip the chapter or section of the book considering that topic.
Also, to understand the numerical algorithms, it is useful if the reader has some knowledge about the
simplest numerical methods. Often we introduce briefly the basic ideas of a method (or they may

become clear from the examples or other material presented), but usually we do not derive the methods.
If a topic is unfamiliar to you, consult a textbook about numerical analysis, such as Skeel and Keiper
(2001).
‡ Recommendations

If you are a newcomer to Mathematica, then Chapter 1, Starting, is mandatory, and Chapter 2, Sightseeing, is strongly recommended. You can also browse Chapter 3, Notebooks, and perhaps also Chapter 4,
Files, so that you know where to go when you encounter the topics of these chapters. After that you can
proceed more freely. However, read Section 13.1, “Basic Techniques,” because it contains some very
common concepts used constantly for expressions.
If you have some previous knowledge of Mathematica, you can probably go directly to the chapter or
section you are interested in, with the risk, however, of having to go back to study some background
material. Again, be sure to read Section 13.1.

Contents
The 30 chapters of the book can be divided into nine main parts:
Introduction

Dynamics

Mathematics

1. Starting

10. Manipulations

2. Sightseeing

11. Dynamics

19. Differential Calculus

20. Integral Calculus

Files

Expressions

3. Notebooks
4. Files

12. Numbers
13. Expressions

Graphics

24. Interpolation

5. Grahics for Functions
6. Graphics Primitives

14. Lists
15. Tables
16. Patterns

7. Graphics Options

Programs

8. Graphics for Data

17. Functions

18. Programs

27. Partial Differential Equations

Data

9. Data

21. Matrices
22. Equations
23. Optimization
25. Approximation
26. Differential Equations
28. Difference Equations
Statistics

29. Probability
30. Statistics

Dependencies between the chapters are generally quite low. If you read Chapter 2, Sightseeing, you
will get a background that may serve you well when reading most other chapters; in some chapters, you
will also find references to previous chapters, where you will find the needed background.
The following bar chart shows the numbers of pages of the 30 chapters:


Preface

xiii

The six longest chapters are 7, Graphics Options; 8, Graphics for Data; 18, Programs; 23, Optimization; 26, Differential Equations; and 30, Statistics.

Next we describe the main parts of the book.
‡ Introduction, Files, Graphics, Data, Dynamics, Expressions, and Programs

The first two chapters introduce Mathematica and give a short overview.
The next two chapters consider files, particularly files created by Mathematica, which are called
notebooks. We show how Mathematica can be used to write mathematical documents. We also explain
how to load packages, how to export and import data and graphics into and from Mathematica, and how
to manage memory and computing time. You may skip these two chapters until you need them.
Then we go on to graphics. One of the finest aspects of Mathematica is its high-quality graphics, and
one of the strongest motivations for studying Mathematica is to learn to illustrate mathematics with
figures. We consider separately graphics for functions and graphics for data. In addition, we have
chapters about graphics primitives and graphics options.
New in Mathematica 6 are the built-in data sources, covering topics such as chemistry, astronomy,
particles, countries, cities, finance, polyhedrons, graphs, words, and colors.
The main new topic in Mathematica 6 is dynamics. This allows us to easily build interactive interfaces.
The user of such an interface can choose some parameters or other options and the output will be
changed dynamically, in real time. This helps in studying various models and phenomena.


xiv

Mathematica Navigator

Then we study various types of expressions, from numbers to strings, mathematical expressions,
lists, tables, and patterns.
We have two chapters relating to programming. The first studies functions and the next various
styles of programming. Four styles are considered: procedural, functional, rule-based, and recursive.
‡ Mathematics and Statistics

In the remaining 12 chapters, we study different areas of pure and applied mathematics and statistics.

The mathematical chapters can be divided into four classes, with each class containing chapters of more
or less related topics. Descriptions of these classes follow.
Topics of traditional differential and integral calculus include derivatives, Taylor series, limits,
integrals, sums, and transforms.
Then we consider vectors and matrices; linear, polynomial, and transcendental equations; and global,
local, and classical optimization.
In interpolation we have the usual interpolating polynomial, a piecewise-calculated interpolating
polynomial, and splines. In approximation we distinguish the approximation of data and functions. For
the former, we can use the linear or nonlinear least-squares method, whereas for the latter we have, for
example, minimax approximation.
Mathematica solves differential equations both symbolically and numerically. We can solve first- and
higher-order equations, systems of equations, and initial and boundary value problems. For partial
differential equations, we show how some equations can be solved symbolically, how to handle series
solutions, and how to numerically solve problems with the method of lines or with the finite difference
method. Then we consider difference equations. For linear difference equations, we can possibly find a
solution in a closed form, but most nonlinear difference equations have to be investigated in other ways,
such as studying trajectories and forming bifurcation diagrams.
Lastly, we study probability and statistics. Mathematica contains information about most of the
well-known probability distributions. Simulation of various random phenomena (e.g., stochastic
processes) is done well with random numbers. Statistical topics include descriptive statistics, frequencies, confidence intervals, hypothesis testing, regression, smoothing, and Bayesian statistics.

Special Aspects
The book explains a substantial portion of the topics of Mathematica. However, some topics are emphasized, some are given less emphasis, and some are even excluded. We describe these special aspects of
the book here.
‡ Breadth

We have had the goal of studying important topics in some breadth and depth. This may mean detailed
explanations, clarifying examples, programs, and applications. It may also mean introducing topics for
which there is little or no built-in material.
The headings of the chapters give a list of topics that are emphasized in this book and that are

explained in some breadth. However, some emphasized topics cannot be identified from the chapter
headings. One of them is numerical methods; they are used in every mathematical chapter. Another is
methods relating to data. Indeed, we use several real-life and artificial data sets in chapters about data,
graphics for data, approximation, differential and difference equations, probability, and statistics.


Preface

xv

‡ Depth

To give an impression of the depth of various topics, we next describe some special topics in various
chapters of the book.
•Chapter 3,Notebooks: An introduction to Mathematica as an environment for preparing technical
documents; writing mathematical formulas
•Chapter 5,Graphics for Functions: Stereographic figures; graphics for four-dimensional functions
•Chapter 8,Graphics for Data: Visualizations of several real-life data; dot plots; statistical plots
•Chapter 18,Programs: Four styles of programming (procedural, functional, rule-based, and
recursive); emphasis on functional programming; many examples of programs
•Chapter 22,Equations: Iterative methods of solving linear equations; programs for nonlinear
equations
•Chapter 23,Optimization: A program for numerical minimization; a program for classical optimization with equality and inequality constraints; dynamic programming
•Chapter 25,Approximation: Graphical diagnostics of least-squares fits
•Chapter 26,Differential Equations: Analyzing and visualizing solutions of systems of nonlinear
differential equations; study of a predator-prey model, a competing species model, and the Lorenz
model; numerical solution of linear and nonlinear boundary value problems; estimation of
nonlinear differential equations from data; solving integral equations
•Chapter 27,Partial Differential Equations: Series solutions for partial differential equations; solving
parabolic and hyperbolic problems by the method of lines;solving elliptic problems by the finite

difference method
•Chapter 28,Difference Equations: The logistic model as an example of nonlinear difference
equations; bifurcation diagrams, periodic points, Lyapunov exponents; a discrete-time predator-prey model as an example of a system of nonlinear difference equations; estimation of
nonlinear difference equations from data; fractal images; Lindenmayer systems
•Chapter 29,Probability: Simulation of several stochastic processes
•Chapter 30,Statistics: Visualizing confidence intervals and types of errors in statistical tests;
confidence intervals and tests for probabilities; local regression; Bayesian statistics; Gibbs sampling;
Markov chain Monte Carlo
‡ Programs

Mathematica has a large number of ready-to-use commands for symbolic and numerical calculations and
for graphics. Nevertheless, in this book we also present approximately 130 of our own programs.
Indeed, programming is one of the strongest points of Mathematica. It is often amazing how concisely
and efficiently we can write a program even for a somewhat complex problem. We think that our own
programs can be of some value, despite the fact that they are not so fine and powerful as Mathematica’s
built-in commands. We have included our own programs for the following reasons:
1.A self-made implementation shows clearly how the algorithm works. You know (or should know)
exactly what you are doing when you use your own implementation. The ready-made commands
are often like black (or gray) boxes because we do not know much about the methods.
2.Writing our own implementations teaches us programming. We present short programs throughout the book (especially in the mathematical chapters). In this way, we hope that you will become
steadily more familiar with programming and that you are encouraged to practice program writing.


xvi

Mathematica Navigator

3.A self-made implementation can be pedagogically worthwhile. For example, we implement Euler’s
method for differential equations. It has almost no practical value, but as the simplest numerical
method for initial value problems, it has a certain pedagogical value. Also, programming a simple

method first may help us to tackle a more demanding method later.
‡ Other Special Aspects

We have integrated the so-called packages tightly into the material covered in this book. Instead of
presenting a separate chapter about packages, each package is explained in its proper context.
We have tried to make the structure of the book such that finding a topic is easy. Usually a topic is
considered in one and only one chapter or section so that you need not search in several places to find
the whole story. Each numerical routine is also presented in the proper context after the corresponding
symbolic methods. This helps you to find material for solving a given problem: It is usually best to try a
symbolic method first and, if this fails, to then resort to a numerical method.
Some topics of a “pure” nature, such as finite fields, quaternions, combinatorics, computational
geometry, and graph theory, are not considered in this book; Mathematica has packages for these topics.
Commands for box and notebook manipulation are treated only briefly. We do not consider MathLink (a
part of Mathematica that enables interaction between Mathematica and external programs), J/Link (a
product that integrates Mathematica and Java), XML (a metamarkup language for the World Wide Web),
or MathML (an XML-based markup language for representing mathematics). Also, we do not consider
any of the many other Mathematica-related products, such as webMathematica, gridMathematica,
CalculationCenter, or the Applications Library packages.

Mathematica 6
‡ Introduction

Mathematica 6 contains a huge amount of new functionality. The following is a part of an on-line
document:
Mathematica 6.0 fundamentally redefines Mathematica and introduces a major new paradigm for
computation. Building on Mathematica’s time-tested core symbolic architecture, version 6.0 adds
nearly a thousand new functions~almost doubling the total number of functions in the system~
dramatically increasing both the breadth and depth of Mathematica’s capabilities, as well as introducing hundreds of major original algorithms, and perhaps a thousand new ideas, large and small.
To study the new features, see the following on-line documentation (the use of the Documentation
Center is explained in Section 1.4.2, p. 17):

• Help @ Startup Palette, the What’s New in 6 link to Wolfram’s website
• Help @ Documentation Center, the New in 6 links in the home page
• Help @ Documentation Center, the guideêSummaryOfNewFeaturesIn60 document
• Help @ Documentation Center, the guideêNewIn60AlphabeticalListing document
• Help @ Function Navigator, the New In 6 item
If you are a new user of Mathematica and would like to study the basics of Mathematica 6, see the
following documents:
• Help @ Startup Palette: the First Five Minutes with Mathematica button
• Help @ Virtual Book: the Introduction item


Preface

xvii

‡ New Properties of Version 6

Because the new features are numerous, we do not list them all here. However, we mention some of the
most remarkable new commands and features, classified according to the chapters of the book:
•Chapter 1, Starting: documentation is on-line in the form of Documentation Center, Function
Navigator and Virtual Book (we do not have a printed manual); documentation is automatically
updated via the Internet; writing Mathematica inputs is helped by syntax coloring
•Chapter 3, Notebooks: Style, Text, Hyperlink
•Chapter 4, Files: commands of many packages are now built-in; the remaining packages are rebuilt;
look at Compatibility/guide/StandardPackageCompatibilityGuide in the Documentation Center
to obtain information about how to replace the functionality of the old packages
•Chapter 5, Graphics for Functions: GraphicsRow, GraphicsGrid, Tooltip; graphics is handled like
other expressions; the default font in graphics is Times instead of Courier; 3D graphics is adaptive;
contours in contour plots have tooltips; density plots, by default, do not have meshes; 2D graphics
can be interactively drawn and edited; 3D graphics can be interactively manipulated (e.g., rotated);

for animation, use Manipulate or Animate
•Chapter 6, Graphics Primitives: Arrow, Opacity, Inset
•Chapter 7, Graphics Options: Directive, BaseStyle, Filling; the default value of AspectRatio in
Graphics and ParametricPlot is Automatic instead of 1/GoldenRatio
•Chapter 8, Graphics for Data: ListLinePlot, GraphPlot; plotting of several data sets
•Chapter 9, Data: ElementData, CountryData, PolyhedronData, etc.
•Chapter 10, Manipulations: Manipulate (for creating interactive dynamic interfaces)
•Chapter 11, Dynamics: Dynamic (for advanced dynamic interfaces), MenuView, TabView, etc.
•Chapter 15, Tables: Grid, Row, Column
•Chapter 16, Patterns: DictionaryLookup
•Chapter 21, Matrices: Accumulate, PositiveDefiniteMatrixQ
•Chapter 23, Optimization: FindShortestTour
•Chapter 29, Probability: RandomReal, RandomInteger, RandomChoice, RandomSample
•Chapter 30, Statistics: Tally, BinCounts, FindClusters
In my opinion, the most impressive new commands in version 6 are Manipulate, Dynamic,
GraphPlot, and Grid.

Note that many familiar commands, such as NIntegrate or NDSolve, have also been enhanced in
version 6.
In the forthcoming chapters, we mark with (Ÿ6) the properties and commands of Mathematica
available for the first time in version 6.
‡ Obsolete Properties in Version 6

Version 6 makes obsolete some old commands and features, especially in graphics. First, here are some
changes that relate to the display and arrangement of graphics:
•To prevent the display of graphics, end the plotting command with ; instead of using the
DisplayFunction option.
•In programs, enclose a plotting command with Print if that command is not the last command of
the program and you would like the program to show that plot.
•GraphicsArray is obsolete. To show, for example, two plots p1 and p2 side by side, use one of the

following ways: {p1, p2}, Row[{p1, p2}], or GraphicsRow[{p1, p2}]. Use GraphicsGrid for
arrays of plots.


xviii

Mathematica Navigator

•To show two plots side by side, you can also simply give a list of plotting commands {Plot[…],
Plot[…]}.
•To show two plots on top of each other, simply write Show[Plot[…], Plot[…]]; the
DisplayFunction option is no longer needed.
•Graphics and Graphics3D no longer need Show to display the graphics. Thus, write
Graphics[{…}] instead of Show[Graphics[{…}].
•Use Inset[gr, pos] instead of Rectangle[{x1, y1}, {x2, y2}, gr].
Some changes that relate to plotting of data are as follows:
•To plot data by connecting the points with lines, use ListLinePlot[data] instead of
ListPlot[data, PlotJoined Ø True].
•To plot data by points and connecting lines, use ListLinePlot[data, Mesh Ø All] instead of
ListPlot[data, PlotJoined Ø True, Epilog Ø {PointSize[s], Map[point, data]}].
•To plot data by points and vertical lines, use ListPlot[data, Filling Ø Axis] instead of
resorting to Prolog or Epilog.
•To plot several data sets, use ListPlot[{data1, data2, … }] or ListLinePlot[{data1, data2, …
}] instead of resorting to MultipleListPlot in a package.
•To plot several points, simply write Point[points] instead of Map[Point, points].
Here are some changes that relate to styles and options of graphics:
•Use Style instead of StyleForm.
•Use the BaseStyle option instead of the TextStyle option or the $TextStyle global constant.
•Use the MaxRecursion option instead of the PlotDivision option.
•Use the DataRange option instead of the MeshRange option.

•Use the Filling option instead of the FilledPlot command.
Some other changes are as follows:
•Use RandomReal[…], RandomInteger[…], and RandomComplex[…] instead of Random[Real, …],
etc.
•For random numbers from probability distributions, use RandomReal[contDist, n] or
RandomInteger[discrDist, n] instead of resorting to Random or RandomArray.
•Use Tally instead of Frequencies in a package.

The Third Edition
‡ Main Changes

The text has been revised throughout. Indeed, Mathematica 6 brings up so much new and changed
features that almost every topic has undergone a revision and new topics are included. Recall that the
second edition of this book was based on Mathematica 5.
The main change in the structure of the book is that we have six new chapters: Chapter 6, Graphics
Primitives; Chapter 9, Data; Chapter 10, Manipulations; Chapter 11, Dynamics; Chapter 15, Tables; and
Chapter 16, Patterns. On the other hand, some chapters have been merged and the result is that the
current edition has but one chapter about the following topics: graphics for functions, graphics for data,
and graphics options (the second edition had two chapters for each of these topics, one for twodimensional and one for three-dimensional graphics).


Preface

xix

The main change in the contents of the book is the transition from version 5 to version 6. In addition,
we have some other enhancements. The chapter on programming is much enhanced and enlarged and
contains much more examples. The chapter about matrix calculus is also enhanced. The chapter about
optimization now includes the method of dynamic programming. Chapters about graphics for data and
optimization have undergone a restructuring.

Note that this book fully utilizes the new features of Mathematica 6. Because version 6 differs so much
from earlier versions, this book cannot practically be used with older versions of Mathematica. If you
have Mathematica 5.2 or an earlier version, please use the second edition of Mathematica Navigator.
The CD-ROM contains Help Browser material that describes the new properties of Mathematica 7.
‡ Some Notes

New Features
Some of the new features of version 6 would have warranted a broader and deeper treatment and more
examples of use throughout the book. These features include the creation of dynamic interfaces and the
use of the built-in data sources. However, to keep the book at a reasonable size, we had to limit the
treatment and the number of examples. We suggest that the reader consults the built-in documentation.
The website contains thousands of examples of dynamic interfaces.
Environment
During the writing of this book, I used a Macintosh with MacOS X. Mathematica works in much the same
way in various environments, but the keyboard shortcuts of menu commands vary among different
environments. To some extent, we mention the shortcuts for the Microsoft Windows and Macintosh
environments.
Options
Many commands of Mathematica have options for modifying them. All options have a default value, but
we can input other values. When listing the options, we give either all possible values of them or some
examples of possible values, but we do not explicitly mention the default values, to save space. In the
context of this book, the default value of an option is always the first value mentioned. After that are other
possible values or examples of other values.
Simulations
In several places in the book, we simulate various random phenomena. Usually, each time a simulation
is run, a slightly different result is obtained. However, in experimenting with the examples of the book,
the reader may want to get exactly the same result as printed in the book. This can be achieved by using
a seed to the random number generator with SeedRandom[n] for a given integer n. With the same seed,
the result of a simulation remains the same in repeated executions. We use SeedRandom quite often in
this book. If you want to get other results of simulation than those of this book, give different seeds or

do not execute SeedRandom[n] at all (in the latter case, the default seed is used).
CD-ROM
The entire book is contained on the CD-ROM that comes with it. With a few easy steps you can install
the book into the Help Browser of Mathematica (the CD-ROM contains installation instructions). With
the Help Browser you can easily find and read sections of the book, experiment with the commands,
and copy material from the book to your document. You can see all of the figures of the book in color
and interactively study the manipulations and animations. The material about the new properties of
Mathematica 7 can also be installed into the Help Browser. In addition, the CD-ROM contains some data
files that are used in the book.


xx

Mathematica Navigator

Notation
Throughout the book, the adjectives one-, two-, three-, and four-dimensional are abbreviated 1D, 2D,
3D, and 4D, respectively. The symbol Ö is used as a hyphen for Mathematica commands. In addition, we
use extensively the following handy short notation:
p Means the same as Pi. The symbol p can be written as ÂpÂ.
¶ Means the same as Infinity. The symbol ¶ can be written as ÂinfÂ.

P…T Means the same as [[…]]. For example, x[[3]] can also be written as xP3T. The symbols P and
T can be written as Â[[Â and Â]]Â.

¨ Means the same as Transpose. For example, Transpose[x] can also be written as x¨. The symbol ¨

can be written as ÂtrÂ.

/@ Means the same as Map. For example, Map[f[#]&, {a, b, c}] can also be written as f[#]& /@ {a,

b, c}. A third way is to write Table[f[x], {x, {a, b, c}}].

The symbols p and ¶ can also be found from the BasicMathInput palette. For example, instead of
Map@Ò ^ 2 &, Transpose@88Pi, Infinity<
99p2 =, 8¶<=

we can write

Ò ^ 2 & êü 88p, ¶<<¨
99p2 =, 8¶<=

Questions
If you have questions about the use of Mathematica, do not hesitate to contact me. I try to answer when I
have the time. Also, please send comments and corrections.

Acknowledgments
In preparing this book, the main source has been the excellent on-line Documentation Center of
Mathematica 6. The technical support staff at Wolfram Research, Inc., helped me a lot; I especially thank
Eric Bynum, Roberto Cavaliere, Huihua Huang, Yong Huang, Vivec Joshi, and Bruce Miller.
The entire book was written and produced with Mathematica; each chapter is a Mathematica notebook.
The notebooks were connected into a single project by the AuthorTools package of Mathematica. The
package then automatically generated the index (after we had attached the index entries with the cells of
the book, also with the package), and the package also prepared the on-line Help Browser version of the
book.
I have been lucky enough to enjoy excellent working conditions at the Department of Mathematics of
the University of Turku. For this my sincere thanks are due to Professor Marko Mäkelä. I also thank
Professor Juhani Karhumäki and Professor Matti Vuorinen for their support and encouragement.
The third edition is also published in India. I am deeply indepted to Professor Ponnusamy
Saminathan, Indian Institute of Technology, Madras, Chennai, for suggesting and supporting the Indian

edition.
For their review of the manuscript of the second edition, I am very thankful to Donald Balenovich,
Indiana University of Pennsylvania; Joaquin Carbonara, Buffalo State University; William Emerson,
Metropolitan State University; Jim Guyker, Buffalo State University; Mike Mesterton-Gibbons, Florida
State University; and Fred Szabo, Concordia University. Their valuable comments and suggestions
greatly improved the second edition.


Preface

xxi

I also thank the following people for taking the task of writing a review of the second edition of the
book in some journals: Robert M. Lurie (Mathematica in Education and Research), Matti Vuorinen
(Zentralblatt MATH), K. Waldhör (Computing Reviews), and John A. Wass (Scientific Computing).
Many readers of the second edition have sent me e-mail, giving feedback and asking questions.
Thank you all! Your support has encouraged me in writing the third edition.
The anecdotes at the beginning of the chapters are from the wonderful book by MacHale (1993) (the
anecdotes are reproduced or adapted with the permission of the publishers, Boole Press, 26 Temple
Lane, Dublin 2, Ireland).
The editorial staff at Elsevier has done a fine work with the production of the book. Especially I
would like to thank Phil Bugeau for efficient project management. I am also very grateful to Dan Hays
and Kristen Cassereau Ng for copy-editing and proofreading the manuscript with great care.
For financial support I express my deep gratitude to Elsevier Academic Press and Suomen
Tietokirjailijat (The Association of Finnish Non-Fiction Writers).
Lastly, I thank my wife, Marjatta, for her encouragement and support during the work.

Heikki Ruskeepää
Department of Mathematics
University of Turku

FIN-20014 Turku
Finland



xxii
This page intentionally left blank

Mathematica Navigator


1
Starting
Introduction 1
1.1 What Is Mathematica? 2
1.1.1 An Example 2
1.1.2 The Structure of Mathematica 4
1.2 First Calculations 6
1.2.1 Opening, Calculating, and Quitting 6
1.2.2 Names and Decimals 7 %, Out, N
1.2.3 Basic Calculations and Plotting 10 Pi, E, Sqrt, Exp, Sin, D, Integrate, Simplify, Plot, etc.
1.3 Important Conventions 12
1.4 Getting Help 15
1.4.1 Palettes 15
1.4.2 On-line Documentation 17
1.4.3 Other Help 20 ?
1.5 Editing 22

Introduction
In 1903 at a meeting of the American Mathematical Society, F. N. Cole read a paper entitled

“On the Factorization of Large Numbers.” When called upon to speak, Cole walked to the board
and, saying nothing, raised two to its sixty-seventh power and subtracted one from the answer.
Then he multiplied, longhand, 193,707,721 by 761,838,257,287 and the answers agreed. Without
having said a word, Cole sat down to a standing ovation. Afterwards he announced that it had
taken him twenty years of Sunday afternoons to factorize the Mersenne number 267 - 1.
This chapter is intended to give you an impression of Mathematica and to teach you some of its basic
techniques and commands. A more complete insight is given in the next chapter, in which we briefly
present a selection of the most important commands of Mathematica.
Although this book puts some emphasis on the methods of applied mathematics, this chapter begins,
in Section 1.1, with a “pure” example: factoring integers. We consider the problem mentioned in the
anecdote above and show what we can do nowadays with such powerful systems as Mathematica. This
example will enlighten you regarding some of the major aspects of the program. We emphasize that it is
not intended that you do the calculations of this example, nor that you should understand the commands we use.
In Section 1.2, we give a brief overview of some of Mathematica’s basic techniques and commands,
beginning with the classical starting example of calculating 1+2 and ending with calculus and graphics.
Section 1.3 presents and explains the important conventions of Mathematica, which often cause trouble
for beginners.


2

Mathematica Navigator

In Sections 1.4 and 1.5, we discuss how you can get help within Mathematica and how you can correct
and edit what you have written. These two sections may give more information than you need now, but
you can read the basic points and return to these sections later, when getting help and editing become
more relevant concerns.
Parts of this chapter depend on the computer you use. We explain only the Windows and Macintosh
environments, although some comments may be found about the basics of Mathematica in a Unix system.


1.1 What Is Mathematica?
1.1.1 An Example
‡ Verifying the Work of Cole

(Note: It is not intended that you do the calculations of Section 1.1.1. The example is only intended to be
read and to demonstrate certain aspects of Mathematica. Your actual lessons begin in Section 1.2.)
Did you read the anecdote about F. N. Cole at the beginning of this chapter? Cole sacrificed every
Sunday afternoon for 20 years to study the Mersenne number M67 = 267 - 1:
2 ^ 67 - 1
147 573 952 589 676 412 927

The first line is the command entered to Mathematica, and the second line is the answer given by
Mathematica. At last he found that the number is the product of 193,707,721 and 761,838,257,287:
193 707 721 * 761 838 257 287
147 573 952 589 676 412 927

M67 is thus not a prime. Cole’s feat was admirable. Now, after 100 years, we have Mathematica, and the
situation is totally different. It now takes only a fraction of a second to do the factorization:
FactorInteger@2 ^ 67 - 1D êê Timing

80.016942, 88193 707 721, 1<, 8761 838 257 287, 1<<<

Mathematica found that 193,707,721 and 761,838,257,287 are factors of multiplicity 1.
‡ Difficult Factors

However, even today some problems can be surprisingly difficult. When Mathematica, in my computer
(which is not very fast), factorizes M254 , it needs approximately 10,000 seconds or 3 hours and approximately 200 megabytes of RAM:

FactorInteger@2 ^ 254 - 1D êê Timing


810 521.7, 883, 1<, 856 713 727 820 156 410 577 229 101 238 628 035 243, 1<,
8170 141 183 460 469 231 731 687 303 715 884 105 727, 1<<<
MaxMemoryUsed@D
207 758 616

However, note that M254 is very big:
2 ^ 254 - 1
28 948 022 309 329 048 855 892 746 252 171 976 963 317 496 166 410 141 009 864 396 001 978 282 Ö
409 983

and two of the three factors are also big. Thus, factoring the number is obviously a difficult task. By the
way, the difficulty of factoring large numbers is a key to some cryptographic methods.


×