SADRI HASSANI www.com UNDERGRADUATE TEXTS IN CONTEMPORARY PHYSICS Series Editors John P. Hilborn David Peak Thomas D. Rossing Cindy Schwarz Springer New York Berlin Heidelberg HongKong London Milan Paris Tokyo www.com UNDERGRADUATE TEXTS IN CONTEMPORARY PHYSICS Cassidy, Holton, and Rutherford, Understanding Physics Enns and McGuire, Computer Algebra Recipes: A Gourmet's Guide to the Mathematical Models of Science Hassani, Mathematical Methods: For Students of Physics and Related Fields Hassani, Mathematical Methods Using Mathematica®: For Students of Physics and Related Fields Holbrow, Lloyd, and Amato, Modern Introductory Physics Moller, Optics: Learning by Computing, with Examples Using Mathcad® Roe, Probability and Statistics in Experimental Physics, Second Edition Rossing and Chiaverina, Light Science: Physics and the Visual Arts www.com MATHEMATICAL METHODS USING MATHEMATICA® For Students of Physics and Related Fields Sadri Hassani With 93 Illustrations and a CD-ROM Springer www.com Sadri Hassani Campus Box 4560 Department of Physics Illinois State University Normal, IL 61790-4560 USA hassani@phy.edu Series Editors John P. Hilborn Department of Physics Department of Physics United States Naval Academy Amherst College 572 Holloway Road Amherst, MA 01002 Annapolis, MD 21402-5026 USA USA jpe@nadn.mil David Peak Thomas D.
Rossing Department of Physics Science Department Utah State University New Trier High School Logan, UT 84322 Winnetka, IL 60093 USA USA Cindy Schwarz COVER ILLUSTRATI00f: Gradient or differen- Department of Physics tiation with respect to distance is shown in Northern Illinois University two dimensions; the surface represents a func- De Kalb, IL 60115 tion of x and y; the gradient is a vector in the USA xy-plane. Library of Congress Cataloging-in-Publication Data Hassani, Sadri. Mathematical methods using Mathematica: for students of physics and related fields/ Sadri Hassani. - (Undergraduate texts in comtemporary physics) Includes bibliographical references and index.
ISBN 0-387-95523-2 (softcover: alk. Physics-Mathematical models. Mathematical physics-Data processing.0285'53042-dc21 2002070732 ISBN 0-387-95523-2 Printed on acid-free paper. Mathematica is a registered trademark of Wolfram Research, Inc.
© 2003 Springer-Verlag New York, Inc. All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY 10010, USA), except for brief excerpts in connection with reviews or scholarly analy- sis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer sofrware, or by similar or dissimilar methodology now known or hereafter developed is forbidden.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. Printed in the United States of America. 9 8 7 6 5 432 1 SPIN 10881953 Typesetting: Pages created by the author in LaTeX 2e using Springer's svsing2e.com Springer-Verlag New York Berlin Heidelberg A member of Bertelsmannbprmger Science+Business Media GmbH www.com To my wife, Sarah, and to my children, Dane Arash and Daisy Bita www.com Preface Over two years have passed since the publication of Mathematical Meth- ods, my undergraduate textbook to which the present book was to be a companion. The initial motivation for writing this book was to take some examples from Mathematical Methods in which to illustrate the use of a symbolic language such as Mathematica®.
However, after writing the first few pages, I realized very quickly that, for the book to be most effective, I had to go beyond the presentation of examples. I had to talk about the the- ory of numerical integration, discrete differentiation, solution of differential equations, and a number of other topics; thus the delay in the publication of the book. As a result, the book has become a self-contained introduction to the use of computer algebra-specifically, Mathematica-for undergraduates in physics and related fields. Although many of the examples discussed here are taken from Mathematical Methods, no prior knowledge of the content of that book is essential for learning the techniques of computer algebra.
Of course, a deeper understanding of the underlying physical ideas requires reading the relevant sections of Mathematical Methods or a book like it. For those interested in the underlying theories of the examples being discussed, I have placed the appropriate page (or section) numbers in the margin. I have to emphasize that the book does not discuss programming in Mathematica. Nor does it teach all the principles and techniques of the most elegant utilization of Mathematica.
The book can best be described as "learning the essentials of Mathematica through examples from under- graduate physics." In other words, Mathematica commands and techniques are introduced as the need arises.com viii Preface I believe that some understanding of the theory behind the numerical calculations is important, especially if it can invoke some Mathematica usage. Therefore, I have included an entire chapter on the theory of the numerical solutions of differential equations, and a rather lengthy discussion on the theory behind numerical integration. In both discussions I make use of Mathematica to enhance the understanding of the theories. After introducing the essential Mathematica commands in Chapter 1, I introduce vectors-using the calculation of electric fields and potentials of discrete charge distributions-and matrices-using the calculation of normal modes of mass-spring systems-in Chapter 2 as they are used in Mathematica.
Chapter 3 discusses numerical integration and a variety of its applications in different physical settings such as the evaluation of elec- tric, magnetic, and gravitational fields of various sources. Infinite series and finite sums are the subject of Chapter 4, in which the theory of nu- merical integration is used as a nice example of the use of summation in Mathematica. Chapter 5 is devoted entirely to a theoretical treatment of the numerical solution of differential equations, discussing such techniques as the Euler methods, the Runge-Kutta method, and the use of discrete differentiation in solving eigenvalue problems. In Chapter 6, I have cho- sen some examples from classical and quantum mechanics to illustrate how Mathematica solves ordinary differential equations.
This book can be used in conjunction with any undergraduate mathe- matical physics book. Many problems are inherently interesting but cannot be solved analytically. Once the student learns the theory and formal math- ematics behind a concept and solves a number of simple and ideal examples analytically, he or she ought to be exposed to problems arising from real- world applications. However, Mathematica has its great- est impact on the process of learning only if the student has completed the preliminary stage of deeply understanding the analytical methods of solution.
This is hardly the place to enter into the controversy surrounding the role of content and memorization in learning. However, as an educator witness- ing the alarming rate at which calculators and computer-algebra software are substituting the learning of physics and mathematics, I feel obligated to emphasize the distinction between the real utility of technology and its advertised glamour. Technology can be a great tool of learning and teaching once students acquire a certain degree of mathematical maturity. And this maturity can be obtained only through a rigorous training in conventional mathematics that emphasizes content at all levels of a student's education.
The neglect of content-such as the multiplication table at the elemen- tary level, and algebraic/trigonometric identities at the high school level- can have a detrimental effect on the mathematical and analytical ability of the pupil's mind. If the educators sequentially postpone the "memoriza- www.com Preface ix tion" of the multiplication table, algebraic and trigonometric identities, and differentiation and integration rules, arguing that such "facts" are always available on calculators and computers, then students will develop the skill of "pushing buttons" beautifully but will be incapable of doing the simplest integration. Some educators argue that lack of ability to multiply, integrate, or simplify an algebraic expression is not a drawback as long as there are calculators to do the job. To this I have to respond that heavy reliance on calculating machines does to the mind what heavy reliance on vehicular machines does to the body: it makes the mind lazy and inactive.
Our minds need raw data-in the form of numbers and symbols in conjunction with the rules that manipulate them-to develop. A mind without data is like a symphony without notes, an opera without lyrics, a poem without words. I sincerely hope that the readers and users of this book will take this advice to heart. Sadri Hassani Campus Box 4560 Department of Physics Illinois State University Normal, 1L 61790-4560, USA e-mail: hassani@phy.com Nate to the Reader I should point out from the very beginning that, as powerful as Mathemat- ica is, it is only a tool.
And a tool is more useful if its user has thought through the details of the task for which the tool is designed. Just as one needs to master multiplication-s-both conceptually (where and how it is used) and factually (the multiplication tablej-i-before a calculator can be of any use, so does one need to master algebra, calculus, trigonometry, dif- ferential equations, etc., before Mathematica can be of any help. In short, Mathematica, like any Mathematica cannot think for you. other calculational tool, Once you have learned the concepts behind the equations and know how is only as smart as its to set up a specific problem, Mathematica can be of great help in solving user can make it! that problem for you.
This book, of course, is not written to help you set up the problems; for that, you have to refer to your physics or engineering books. The purpose of this book is to familiarize you with the simple~ but powerful-s-techniques of calculation used to solve problems that are otherwise insoluble. I have taken many examples from your undergraduate courses and have used a multitude of Mathematica techniques to solve those problems. I encourage you to explore the CD-ROM that comes with the book.
Not only does it contain all the codes used in the book, but it also gives many explanations and tips at each step of the solution of a problem. The CD-ROM is compatible with both Mathematica 3.com Contents Preface vii Note to the Reader xi 1 Mathematica in a Nutshell 1 1.3 Algebraic and Trigonometric Calculations 4 1.4 Calculus in Mathematica .3 Contour and Density Plots 22 1.4 Three-Dimensional Plots.1 An Example from Optics 28 1.9 Input and Output Control. 43 2 Vectors and Matrices in Mathematica 49 2.com xiv Contents 2.1 One-Dimensional Crystal .2 Two-Dimensional Crystal .3 Three-Dimensional Crystal 58 2.1 A System of Two Masses 70 2.2 A System of Three Masses.3 A System of Five Masses .6 Normal Modes of a System of n Masses 78 2.1 Integration in Mathematica .1 The Simple Example of a Pendulum .2 Shortcomings of Numerical Integration in Mathematica 87 3.3 Other Intricacies of Integration in Mathematica 89 3.2 Integration in Mechanics.1 Position-Dependent Forces 91 3.3 Integration in Electrostatics 106 3.1 Potential of a Ring.2 Potential of a Spiral 109 3.3 Flat Surface Charge Distributions 109 3.4 Integration in Magnetism .2 Current with General Shape.4 Rotating Charged Spherical Shell .5 Rotating Charged Hollow Cylinder 118 3.5 Problems 120 4 Infinite Series and Finite Sums 125 4.1 The Simplest Method 129 4.3 Working with Series in Mathematica 138 4.4 Equations Involving Series .com Contents xv 5 Numerical Solutions of ODEs: Theory 155 5.1 Various Euler Methods.2 Modified Euler Method 157 5.3 Improved Euler Method 157 5.4 Euler Methods in Mathematica 158 5.5 Alternative Derivation of the Improved Euler Method 161 5.2 The Kutta Method.3 The Runge-Kutta Method.4 Higher-Order Equations .2 Discrete Eigenvalue Problem 173 5.6 Problems 173 6 Numerical Solutions of ODEs: Examples Using Mathemat- ~a 177 6.1 Some Analytic Solutions .2 A One-Dimensional Projectile.3 A Two-Dimensional Projectile.4 The Two-Body Problem .1 Precession of the Perihelion of Mercury 196 6.5 The Three-Body Problem .1 Massive Star and Two Planets 198 6.2 Light Star and Two Planets .6 Nonlinear Differential Equations .7 Time-Independent Schr6dinger Equation.1 Infinite Potential Well 211 6.2 The General Case .3 Finite Potential Well.8 Problems 223 References 227 Index 229 www.