ebook img

A Crash Course in Mathematica PDF

193 Pages·1999·3.128 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview A Crash Course in Mathematica

Stephan Kaufmann Crash Cou rse Mathematica in Birkhauser Verlag Basel· Boston · Berlin Author: Stephan Kaufmann Mechanik ETH Zentrum CH-8092 Zurich E-mail: [email protected] Homepage: http://www.ifm.ethz.ch/-kaufmann 1991 Mathematics Subject Classification 00-01 A CIP catalogue record for this book is available from the Library of Congress, Washington D.C., USA Deutsche Bibliothek Cataloging-in-Publication Data A Crash Course in Mathematica [Medienkombinationl I Stephan Kaufmann. - Basel; Boston; Berlin: Birkhauser ISBN 978-3-7643-6127-3 ISBN 978-3-0348-7589-9 (eBook) DOI 10.1007/978-3-0348-7589-9 This work is subject to copyright. All rights are reserved, whether the whole or part of the material is con cerned, specifically the rights of translation, reprinting, re-use of illustrations, broadcasting, reproduction on microfilms or in other ways, and storage in data banks. For any kind of use whatsoever, permission from the copyright owner must be obtained. The software and hardware terms referred to in this book are in most cases also registered trademarks and as such come under the same legal restrictions. The text, illustrations and programs have been carefully prepared. However, the publisher and the author accept no responsibility for errors or their consequences. Mathematica® is a registered trademark of Wolfram Research, Inc. MathReader® ist a registered trademark of Wolfram Research, Inc. ©1999 Birkhauser Verlag, Postfach 133, CH-4010 Basel, Schweiz Cover design: Markus Etterich, Basel Printed on acid-free paper produced of chlorine-free pulp. TCF oc 987654321 • Contents Preface .............................................................................................................................. 9 A Short Tour ..................................................................................................................... 16 Formula Entry ........................................................................................................... 16 Numerical Calculations ............................................................................................ 17 Symbolic Mathematics ..... ... ... .......... ............ ....... ... ... ....... ....... ....... ... ....... ................ 17 Graphics .................................................................................................................... 19 Programming ... ..... ..... ... ..... ... ... ............ .......... ..... ... ....... ............... ... ..... ..................... 22 Some of the Most Important Functions ....... ..... ... ..................... ... ..... ..................... ... 23 Part 1: The Basics ........................................................................................................... 27 1.1 The Structure of the Program. ... ............................. .............. ..... ...................... ... 28 1.1.1 The Front End .......................................................................................... 28 1.1.2 The Kernel ............................................................................................... 29 1.2 Online Documentation .. ....... .............................. ....................... ....... ......... ......... 31 1.3 Formulas ............................................................................................................. 32 1.3.1 Formats .................................................................................................... 32 1.3.2 Entering Formulas and Special Characters ............................................. 34 1.4 Simple Calculations ............................................................................................ 37 1.4.1 Conventions ............................................................................................. 37 1.4.2 Numerical Calculations ........................................................................... 41 1.4.3 Algebraic Manipulation ... ... ... ... .......... .......... ...... ............. ........................ 44 1.4.4 Transformation Rules and Definitions .................................................... 46 1.4.5 Equations .. .......................... ..... ...................... ........ .................... ....... ... .... 51 1.4.6 Calculus .... .................... ...... ..... ............... .... ... ..... ... ........................ ... ....... 59 Part 2: Graphics .... ............ ... ............. ..... ..... ....................... ............................ ....... ......... 67 2.1 Graphs of Functions of One Variable............ ....... ... ... ........... ... ........ ... ... ............ 68 2.2 Graphs of Functions of Two Variables .......................................... .................... 80 2.2.1 Surfaces ... .............. ....... ....... ............................ ..... ...... ....... ..... ... .............. 81 2.2.2 Contours .................................................................................................. 86 2.2.3 Density Plots.... ..... .... ... ... ......... ..... ........ ... ... ......... ............ .................... .... 89 2.3 Parametric Plots .................................................................................................. 92 2.3.1 Two-Dimensional Parametric Plots ......................................................... 92 2.3.2 Three-Dimensional Parametric Plots ....................................................... 93 2.4 Tools from Standard Packages ........................................................................... 100 2.4.1 Three-Dimensional Contour Plots ........................................................... 100 2.4.2 Tools for Two-Dimensional Graphics ..................................................... 101 6 2.4.3 Tools for Three-Dimensional Graphics ................................................... 10 2 2.4.4 Legends ................................................................................................... 103 2.4.5 Vector Fields ........................................................................................... 105 2.5 Animations ......................................................................................................... 110 2.6 Exporting to Other Programs ............................................................................. 113 Part 3: Lists and Graphics Programming .................................................................... 115 3.1Lists .................................................................................................................... 116 3.1.1 Creating One-Dimensional Lists ............................................................. 116 3.1.2 Manipulating Lists ................................................................................... 117 3.1.3 Multidimensional Lists ............................................................................ 120 3.2 Calculating with Lists ......................................................................................... 120 3.2.1 Automatic Operations .............................................................................. 120 3.2.2 Mapping Functions on Lists ................................................................... .121 3.2.3 Pure Functions ......................................................................................... 122 3.2.4 Using List Elements as Arguments ......................................................... 124 3.2.5 Plotting Lists ............................................................................................ 126 3.3 Linear Algebra .................................................................................................... 131 3.4 Graphics Programming ....................................................................................... 136 3.4.1 Graphics Objects ................................................................................. 136 3.4.2 Graphics3D Objects ............................................................................. 139 3.4.3 Objects from Standard Packages ............................................................ .140 3.5 Application: Animating a Mechanism ............................................................... 146 Part 4: Introduction to Programming .......................................................................... 151 4.1 Expressions ......................................................................................................... 152 4.2 Patterns ............................................................................................................... 155 4.2.1 Simple Patterns ........................................................................................ 155 4.2.2 Constraints ............................................................................................... 157 4.2.3 More Complicated Patterns ..................................................................... 162 4.2.4 A Simple Integrator ................................................................................. 163 4.3 Evaluation ........................................................................................................... 167 4.3.1 Associated Definitions ............................................................................ 167 4.3.2 Attributes ................................................................................................. 168 4.3.3 The Evaluation Process ........................................................................... 169 4.4 Programming Tools ............................................................................................ 172 4.4.1 Local Variables ........................................................................................ 172 4.4.2 Functional Programming ......................................................................... 173 4.4.3 Rule-Based and Recursive Programming ................................................ 176 4.4.4 Procedural Programming ......................................................................... 179 Contents 7 4.4.5 Modularity ............................................................................................... 181 4.4.6 Compiling Numerical Calculations ......................................................... 183 4.5 Further Information ............................................................................................ 185 4.5.1 Internet ..................................................................................................... 185 4.5.2 MathSource ............................................................................................. 185 4.5.3 Literature ................................................................................................. 185 Index ................................................................................................................................. 187 • Preface • About Mathematica Mathematica unites the following tasks, among others, in one uniform interactive environ ment: • the entry and display of mathematical formulas, • numerical calculation, • symbolic mathematics, • plotting functions, • contours and density plots • parametric plots of curves and surfaces, • creating graphics from elementary objects, • animating graphics, • list processing, • pattern matching, • functional, procedural and rule-based programming, • structuring documents hierarchically, • programming interactive documents. This is the ideal tool for those who use pure or applied mathematics, graphics, or program ming in their work. Mathematica is available for all the usual computer operating systems. Thanks to the uniformity of its file format, it is also a practical medium for the electronic exchange of reports or publications which contain formulas and graphics. Mathematica files, called notebooks, can also be saved directly into HTML format for easy publication on the World Wide Web. Mathematica allows you to solve many problems quickly, like calculating integrals, solving differential equations, or plotting functions. In order to use this powerful tool efficiently, however, you need to know the basics of the user interface and of the syntax of Mathematica expressions. Otherwise you would be like a driver who has not noticed that there are more gears than just first and that it makes sense to obey the rules of the road. In both cases its better not to attempt to learn by just trying things out. 10 • The Goals of this Course This book and the accompanying Mathematica notebooks on CD-ROM give you the basics of Mathematica in short form. We will discuss the user interface (front end), the most important functions built into the actual calculator (kernel), and some additional programs (packages) which come with Mathematica. The examples are kept at a simple mathematical level and to a great extent independent of special technical or scientific applications. Emphasis is put on solving standard problems (equations, integrals, etc.) and on graphics. After working through this course you will be able to solve your own problems indepen dently and to find additional help in the online documentation. Depending on your inter ests and needs, completing the first two parts of this course may be sufficient, as they include the most important calculations and graphics functions. The third part is more technical and the fourth introduces programming with Mathematica. • The Book and the CD-ROM The book is basically a direct printout of the corresponding Mathematica notebooks on the CD-ROM. Some things had to be left out like the colors, the animation of graphics, and also the hyperlinks within the notebooks to the online documentation of Mathematica and to Web sites. Why a book? Books are still the most ergonomic medium for the sequential study of texts-and today most of them are still lighter than a laptop computer. • What this Course Is Not This course is neither complete nor meant to be a reference tool. The four parts of the book therefore do not include summaries of the Mathematica commands discussed. However, the notebooks on the CD-ROM contain hyperlinks to online documentation of the com mands. The advantage being that you always see the documentation corresponding to your version of the program. A complete installation of the program includes the 1403 page "Mathematica Book" by Stephen Wolfram. This book is perhaps the first exception to the rule above: because of its size and format, comparable to a laptop, the electronic version, with its many useful hyperlinks, is usually more practical than the printed version. Introduction 11 • Organization The introduction contains a short overview of Mathematica's capabilities and-for minimalists-a summary of the most important commands. The following four parts form a progression and should therefore be done in sequence. It is not necessary, however, to complete all the parts in one go. The methods in the first two parts will already allow you to solve many problems. The motivation for studying the last two parts will probably arise after you have worked with the program for a while. The first part leads to the most important capabilities of the user interface (front end) and explains the different possibilities for creating Mathematica entries and formulas. Next, how to tackle the most common problems is shown using examples: numerical calculation, manipulation of formulas, solving equations and differential equations, calculating limits, derivatives and integrals. The second part deals with an especially compelling aspect of the program: plots of graphs of functions and parametric plots of curves and surfaces. Many of these features are built into the Mathematica kernel; additional useful tools are available from standard packages. The third part starts with a discussion of lists. They are used to manipulate vectors and matrices; they also appear in many Mathematica functions as arguments or results, and can be used to structure data. In connection with this, this part also deals with mapping functions on lists and simple calculations of linear algebra. Lists allow you to assemble graphics from graphics elements (lines, circles, etc.). Sequences of graphics can be animated. The fourth part is aimed at users who want a more in-depth study of Mathematica. It is the starting point for the independent development of complicated programs. The first three chapters are dedicated to the structure and evaluation of Mathematica expressions. Based on this, we discuss different possible programming methodologies and the tools for their application. At the end you will find leads to further information such as relevant Web sites and a link to Mathematica literature. Several chapters include in-depth paragraphs covering special features and technical details, which can be left out at first. The exercise problems have been kept simple on purpose. They should allow you to master the program without getting bogged down in complicated mathematics. The ideal exercise examples are not found in the book-they develop from your work. There are many problems which you can solve with Mathematica. Try it! 12 • Tips For best results, the notebooks should be worked on directly in Mathematica on the computer. If you do not own the complete program, you can use the program MathReader, which is included on the CD-ROM, to access the notebooks (and the animations). Math Reader is a reduced version of Mathematica which cannot be used to make calculations but which does give you a first impression of how the program works. When using the full version, it is best to use the files in the In-only directory; for MathReaderuse the files in In-out (see the paragraph "The Files on the CD-ROM"). It is important to know that the cell groups (shown as square brackets on the right-hand side of the notebook window) can be opened or closed by double-clicking on the bracket itself, or by using the command Cell> Cell Grouping on the menu bar. With the menu Format> Magnification you can adjust the magnification of the window for maximum overview and readability. Graphics might then appear jaggy. Use the command Cell> Rerender Graphics to smooth them out again. With the computer you can use the hyperlinks to access the documentation of built-in functions, or to jump from one section of the book to another. The menu Find> Go Back is useful here: it takes you back to the original hyperlink. Depending on the version and the installation options of Mathematica, certain links are inactive. The links in the table of contents and the subject index are useful to navigate between the notebooks. It is best to start with the examples in the chapter "A Short Tour" (in the Introduction. nb file). With the full version of Mathematica the input cells can be evaluated using the <Enter> key (or <Shift> and <Return». In the "Short Tour", and during the whole course, you are invited to change the examples in order to test the possibilities and limits of the program and to get used to the syntax. It will quickly become obvious that a lot can be done with the commands in the "Short Tour", but that much remains unclear. This will motivate you towards a systematic and in depth study of the program using the rest of the course sections. • The Files on the CD-ROM The CD-ROM can be used with MacOS, Windows 95/98/NT, or UNIX. It contains the Mathematica notebooks from the book in different versions, as well as (for MacOS and Windows) the program MathReader, with which the notebooks and the animations can be viewed but not changed. The file Info. txt contains up-to-date information.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.