Text
                    MATHIMATI(A@
FOR PH Y S I (S
SECOND EDITION
i'
\ '/
II
,/
: r/I;
 1 1 (; j
. I/ /{
\
\
Robert l. Zim'merman
Fredrick I. Olness


c\<v MATHEMATICA FOR PHYSICS Do 70:::(':t60 , \ lO()Q2 "0 
MATHfMATICA FOR PHYSICS SECOND EDITION Robert L. Zimmerman University of Oregon Fredrick I. Olness Southern Methodist University U.I\lERSIDAD DE r,AlHABRIA 8ibiioteca " . .. .. _.:l; '13- i- _.u.2-R5 J IJ.. 2- I, Cic .: ' ,:d -'.:Df2... .A '1 0  TT Addison Wesley -- San Francisco Boston New York Capetown Hong Kong London Madrid Mexico City Montreal Munich Paris Singapore Sydney Tokyo Toronto 
Acquisitions Editor: Adam Black Project Editor: Nancy Benton Production Editor: Joan Marsh Text Designer: Leslie Galen Cover Designer: Blakeley Kim Marketing Manager: Christy Lawrence Manufacturing Coordinator: Vivian McDougal Project Coordination and Electronic Page Makeup: Integre Technical Publishing Co., Inc. The programs and applications presented in this book have been included for their instructional value. They have been tested with care but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications. Copyright @ 2002 by Addison-Wesley Publishing Company, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Library of Congress Cataloging-in-Publication Data Zimmerman, Robert L. Mathematica for physics I Robert Zimmerman, Fredrick Olness-2nd ed. p. cm. Includes bibliographical references and index. ISBN 0-8053-8700-5 1. Mathematical physics-Data processing 2. Mathematica (Computer file) 1. Olness, Fredrick Ive£.. II. Title. QC20.z562003 530' .0285' 53-dc21 2002004623  TT Addison Wesley ---- 1 2 3 4 5 6 7 8 9 10 -MA- 9897969594 www.aw.comlaw 
To Merrie, and to Gloria, Jonathan, Jacqueline, and Benjamin for support and encouragement. 
Contents 1 . Getting Started 1.1 Inttoduction I 1.2 Arithmetic and Algebra 4 1.3 Functions and Procedures 14 1.4 Packages 23 1.5 Calculus 27 1.6 Graphics 32 1.7 Exercises 39 1 2 . General Physics 2.1 Inttoduction 44 2.2 Newtonian Mechanics in Inertial Frames 44 2.3 Newtonian Mechanics in Rotating Frames 77 2.4 Electricity and Magnetism 93 2.5 Modern Physics 116 2.6 Exercises 127 44 3 . Oscillating Systems 3.1 Inttoduction 130 3.2 Linear Oscillations 131 3.3 Small Oscillations 157 3.4 Oscillating Circuits 182 3.5 Exercises 191 130 4 . Nonlinear Oscillating Systems 4.1 Inttoduction 193 4.2 Nonlinear Pendulum 195 4.3 Duffing Equation 232 4.4 Exercises 255 193 vii 
viii Contents 5 . Discrete Dynamical Systems 5.1 Inttoduction 258 5.2 Logistic Map 260 5.3 Other Maps 276 5.4 Fractals 291 5.5 Exercises 296 258 6 . Lagrangians and Hamiltonians 6.1 Inttoduction 298 6.2 Lagrangian Problems without Lagrange Multipliers 299 6.3 Lagrangian Problems with Lagrange Multipliers 335 6.4 Hamiltonian Problems 344 6.5 Hamilton-Jacobi Problems 365 6.6 Exercises 375 298 7 . Orbiting Bodies 7.1 Inttoduction 377 7.2 The Two-Body Problem 378 7.3 Restricted Three-Body Problem 396 7.4 Exercises 433 377 8 . Electrostatics 435 8.1 Inttoduction 435 8.2 Point Charges, Multipoles, and Image Charges 437 8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 467 8.4 Laplace's Equation in Spherical Coordinates 488 8.5 Exercises 511 9 . Quantum Mechanics 9.1 Introduction 513 9.2 One-Dimensional Schrodinger's Equation 515 9.3 Three-Dimensional Schrodinger's Equation 549 9.4 Exercises 576 513 10 . Relativity and Cosmology 10.1 Introduction 578 10.2 Special Relativity 579 10.3 General Relativity 597 10.4 Cosmology 621 10.5 Exercises 639 578 Index 643 
Foreword To be good at physics you no longer have to be good at calculating. When I started doing physics in the early 1970s, it was generally thought that being able to do long calculations by hand was an essential skill. But as it happens I was never very good at such calculations. And so I looked for an alternative, and before long I found one: I discovered that I did not really need to do the calculations myself-I could get a computer to do them instead. My physics papers from the late 1970s were full of elaborate calculations. And from seeing this many people came to the conclusion that I must be a great calculator. But in fact that was far from the ttuth, and what was actually going on was that I was doing all my calculations by computer. Of course, in those days it required a considerable amount of programming effort to get a computer to do one's calculations-particularly when algebra and graphics were involved. But after a few years I realized that with new generations of computers and software engineering tools it would actually be possible to build a single software system that would be able to handle all the various kinds of calculations that one needed to do. And from this realization I came in the end to develop Mathematica. So now that Mathematica exists, what does it mean for physics? In the years since the first version of Mathematica became available (version 1.0 was released on June 23, 1988), a vast amount of new physics has been done with it. Indeed, for example, if one looks today at any of the leading physics journals, one can tell that a large fraction of the calculations and pictures in them were done with Mathematica. But it is not just at the level of research that Mathematica affects the way physics is done. Anyone who learns physics today can do so in a very different way because of Mathematica. And that is the point of this book. What the authors have done is to take the topics from a mainstteam physics course and show how each of them can be handled in a new way with Mathematica. The results are impressive. Over and over again what was once a calculation too lengthy to be reproduced as part of a course now becomes a few lines of Mathematica input that can be executed in a matter of seconds. And instead of having to explain in painful detail the mechanics of the calculation, one can concenttate on the conceptual issues that underlie it. One of the things that one sees in many of the examples in the book is the extent to which Mathematica has narrowed the gap between physics learning and physics research. For once a calculation has been set up in Mathematica, one can tty the calculation in many different cases-not just ones already covered in textbooks, but also ones that may never have been tried before. ix 
x Foreword This book will no doubt be read by many students of physics and many professors. Students may wonder how many of the calculations it describes could ever have been done before Mathematica. Perhaps sometimes their professors will tell them tales from the heroic age of hand calculation. But mostly I hope that students and professors alike will be able to use the technology that we have built and material of the kind that is included in this book to learn and discover physics in a new and exciting way. Stephen Wolfram Creator of Mathematica 
Introduction Computer algebra software has already had an important impact on the way physics is taught and research is performed. While computers cannot replace thinking, they signif- icantly enhance problem-solving abilities of the scientist and student by eliminating the tedious mathematics. As computers become more powerful and more readily available, the scope of problems solved in both research and teaching ttemendously expands. This book serves as a guide for using the computer algebra program Mathematica for physics research and teaching. The flexibility of Mathematica to manipulate analytical, numerical, and graphical expressions will further broaden the scope of problems that the student and researcher can solve. Physics is not a spectator sport. The best way to demonsttate Mathematica is by solv- ing a variety of physics problems chosen to illusttate its ability to display the output in many forms. A significant asset of Mathematica is the ease with which results can be vi- sualized. This feature brings physics problems "alive" so that the reader can interact and experiment with the solutions. One can change the parameters and immediately observe the consequences, thereby gaining deeper insight into the physics of the solution. Instead of being throughly exhausted by the burdensome mathematics required to obtain the answer, Mathematica enables us to focus our attention on understanding the solution. HOW TO USE THIS BOOK This book is intended for undergraduate students, graduate students, and practicing physi- cists who want to learn new Mathematica techniques for solving a general class of physics problems. For the student, we expect this text to be a supplement to the standard course texts in mechanics, electtodynamics, relativity, and quantum mechanics; the student should use this book to get ideas on how to use Mathematica to solve the problems assigned by the insttuctor. Since we cover the canonical problems from the core courses, the student can practice with our solutions, and then modify our solutions to solve the particular problems assigned. This should help the student move up the Mathematica learning curve quickly. This book is also suitable for a course designed to teach the applications of Mathematica to physicists. As such, the design of this book is more like a reference book than a novel to be read cover to cover. Each problem is self-contained (up to user-defined functions discussed at the beginning of each chapter), so the reader can go immediately to the portion of the book that is relevant to his or her problem. xi 
xii Introduction There are two sections of the book which we recommend all readers examine before trying the problems. . The section in this preface on ttoubleshooting, so that the reader knows where to turn in case difficulties arise. . The first chapter contains useful information about style, notation, and short-cuts that we will make use of throughout the book. Note that we assume the reader is reasonably familiar with Mathematica (at least at the level of the tutorial in the Mathematica manual), so we focus on the physics applications and not on rudimentary Mathematica techniques. The book consists of two levels of material. The few sections of each chapter are readily understandable by the undergraduate physics student. The latter portions of the chapters are intended for advanced undergraduate and graduate physics students, and cover a broader range of topics. Each of the chapters 2 through 10 are divided into three parts: . an inttoduction to the physics and Mathematica commands; . solved problems that cover the standard ideas and methods found in the discipline; . unsolved exercises. As the reader gains insight into the power of symbolic computations, they can easily extend the techniques demonsttated here to go beyond these examples and explore more difficult problems. ABOUT THE ELECTRONIC SUPPLEMENT The Mathematica input code for the entire book is available in the electtonic supplement so that you can begin working the examples immediately. We will also post tips and sug- gestions about using this book, extensions to other problems and related fields, and bug fixes (should we encounter any). The electtonic supplement is available as item number 0206-862 from MathSource(TM). MathSource is an on-line archive of Mathematica related materials contributed by Wolfram Research and Mathematica users around the world. You can reach this site at: http://mathsource.wri.com/ The material is also available from the authors web sites at: http://www.physics.smu.edu/-olness and http://darkwing.uoregon.edu/-phys600/ 
Introduction xiii HOW TO USE THE ELECTRONIC SUPPLEMENT To spare the reader tedious typing, we have put all the source code for each chapter into a single notebook file. This enables the reader to start solving problems immediately without re-typing the lengthy commands. Furthermore, if there is any confusion about what input we used to generate these problems, you can simply cross-check with the source code. For example, if you want to solve Problem 6 in Chapter 7, all you need do is to open the source code for chapter 7 (ch7.nb), execute the initialization cells, and then proceed directly to problem 6 (or whatever problem you choose) and begin working. COMMUNICATION WITH THE AUTHORS We welcome any comments and suggestions regarding this book. You may contact us via e-mail or regular mail at: Robert Zimmerman Institute of Theoretical Science University of Oregon Eugene, OR 97403 bob@zim.uoregon.edu Fredrick Olness Department of Physics Southern Methodist University Dallas, TX 75275-0175 olness@mail.physics.smu.edu We welcome bug reports, and will post such information on the MathSource server (should we encounter any). However, we are unable to offer any help debugging problems specific to the compatibility of different Mathematica versions or hardware installations; for this type of assistance, we must refer you to the previous section on Troubleshooting, or to your local system manager. ACKNOWLEDGMENTS It is our pleasure to acknowledge the people who have contributed to this project. We thank Fumitaka Umewaka whose masters thesis, "Applications of Mathematica in Teach- ing Physics," at the University of Oregon, initiated this project. We thank Pearson Edu- cation Japan for publishing the Japanese edition of this book. A special thanks to John G. Cramer of the University of Washington, who updated many of the commands in the first edition. We thank our many colleagues at the University of Oregon and Southern Methodist University, too numerous to name, who have supported the development of this book. We also extend our gratitude to the graduate students at these institutions who have tested solutions to several of the problems and to Lester E. Matson for reading some of 
Introduction the Mathematica files and making consttuctive suggestions. For the second edition, we would also like to thank the many referees who carefully read the manuscript and provided valuable feedback, in particular, John Cramer and Paul Abbott, who provided many useful comments. Fred Olness would like to thank Davison E. Soper of the University of Oregon for inttoducing him to Mathematica. He would like to thank the Lightner-Sams Foundation for support, and Southern Methodist University for an Insttuctional Technology Grant. Fred Olness also acknowledges the U.S. Department of Energy for support of his high energy physics research; many techniques developed in the course of his research were incorporated in this book. At Addison-Wesley, we would like to acknowledge the invaluable contributions by Adam Black, Nancy Benton, and Joan Marsh. We also thank those who contributed to the first edition: Stuart Johnson (Physics Editor), Amy Willcutt, Jennifer Albanese, Nev Hanke, Eileen Hoff, and Laurie Pettycki. At Wolfram Research, we thank Glenn Scholebo for elegantly converting the Mathe- matica notebooks into final typeset form for our first edition, and Stephen Wolfram for contributing the foreword. At Integre Technical Publishing Company, we thank Don DeLand, Leslie Galen, Karen Couzin, and Lynn Ryan for their work on the second edition. 
Troubleshooting This manuscript was generated directly from a Mathematica notebook to minimize the possibility of inttoducing errors. The draft manuscript was written in Mathematica, and then converted to Tex using the TexSave feature. Final formatting was performed using the Tex source. The final version of the Mathematica code was run using version 4.1, but is fully com- patible with all Mathematica versions back to 3.0. There are subtle differences between different versions and implementations of Math- ematica. This means that on occasion the reader will find that some of the examples pre- sented in this book need to be slightly modified to adapt to your particular version. We have tested these examples extensively on different platforms and with different versions to ensure that they are robust. However, we list below the most common difficulties that the reader is likely to encounter. In our examples, we have been careful to present enough intermediate output so that the reader can cross-check their results for consistency. This allows the reader to isolate any differences that may arise, and find the cause quickly. Possible TEX Conversion Errors The typesetting features of Mathematica significantly enhance the user's ability to read and understand the Mathematica output. Unfortunately, this also means that the process of converting the Mathematica code to TEX is significantly more complex. While we have been very careful to avoid errors, there is the possibility that some characters are corrupted in the conversion process. Unfortunately, one of the more common errors is to have missing braces" {" and "}". For this reason, in part, we have posted the complete set of input files on the web. Should you encounter a "mysterious" problem that you suspect may be linked to a typographic error, you can use the input source code (which has not had any conversion) to ensure you have the correct expression. In fact, we recommend you use the input source code from the web in general to save yourself the effort of re-typing our expressions. Order of Roots in Solve A significant difference between different Mathematica versions is the order of the solu- tions returned by Solve and DSol ve. Throughout the book, you will note we are careful to select the desired root using the [ [i] ] notation. If you have difficulty with the prob- lems, this is one of the first places to look. Compare the intermediate output displayed in the book with your results. Use this information to isolate the problem, and determine if it is due to the ordering of the roots of the Solve command. xv 
xvi Troubleshooting Debugging Techniques To save paper (and trees), we have not displayed intermediate output for all expressions. Additionally, we have not displayed intermediate graphics output using the $Display- Function->Identity command. While this is a good practice when writing a book, when we were developing the problems we did display this intermediate output to help guide us through the problem; only after we obtained our solution did we go back and "clean up" the output. How to Debug Modules and User-Defined Functions In Chapter 3, Section 2, Problem 5, (Understanding the User-defined procedure small- Os c) we discuss how to redefine a Module so that the variables are Global and can be examined. This allows the reader to debug a Module program by stepping through each statement of the Module individually to tty and isolate the error. This is a very useful debugging technique. Commands That Never Return an Answer In cases where the Mathematica command takes a long time (more than a minute on a  1 GHz Pentium 4) to return an answer, we have indicated this in the text. If you wait a long time, get no output, and suspect a problem, there are many ways to approach this problem. The most obvious is to break the procedure up into smaller steps. We often group commands together to shorten our solution. We must confess that when we initially solved the problem, we actually performed each step individually, examined the output, and after- wards decided the most efficient set of steps to use and display. Avoid the FullSimplify Command In particular, if you are having ttouble with lengthy expressions, tty to avoid the Full- Simplify command. Until you know the scope of your problem, you will find that the Expand, Together and ordinary Simplify command are much more efficient at re- ducing the answer. Once you have massaged the result into something Mathematica can swallow in a single bite, then you may want to tty and FullSimplify the result. Animation The details of animating a series of graphics varies widely with different implementations of Mathematica. In this text we simply show the reader how to generate the sequence of graphics. The reader must refer to the computer specific user guide for the details of displaying the animation. Clearing Variables If Mathematica is yielding unusual results, a common cause is that there are variable defi- nitions (possibly from a previous problem) that are conflicting with the assumed definitions for the present problem. The command Clear [ "Global' * "] will solve most of these problems. In fact, each chapter of this book was initially a single Mathematica notebook. 
Troubleshooting xvii Using the Clear [ "Global \ * "] command, we were able to run each chapter as a single Mathematica session from start to finish. (Again, this helped us eliminate errors, and verify that our examples were correct.) While this command should solve most all problems of this type, it may be worth restarting the kernel if mysterious problems still persist. WHAT'S NEW WITH MATHfMATICA IN THE SECOND EDITION The first edition of our text was produced with Mathematica version 2.2. The current ver- sion of Mathematica has dramatically changed since that time. . Typesetting. Beginning with version 3.0, Mathematica inttoduced typeset input and output. This significantly shortens the length of the output (compare with our first edition); more importantly, it makes the input and output much more readable. Ex- pressions that previously would span multiple pages (or fill the computer screen) are now succinctly displayed. . Mathematica has greatly expanded its knowledge base. In the first edition, we often had to help Mathematica with complex integrals or differential equations. In this edition, Mathematica is fully capable of evaluating such expressions. . For our first edition in 1995, it took about an hour on a "modern" computer to execute a chapter. With improved Mathematica algorithms and improved CPU's, an entire chapter runs in a few minutes. WHAT'S NEW WITH THIS BOOK IN THE SECOND EDITION In this second edition we have significantly expanded the number and variety of problems. In particular, we have expanded the book from seven to ten chapters; the three additional chapters are on Nonlinear Systems and Chaos, Discrete Systems, and Chaos and Orbiting Bodies. New problems and exercises have also been added to all chapters. 
CHAPTER 1 Getting Started 1.1 . INTRODUCTION 1.1.1 . Computers as a Tool The solution of realistic physics problems is often hampered because the algebra is too complex for anyone but the dedicated researcher. Just as the calculator eliminated labo- rious numerical computations, symbolic software programs eliminate arduous algebraic computations. While computer power is no substitute for thinking, it spares the scientist from performing mundane mathematical steps, and thereby frees time for creative think- ing. The scientist is able to explore complex relationships among quantities, ask "What if. .. ?", and obtain an immediate answer. Mathematica is only one of the popular systems for doing such calculations; other systems include Maple, Derive, Axiom, Macsyma, and Reduce. Because there are many ways to solve physics problems, we present a variety of styles to illusttate different ways of solving similar problems using Mathematica. We emphasize that the solutions presented here are not necessarily the most efficient for dealing with all possible instances. While we do discuss writing efficient Mathematica code, we sometimes sacrifice the most elegant or efficient solution in favor of one that is most easily understood pedagogically. For example, we inttoduce some user-defined procedures to automate repet- itive tasks in an intuitive way. Had our goal been to write an efficient "black-box" program that could handle all possible inputs in an error-free manner, the routines would be less pedagogical, more complex to read, and encumbered with additional code to ttap error conditions. Where appropriate, we prompt the reader to expand upon our solutions. Each chapter has a short overview of the major physics and mathematics topics empha- sized in the chapter. The problems are chosen to cover a broad range of physics problems and to illusttate a variety of Mathematica procedures. Exercises are included at the end of the chapter to reinforce the techniques developed in the examples, and to suggest additional applications not covered. Our goal is to focus on the Mathematica techniques that are most appropriate for solv- ing physics problems; thus, we assume the reader is familiar with the most basic features of Mathematica as discussed in The Mathematica Book, Fourth Edition, by Stephen Wol- fram. At a minimum, the reader should be familiar with the Tour of Mathematica, which is contained in The Mathematica Book. 1 
2 Chapter 1 Getting Started 1.1.2 . A Note about Notation and Style Here we make a few notes about what notation we do and do not use throughout the text, as well as some stylistic issues. 1. We do not use subscript notation for variables. Although this often makes the output more readable, we encounter some very subtle features when using subscript nota- tion. Therefore, our preference is to create variables in the form {x 1, x2, x3, ...} rather than {xl' X 2 ' X 3 , ...}. We explain this in more detail in the next section. 2. Initially we will type certain symbols in their expanded form. For example, the sym- bol "->" is equivalent to "-7"; however, we will initially enter this expression in the format "->" so the beginning Mathematica user knows exactly what to type. 3. We often use special characters, including letters from the Greek alphabet. These can be entered using the palettes, or using keyboard short-cuts. For example, the character (J can be entered by typing (esc)q(esc), or by typing (esc)\theta(esc), where (esc) represents the escape key. The latter form may be more familiar to those who use the TEX typesetting program. 4. In general, we avoid inttoducing short-hand definitions for commands with a lengthy name. While we often use such short-cuts in our personal work, doing so here makes it difficult for the reader who must first look up our definition for our short-cut, and then look up the Mathematica command. This philosophy is good practice when you are sharing your notebooks with others. In place of using short-cut commands to save typing, Mathematica has a very useful menu feature called Complete Selection. Refer to the description of this command in the Help Browser. 5. We will use the semicolon ";" to suppress unwanted intermediate text and graphics output. While this makes the book more compact, when you are initially solving a problem you probably will want to view the intermediate output to check for errors. 6. Our preference is to turn off the automatic spell checking within Mathematica. Again, this is helpful for debugging, but for a finished product (such as this book), it is not necessary. In[l]:= Off [General :: spelll]; Off [General: : spell]; 1.1.3 . Notation and Symbols (For Experts Only) Here we explain some of the subtle features of Mathematica notation. Beware: you should read this section only if you are an experienced Mathematica user, and need to use sub- script notation for variables, e.g., {Xl' X 2 ' X 3 ' ...}. Otherwise, you should immediately skip to the next section. We include this section here so that if you encounter sttange behavior when ttying to use subscript notation for variables, you will know where to look for explanations. This section also uses some commands that are not inttoduced until later in this chapter; therefore, you may find it best to come back to this section after reading the rest of the chapter. Subscript notation for variables is tricky because you can have two expressions that have identical output display formats, but they can in fact have very different internal forms. 
1.1 Introduction 3 Debugging Mathematica code with such expressions becomes complicated, and this is why, in general, we do not use subscript notation in this book. For example, let us tty to use the symbol xl as an independent variable. If we enter this symbol using the basic input palette or with a keyboard short-cut, we obtain In[2J:= xl//FullForm Out[2J= Subscript [x, 1] When we tty to use such notation in a simple expression, we are in for some surprises. The following expression looks simple enough. In[3J:= term = a Xl + b + ex Out[3J= cx+ax 1 +bx 2 But, if we tty to make a substitution for the variable X (without any subscript), which we intend to be a variable independent of xl' we obtain In[4J:= term/.{x....l} Out[4J= c+a1 1 +b1 2 The result is obviously nonsense. Next, we make use of the Symbolize function contained in the package Utili- ties 'Notation'. In[5J:= «utilities'Notation' In[6J:= ?Symbolize "Symbolize [boxrs] forces any box structure matching boxrs to be treated internally as a single symbol anywhere it appears in an input expression." However, when we tty this command in a simple manner, the result is an error. In[7J:= Symbolize[x l ] Symbolize :: badSymbolizeBoxes : The Symbolize boxes x do not have an em- bedded NotationBoxTag TagBox. The Symbolize statement Symbolize[x ] may not have been entered using the palette, or the embedded TagBox may have been deleted. The embedded TagBox ensures correct parsing and retention of proper styling and grouping information. 1 1 Out[7]= $Failed If, instead, we use the Symbolize command from the Notation Palette, we get a vari- able that appears to be identical to xl defined above, but has a very different internal form. In[8J:= Xl//FullForm (* Entered from the Notation Palette *) Out [8J= NotationBoxTag [SubscriptBox ["x", "1"] ] 
4 Chapter 1 Getting Started Using this form, we can Symbolize the variables xl and x 2 ' and define a new expres- sion, term2, using these variables. In[9J:= Symbolize[x l ] Symbolize [] term2 = ax l + bX 2 + ex; Now the substitution works properly, and Mathematica can distinguish between the variables x, xi' and x2 . In[10J:= term2 I.x.... 1 Out[10J= c+ax 1 +bx 2 Again, the moral of the story is that if you are going to use subscript notation {xl' x 2 ' x 3 ' . ..}, you need to know these subtle features; if you are satisfied to use the simpler notation {xI, x2, x3, ...} you can ignore this entire section. 1.2 . ARITHMETIC AND ALGEBRA 1.2.1 . Arithmetic and Notation The simplest commands in Mathematica are arithmetic commands. These commands are: addition (+), subttaction (-), multiplication (space or *), and division (f). For example, type in the following fraction and press enter (or shift-return keys) to evaluate the command. In[llJ:= 2*6 (12+4)/( 12-4) Out[l1J= 24 Note in the above example we have used all operations including both space and "*,, for multiplication. More sophisticated commands are exponent C), square root (Sqrt), factorial (!) and double factorial (! !). Examples of these commands are In[12J:= {2 A 3,Sqrt[2],4!,4!!} Out [12J= {8,..[2, 24,8} Notice in the previous examples we used three different kind of brackets. Each type is used for a specific purpose: . Square brackets [...] are for functions or commands like Sqrt[2], . Curly brackets {...} are used to make lists of objects like {1, 2, 3}, and . Parentheses (...) are used to group terms like 21(1 + 1). 
1.2 Arithmetic and Algebra 5 The command N is used to convert expressions to numerical values (if possible). Wrapping the function N around the Sqrt function, you get In[13]:= N[Sqrt[2]] Out[13]= 1.41421 An alternate way of entering the numerical procedure is to use postfix notation: In[14]:= Sqrt[2]//N Out[14]= 1.41421 The postfix form is useful because it allows repeated operations to be efficiently expressed. In[15]:= 211Sqrt IIN Out[15]= 1.41421 While Mathematica only displays a limited number of digits as determined by the Print- Precision option (which may be found in the Options Inspector), we can view more digits using a second argument for the N command: In[16]:= N[Sqrt [2],50] Out[16]= 1.414213562373095048801688724209698078569 6718753769 We also show the previous command using the postfix notation. In[17]:= Sqrt [2] I/N[#, 50]& Out[17]= 1.414213562373095048801688724209698078569 6718753769 In this case, the syntax N [#, 50] &: represents a pure function that will take a single argument-the Sqrt [2] , in this case. The argument will be inserted in Slot number one represented by the symbol #. The symbol &: is short-hand notation for the Function function. Mathematica has several built-in constants such as: In[18]:= list1 = {I, 7f, e, 00, GoldenRatio, EulerQamma,Catalan,O} Out[18]= {i, If, e, 00, GoldenRatio, EulerGamma,Catalan,deg} We have named the set list1. The relation lhs = rhs assigns left-hand-side (lhs) to be the value of right-hand-side (rhs). From then on, lhs is replaced by rhs whenever it appears. The list can be recalled at a later time by typing list1. To obtain the numerical values in the list use the command N: 
6 Chapter 1 Getting Started In[19]:= list1/1N Out[19]= {O. + 1.:ft., 3.14159, 2.71828,00, 1.61803,0.577216,0.915966,0.0174533} You can clear list1 from memory by typing: In[20]:= Clear[list1] It follows that list1 has lost its assignment, In[2i]:= list1 Out[2i]= list1 You can evaluate complex values as you do real values. The Mathematica symbol for a complex quantity is 1= H (or i found in the menu under Edit->Palettes). These three input forms represent identical expressions. In[22]:= {Sqrt[-1],I,Ji.} Out[22]= {L:ft., i} The same arithmetic commands that work with real numbers also work with complex numbers. For example, In[23]:= (U+6I)/(2-U) Out[23]= -2+i Mathematica defines Abs for absolute value, Conjugate for complex conjugate, and Re and J:m give the real and imaginary parts of a complex number: In[24]:= {Abs[2+I],Re[2+I],Im[2+I], Conjugate [2 + I] } Out[24]= {-VS,2,1,2-i} 1.2.2 . Algebraic Manipulations Some useful commands for manipulating expressions are: Expand, ComplexExpand, ExpandAll, PowerExpand,Factor, Simplify, FullSimplify, and Together. For example, use the command Expand to expand the expression (1 + ;x2)5: In[25]:= eq1 = Expand[(1 +x A 2)AS] Out[25]= 1 + 5x 2 + 10x 4 + 10x 6 + 5x 8 +x 10 where we named the expression eq1. The command Factor reduces eq1 to its original form (using the postfix form), In[26]:= eq1//Factor Out[26]= (1+X 2 )5 
1 .2 Arithmetic and Algebra 7 You can also factor eql over the complex numbers if the GaussianJ:ntegers op- tion of Factor is used: In [271 := Factor [eq1, GaussianIntegers- > True] Out[27J= (_i+X)5 (i+X)5 This option was added to Factor with a "rule" of the form "option -> value". The Options command displays the known options of a specific command: In[28J:= O,ptions[Factor] Out [28J = {Extension -7 None, GaussianIntegers -7 False, Modulus -7 0, Trig -7 False} You have additional conttol of an expansion with Expand [expr,patt] . This com- mand expands expr without expanding any parts of expr that are free of the pat- tern patt. For example, the following expression expands only the terms in y, leaving (l+x) 5 unexpanded: In [29J := eq1 = Expand [ (x+ 1) 5(y+ 1) -2, y] Out[29J= (l+x)5+2 (1+x)5 y + (1+x)5y2 The command Simplify can then be used to restore the original form: In [3 0 J : = eq1 / / Simplify Out[30J= (1+x)5 (1+y)2 Simplify tries to reduce an expression to the smallest number of terms. If this command does not work, then tty FullSimplify. Using Simplify and FullSimplify on complicated expressions may take a long time because the commands have to test a large number of forms to find the simplest one. With more involved expressions you may want to exercise more conttol of the process by using specific commands. You can broaden the use of Simplify by adding conditions to the variables. For ex- ample, consider In[31J:= S qrt [(ab c d Cos [8]) -2] / /Simplify Out[31J= -J a 2 b 2 c 2 d 2 COs[e]2 Simplify did not change the expression. If you have additional information about the variables, Simplify can make use ofthis: In [32J : = Simplify [ Sqrt [ (a bed Cos [8]) 2], { a > 0, b e Reals, c e Complexes, 1£/2 <8 <1£}] Out[32J= -a Abs[b] Cos[e] In this case, it can exttact a, b, and Cas [0] from the Sqrt, but not cord. 
8 Chapter 1 Getting Started Another example is Cos [n n] and Sin [n n] when n is an integer. Applying Sim- plify to these functions with the restriction that n is an integer, you get In[33]:= SiD\plify[{Cos[ n 71"], Sin[n7l"]}, n e Integers] Out[33]= {(_1)n, O} The symbol E is a short-hand for the Element function; this symbol is contained in the BasicInput palette. There are several ways to manipulate trigonometric functions. Compare the two cases where we Factor this expression with and without the option Trig->True. In[34] : = Factor [Cos [4x] 2 - 2Cos [4x] Sin [3x] + Sin[3x] 2] Out[34]= (Cos[4x] -Sin[3x])2 In[35]:= Factor [Cos [4x] 2 - 2Cos [4x] Sin[3x] + Sin[3x] 2, Trig- > True] Out[35]= (cos [] +Sin[])4 (1-2 Cos[2x] -2 Sin [x] +2 Sin[3x])2 Using the command TrigFactor is equivalent to Factor with the option Trig ->True. In[36]:= Cos[4x]2-2Cos[4x] Sin[3x] +Sin[3xr2// TrigFactor Out[36]= (coS[]+Sin[]( (1-2 Cos[2x] -2 Sin [x] +2 Sin[3x])2 Other commands that have the option Trig->True include Expand, ExpandAll, Apart, Together, Simplify. If some of the symbols represent complex numbers, then you can use ComplexExpand to simplify the expression. In[37]:= ComplexExpand[Exp[I8]] Out[37]= cos[e] +i Sin[e] In this case, () is taken to be a real angle. If some of the symbols represent complex numbers, then you can use ComplexExpand [expr, {xl, x2, . . . }] to simplify the expression. The symbols{ xl, x2, . . .} are assumed to be complex. For example, if we allow for () to be complex, we obtain: In[38]:= ComplexExpand[Exp[I8],8] Out[38]= e-Im[e] Cos[Re[e]] +ie-Im[e] Sin[Re[e]] The type of ComplexExpand output can be conttolled with the following options: In[39]:= O,ptions[ComplexExpand] 
1.2 Arithmetic and Algebra 9 Out[39J= {TargetFunctions {Re, Im, Abs, Arg, Conjugate, Sign}} ComplexExpand will tty to return results in terms of the TargetFunctions. For example, In[40J:= ComplexExpand[Exp[I8],8, Targetl"unctions .... Abs] ie_ iAb[e]2 [ e Abs[e]2 ] e 2" e Cos - + + 2 2e ie¥ iAb n e ]2 Sin [ :!?+ Abs[e]2 ] 2 2e Out[40J= 1.2.3 . PowerExpand Next, let us say a few cautionary words about the PowerExpand command. This can be very useful for certain types of expressions. In [41J:= {Sqrt [a-2], Log [alb], Log[aAb]} / / PowerExpand Out [41J= {a, Log [a] - Log [b] , b Log [a] } However, the operations of the PowerExpand command are not always correct. With- out PowerExpand, we obtain both roots. In[42J:= Solve[Sqrt[x A 2] ==a,x] Out[42J= {{x-a}, {xa}} With PowerExpand, we miss the negative root. In[43J:= Solve [Sqrt [x-2] == a / /powerExpand, x] Out[43J= {{xa}} In short, PowerExpand should be used with care. 1.2.4 . Simple Rules Rules are useful for making temporary substitutions; this allows us to make substitutions into expressions without those substitutions becoming permanent definitions. A simple example is to consider In[44J:= {a,b}/.{a.... b, b....c} Out[44J= {b, c} The substitution operator /. applied the list of rules {a->b,b->c} once to {a,b}. It is obvious that the rule has only been applied a single time by comparing with multiple application of this rule as in this command: 
10 Chapter 1 Getting Started In[45]:= {a,b}//.{a.... b, b....c} Out[45]= {c, c} The replacement operator II. applies the list over and over again until the expression no longer changes. Beware, as expressions such as the following will generate an endless loop. In[46]:= a//.{a....b,b....a} (* generates endless loop *) ReplaceRepeated :: rrlim : Exiting after a scanned 65536 times. Out[46]= a 1.2.5 . A Homemade Complex Conjugate with SuperStar We will often find it convenient to take the complex conjugate of an expression where we assume all complex quantities are explicit. However, the obvious rule, {J: -7 -J:}, does not always work: In[47]:= 2I/.{I.... -I} Out[47]= 2 i To see why this fails, we can use the FullForm command to see how Mathematica represents these expressions internally. In[48]:= 2I//FullForm Out[48]= Complex[O, 2] In[49]:= {I.... -I}//FullForm Out[49]= List [Rule [Complex [0, 1] , Complex [0, -1]]] We see the problem is that Mathematica is searching only for patterns of the form Com- plex [0, 1] . This gives us an idea for a rule that will accomplish what we desire. In[50] : = conjugateRule = {Complex [re_, im...] - > Complex [re, -im] }; We verify that conjugateRule works as expected: In[51]:= 2I/.conjugateRule Out[51]= -2 i Be sure to use the single replacement operator t. and not 1/. or you will have an endless loop. For many physics problems, we find that this conjugateRule is more useful than the built-in Conjugate function. For this reason, we find it convenient to create our own "homemade" conjugate function. We will make use of the SuperStar operator to allow for an elegant short-hand notation. 
1.2 Arithmetic and Algebra 11 In[52J:= Unprotect[SuperStar]; In[53J:= SuperStar /: exp_* : = exp /. {Complex [a_, b_] :-+ Complex [a, -b]} protect[SuperStar]; The SuperStar /: notation above is redundant, but we include it so it is clear which symbol is associated with this rule. (Try the definition without this assignment.) We Protect [SuperStar] so that we don't erase this definition with the Clear ["Global '*"] command. Let us test that this works. (Note, we enter this symbol as a superscripted asterisk.) In[54J:= (a + Jib + e ie ) * Out[54J= a_ib+e- ie Equivalently, we could write: In[55J:= SuperStar [a + Ji b + e ie ] Out[55J= a_ib+e- ie Conttast this with the built-in function Conjugate: In [56J := Conjugate [a + Jib + e ie ] Out [56J= e- i Conjugate[e] + Conjugate [a + i b] The Conjugate function is more cautious as it does not assume {a, b, B} are real (as SuperStar does); however, for our examples, we'll find this SuperStar definition to be better suited. 1.2.6 . Immediate and Delayed Substitutions Previously we used the "- >" form of the substitution command-this makes an immediate substitution, as opposed to a delayed substitution. Consider the following substitutions. First, we use the immediate substitution, "->" In [571 := {x, x, x} /. {x.... Random[]} Out[57J= {0.336606, 0.336606, 0.336606} Notice the elements of the list are identical. Conttast this with the case where we use the delayed form of the substitution, ": >" In[58J:= {x, x, x}/.{x:>Random[]} Out[58J= {0.780078, 0.71793, 0.653235} Here, the elements are all distinct because the right -hand-side of the rule (Random [ ] ) was not evaluated immediately, but was delayed until after the substitution. 
12 Chapter 1 Getting Started 1.2.7 . Selecting Parts of Expressions We often work with only a portion of a complicated expression. The Part command can be used to exttact the individual terms of the complete expression. Consider the relation In[59]:= eql = alx+ a2xA2 + a3 x A 3 Sin [x/y] ; You can exttact the third term by entering In[60]:= Part [eql,3] Out[60]= a3x 3 Sin [] or equivalently In[61]:= eql[[3]] Out[61]= a3x 3 Sin [] Subexpressions can be obtained as follows: In[62]:= eql[[3,1]] Out[62]= a3 If I want the first and third parts, I enter: In[63] : = eql [[ {3, 1}]] Out[63]= alx+a3x 3 Sin [] Notice the additional curly braces {} and compare with the previous expression. If you didn't know the position of Sin [x/y] , then you could have entered In[64]:= position = position [eql, Sin [x,ly] ] Out[64]= {{3, 3}} You can also replace a term in an expression with a new term using the command Re- p1acePart [expr,new,n]. This command replaces the nth part of expr with new. Let us replace Sin [x/y] with Cos [x/y] in eql at posi tion. In[65]:= ReplacePart [eql, Cos [x/y] , position] Out[65]= alx+a2x 2 +a3x 3 Cos [] 1.2.8 . Algebraic Equations Consider solving algebraic equations such as a x2 + b x + c == O. The symbol == is used to define the algebraic equation. (Recall the single symbol = creates an assignment.). The principal Mathematica commands for symbolically solving equations include Solve, Reduce, Eliminate, and Roots. If we take the quadratic equation as an example: 
1 .2 Arithmetic and Algebra 13 In [ 66] : = eq1 = a x- 2 + b x + C = = 0; the Solve command returns two solutions. In[67]:= so11 = Solv e [eq1, x] {{x  -b- Y b 2 2 a -4aC }, Out[67]=  {X-7 -b+y2a-4aC }} The solution is returned in the form of a rule, and these rules are sITung together into a list. The substitution operator ( - » allows the solution to be substituted at a later time into any expression containing x. If only the second root is desired, it can be selected using the Part command discussed earlier; we use the short-hand form of the Part command by appending [ [2]] to the end of the solution: In[68]:= x/.so 11[[2]] -b + Y b 2 - 4 a c Out [68]= 2a A similar command follows for taking the first solution in the list. The roots can be verified by substituting soIl back into the original equation: In[69]:= eq1/.s011//Simp1ify Out[69]= {True,True} The solution also follows from the commands Roots and Reduce: In[70]:= Roots [eq1,x] -b - Yb 2 - 4 a c -b + Y b 2 - 4 a c Out[70]=x== 2a Ilx== 2a In[71]:= Reduce [eq 1,x] -b - Yb 2 - 4 a c Ou t [71] = x = = 2 a & &a '" 0 I I -b+Yb 2 -4ac x == 2 a &&a", 0 II a == O&&b == O&&c == 0 I I c a == O&&x == -j;&&b '" 0 Roots and Reduce returned the logical set of solutions to the equation. The operator II is the logical OR function, &:&: is the logical AND function, and * (or ! =) means not equal to. Reduce returns a complete set of solutions and does not assume that the parameters in an equation are generic; i.e., that { a*O , b* 0, . . . }. Let us consider the solution for two coupled equations: In[72]:= eq2 = {ax+by==c,ax-by==d}; 
14 Chapter 1 Getting Started Using Reduce to get the solution, we find In[73]:= eq3 = Reduce [eq2, {x, y}] Out[73]= a == O&&b == O&&c == O&&d == 0 II c a == O&&d == -c&&y == i)&&b * 0 II b == O&&d == c&&x == =&&a * 0 II a c+d c-d x == -&&y == -&&a * O&&b * 0 2a 2b Reduce tries to search for all possible solutions, and therefore takes longer than Solve. As before, the desired part of the solution can be exttacted using the Part command-we use the syntax [ [4., {1, 2}] ] to exttact the first and second sub-part of the fourth part. In[74]:= eq3 [[4, {1, 2}]] c+d c-d Out[74]= x == -&&y == - 2a 2b If you want to restrict a and b to be nonzero at the start, then enter In[75]:= eq3 = Reduce [{eq2, a;' 0, b;. O}//Flatten, {x, y} ] c+d c-d Out[75]= x == -&&y == -&&a * O&&b * 0 2a 2b where Flatten returns a flat list of equations without any sub-lists. 1.3 . FUNCTIONS AND PROCEDURES 1.3.1 . Built-In Functions Mathematica has many built-in functions, including Sin [x] , ArcCos [x], Cosh [x] , ArcSinh [x] , and BesselJ [n, x] . In the following, we input these functions in Stan- dardForm (so you know exactly what we typed), and the output is displayed in Tradition- alForm. In[76]:= list1 = {Sin [x] , ArcCos [x], Cosh [x] , ArcSinh[x],BesselJ[n,x]} Out[76]= {Sin[x),ArcCos[x),Cosh[x), ArcSinh[x),BesselJ[n,x]} These functions can, of course, return numerical values: In[77]:= list1 /. {x -+ 0.5, n -+ 2} Out[77]= {0.479426, 1.0472, 1.12763,0.481212,0.030604} 
1.3 Functions and Procedures 15 All Mathematica functions start with a capital letter; for this reason, we generally create variables whose names begin with a lower-case letter to avoid conflicts with any possible Mathematica definitions. Information about any specific function can be obtained by prepending ? to the function: In[7B]:= ?Sin Sin[z] gives the sine of z. More... By prepending ?? to the function, we can obtain additional information. In[79]:= ??Sin Sin[z] gives the sine of z. More... Attributes [Sin] = {Listable, NumericFunction, protected} In this case, we learn that the Sin function has Listable as an Attribute. This means that the Sin function can be trivially applied to a list of objects: In[BO]:= list = {O, 45, 90, 180, 270, 360}*o; Above, the Degree command "0" is a defined constant that will convert degrees to radians. We now apply Sin to the list. In[Bl]:= Sin [list] Out[Bl]= {o, .1 ' 1, 0, -1, o} Note that in a FOrITan or C program this operation would require writing a loop state- ment. This example gives us a glimpse at the features that make Mathematica programming much more flexible than ttaditional programming languages. 1.3.2 . User-Defined Functions A frequently used feature of Mathematica is the ability to define your own functions. A simple example is In[B2]:= f1[x_] = x-2; The variable x on the left-hand side of the equation represents a dummy variable; the fact that this is a dummy variable is indicated by the underscore symbol "_" following the x. Let's verify that this works: In[B3]:= f1[2] Out[B3]= 4 Had we not included the underscore symbol "_" in the definition, we would obtain a function that would operate only on the specific variable with the label x and not on any general variable. 
16 Chapter 1 Getting Started In[84]:= f2 [x] = xA2; {f2 [x], f2 [2]} Out[84]= {x 2 ,f2[2]} In the definitions of both £1 and £2, we used the "=" symbol to make an immediate assignment. In most cases, this is what you probably want (and it executes faster if it suits your purpose). However, there are instances where you require a delayed assignment via use of the " : =" symbol. We illustrate with an example. In[85]:= a=1; f3 [x.] := :If [x :S a, -1, 1]; f4 [x_] =:If [x:s a, -1, 1]; Here, we have created two functions. The first, £3 uses the delayed assignment, ": =", and the second, £4 uses the immediate assignment, "=". Notice that the variable a is set before the functions are defined. As long as we don't need to change a, the functions will work as expected. In[86]:= {f3[2],f4[2]} Out[86]= {1,1} However, if we want to change the value of a, the function £4 that uses the immediate assignment, "=", will not work properly. In[87]:= a = 3; {f3 [2], f4 [2]} Out[87]= {-1, 1} To see why, let's examine what Mathematica knows about the functions. In[88]:= ?f3 Global'f3 f3[x.] := If[x s a, -1, 1] In[89]:= ?f4 Global'f4 f4[x_] = If[x s 1, -1, 1] Now the problem is obvious; the function £3 used the delayed assignment, ": =", so that it always uses the current value of a. In conttast, the function £4 used the immediate assignment, "=", so that it immediately evaluates the right-hand side of the function defini- tion and substitutes the value 1 for a; once this value of a is "hard-wired" into the function, no later re-definitions of a will change the function £4. Let us clear the assignment to a, In[90]:= Clear[a] 
1.3 Functions and Procedures 17 The factorial function provides a nice example of procedural programming. Although Mathematica has a built-in factorial function (!), we can define our own using only two definitions. In[91]:= Clear[fac] We clear any previous definitions of the function £ac with the command Clear simply as a precaution. In[92]:= fac[l] = 1; fac [n.Xnteger?positive] : = n fac [n - 1] The first command simply defines the factorial of 1 to be 1. The second command states that the factorial of n is simply n times the factorial of n-1; this recursion relation defines the factorial function for any positive integer. To ensure that this definition is applied only to the case of positive integers, we include some parameter checking in the definition. The syntax n_J:nteger ensures that this definition will be used only if the argument is an integer. The syntax ?positive performs a test on the argument to ensure it is positive. The combination of these checks on the input parameter ensures the rule will apply only to positive integers. We check that this implementation is correct by evaluating: In[93]:= {41 I fac [4] I fac [4.] I fac [-4] I fac [a]} Out[93]= {24, 24, fac[4.], fac[-4], fac[a]} As promised, only arguments with positive integers are evaluated using this set of rules. 1.3.3 . Pure Functions In many cases it is desirable to define procedures using pure functions. Pure functions differ from the ordinary functions we have encountered in only one respect-they do not have a name. The command Function [x, body] defines a pure function where the variable is x and body represents the body of the function. A trivial example of a function with two variables is: In [94] : = f1 = Function [{x, Y} I Sin [x /y]]; f1 [a , b] Out[94]= Sin [] Clearly, in the definition of the £1 function, a and b represent dummy variables. A slightly different notation that accomplishes the same end is In [95] := f2 = (Sin[#1/#2]) &; f2 [a , b] Out[95]= Sin [] 
18 Chapter 1 Getting Started Pure functions are particularly useful when making substitutions in differential equa- tions. For example, if we consider the differential equation below, and attempt to change from the function x [t] to a different function y [t] , the obvious substitution does not work. In[96]:= eql = x'[t] + ax[t]; eql /. {x[t] -+ y[t] + b} Out[96]= a (b+y[t)) +x'[t] However, if we use a pure function to implement the substitution, we obtain the correct form. In[97]:= eql/.{x-+ (y[#] +b&:)} Out[97]= a (b+y[t)) +y'[t] We will return to this point in the following section on differential equations. We can also use pure functions with the Select function to pick out terms that satisfy a specific criteria. This is often useful when performing separation of variables in the case of differential equations. Consider the following expression: In[98]:= terml= (1+x)2 (1+y)2//Expand Ou t [ 9 8 ] = 1 + 2 x + x 2 + 2 y + 4 x y + 2 x 2 y + y2 + 2 x y2 + x 2 y2 We use Select to exttact all terms that do not contain x. In[99]:= Select [terml, FreeQ[#,x]&:] Out[99]= 1+2y+y2 The expression FreeQ [# ,x] &: represents a pure function; this will return True if the subexpression is free of x, and False otherwise. With the help of the logical NOT function ( ! ) we can also exttact all terms that do contain x. In[lOO]:= Select[terml,IFreeQ[#,x]&:] Out [100] = 2 x + x 2 + 4 x y + 2 x 2 y + 2 x y2 + x 2 y2 1.3.4 . Assigning Rules and Restrictions to Functions We can use the command syntax f: /lhs = rhs to associate the assignment lhs rhs specifically to the object f. For example, let us assign properties to i to make it behave like a complex number p. Mathematica already has this symbol defined by I, but this will give us some practice with function definitions. For i to be a complex symbol, it must have the properties i 2 = -1, ;3 = -i, and i 4 = + 1. Consider the following assignments to i: 
1.3 Functions and Procedures 19 In[lOl]:= i/:i-2=-1; i/ : i -3 = -i; i/: i-oil = 1; Note that the syntax": /" is necessary; otherwise Mathematica would attempt to asso- ciate the rule with the system-defined Power function, which is protected. (Try evaluating i2=-1 .) This basic pattern for complex multiplication can be extended to higher orders of mul- tiplications by using Mod. The command Mod [m, n] gives the remainder on division of m by n. We define the final condition with In[102]:= i/ : i -n_J:nteger : = i Mod[n, 4] /; n < 0 114 <n; The notation n_J:nteger restricts n to be an integer. The syntax patt /; test allows us to test whether n is less than zero or greater than 4 before we evaluate this assignment. To show that our home-made i has the correct properties, we create a table of tests: In[103]:= Table[i -n == J:n, n, -8, 8] / .i- > J: Out[103]= {True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True} This verifies that our definition matches the built-in Mathematica definition. Let us define the unit step function with the help of the syntax patt /; test. A possible definition is: In[104]:= Clear[step1,step2] In[105]:= step1[x.] = 0/; x <= 0; step1 [x.] = 1/; 0 < x; The restrictions on stepl have been placed on the right-hand side of the equation using patt /; test. An alternate definition where the restriction is placed on the left-hand side is: In[106]:= step2 [x_ /; x <= 0] = 0; step2 [x. /; 0 < x] = 1; With the format in step2, the right-hand side of these expressions is only evaluated in the case where the argument satisfies the condition imposed on the left-hand side. We can observe this with the Trace command. The Trace command generates a list of all ex- pressions used in the evaluation of the argument, so we can see exactly what Mathematica is doing. In[107]:= step1[-0.1] //Trace Out[107]= {stepl[-O.l],O/;-O.l,;O} 
20 Chapter 1 Getting Started In[10BJ : = step2 [-0.1] / /Trace Out[10BJ= {step2[-0.1], {-O.l,;O,True},O} A third form of the unit step function can be created with the Which command. In[109J:= step3[x...] :=Which[x<=O,O,x>O,1] In [11 OJ: = step3 [-0.1] / /Trace Out[l1OJ= {step3[-0.1],Which[-0.1,; 0, 0, -0.1 >0, 1], { - 0 . 1 ,; 0, True}, O} Note that If command would also work for this simple example, but the Which com- mand can work in more general situations. Let's use Timing to see how the speed of the functions compare. In [lllJ : = {Table [ step1 [x], {x, -10000, 10000, 1}] / /'l'iming / /First, Table [ step2 [x], {x, -10000, 10000, 1}] / /'l'iming / /First, Table [ step3 [x], {x, -10000, 10000, 1}] / /Timing / /First} Out [lllJ= {3. 76667 Second, 4.56667 Second, 4.18333 Second} In this case, stepl is the fastest; in general, the speed will depend on the complexity of your expressions and your tests. However, with these commands, you can easily evaluate the most efficient means appropriate for your problem. 1.3.5 . Module Procedures that involve several steps can be conveniently combined using the command Module. Effectively, you can think of this as a subroutine. Consider a procedure to input a list of numbers, increment the numbers by a fixed constant, determine the maximum of the list, and output the new list. In[112J:= shift[list_] := Module [{newList, a = 1, max}, newList = list + a; max = Max [newList] ; Print [nThe max of the new list is: n, max] ; Return [newList] In[l13J:= shift [{1,2, 3}] The max of the new list is: 4 Out[113J= {2,3,4} The first item to note in the definition of Module is the list of variables {newList, a=l, max}; these are local variables defined only within the scope of the module 
1.3 Functions and Procedures 21 shift. This important feature allows you to write a subroutine Module without the danger of conflicting variables. We can verify that these are local to shift by evaluating the following: In[114] : = {newList, a, max} Out[114]= {newList,a,max} Clearly, these variables are unknown to the outside world. Coming back to the shift module, in the second line the variable newList is the old list plus a constant a. Note how the constant a is initialized to 1. In the third line, max is the Max of newLi st. Next, we print out the statement of the max. Finally, our Module returns the value ofnewList as the output. An alternate definition of this function is: In[115]:= shift2 [list_, a. :1] := Module[{newList,max}, newList = list + a; max = Max [newList] ; Print [nThe max of the new list is: n, max] ; Return [newList] In[116]:= shift2 [{1, 2, 3}, 2] The max of the new list is: 5 Out[116]= {3, 4, 5} This function is similar to shift, but we now pass the value of a as a second argument. We also provide a default value, so if we call shift2 with a single argument, a takes on the default value of 1. In[117]:= shift2 [{1, 2, 3}] The max of the new list is: 4 Out[117]= {2, 3, 4} 1.3.6 . rootPlot Consider an example of a procedure that solves an equation numerically and plots the roots in the complex plane. Before we create a module to perform these functions, let's go through the steps individually. For the equation eql, we use NSol ve to find the numerical roots. In[118]:= eq1 = 0 == 1 + x + 2XA2 + 3x A 3 + 4x A 4 + 5x A 5; NSolve[eq1, x] 
22 Chapter 1 Getting Started Out[118J= {{x-7-0.789728}, {X-7 -0.326925 - 0.674868 i}, {X-7 -0.326925 + 0.674868 i}, {x -7 0.321789 - 0.588911 i} , {x -70.321789 + 0.588911 i}} Recall that while it is not possible in general to solve a fifth-order polynomial equation in closed form, Mathematica has no difficulty obtaining the numerical solution. Next, we can place the real and imaginary parts of these roots into a list suitable for input for the ListPlot command. In[119J:= {list = {Re[x], Im[x]} /. NSolve[eql, x]) / / TraditionalForm -0.789728 -0.326925 Out[119J= -0.326925 0.321789 0.321789 o -0.674868 0.674868 -0.588911 0.588911 In[120J:= ListPlot [list, PlotStyle -+ PointSize [0 .03]]; . 0.6 . 0.4 0.2 .0.8 -0.6 -0.4 -0.2 0.2 .0.2 .0.4 -0.6 . . Now that we have stepped through the solution, we can combine these operations into a single module. In[121J:= rootPlot [equation_, variable. :x, opts__.] : = Module [{nSol, list}, nSol = NSolve [equation, variable]; list = {Re[x], Im[x]} /.nSol; Return[ListPlot[list, PlotStyle -+ PointSize [0 .03], opts] ] ; We include the argument opts___ (with 3 underscores) so that we can pass plot options to ListPlot. The 3 underscores allow opts to match any sequence of zero or more Mathematica expressions. We leave it as an exercise to the reader to verify that the root Plot [eql] command generates the same output as above. Instead, we apply this procedure to the example x l5 - 1 == O. The plot of the roots is: 
1.4 Packages 23 In [122J : = rootPlot [X 15 - 1 == 0, x, AspectRatio -+ 1] ; .1 . . . . 0.5 . . -1 -0.5 0.5 . . -0.5 . . . .1 . By setting the aspect ratio of the plot to unity, we can see that these roots lie uniformly on the unit circle in the complex plane. 1.4 . PACKAGES 1.4.1 . Loading Packages We make frequent use of the standard Mathematica packages. A complete list of Standard Packages can be found in the Help Browser listed under Add-oDs. The commands defined in these packages must be loaded manually before you have access to them. Loading a package can be done in several ways. Let us use the Graphics' Graphics' package as an example. First, we check to see if the package has already been loaded. In[123J:= $Packages Out[123J= {Utilities'Notation',Global',System'} Then we load the package using the command Needs: In[124J:= Needs[nGraphics'Graphics,n] Let's verify that it now appears in the list of the contexts corresponding to all packages that have been loaded in the current Mathematica session. In[125J:= $packages Out[125J= {Utilities 'FilterOptions ' , Graphics'Common'GraphicsCommon', Graphics'Graphics', Utilities'Notation',Global',System'} 
24 Chapter 1 Getting Started Often, however, you will want to read in a particular package only if it is needed. The command Needs tells Mathematica to read in a package if the context associated with that package is not already in the list $Packages. Some packages are not designed to be loaded twice, and large packages may take a while to load. You should use Needs if you are unsure whether you have loaded a particular package in your current session. Some packages are set up so that when they are loaded, other related packages are automatically loaded at the same time. Packages may have been loaded that you haven't explicitly read in, so it is best to let Mathematica decide which packages need loading. To see what functions are defined in Graphics' Graphics', we execute: In[126J:= ?Graphics'Graphics'* Out[126J= BarChart BarEdges BarEdgeStyle BarGroupSpacing BarLabels BarOrientation BarSpacing BarStyle BarValues DisplayTogether DisplayTogetherArray ErrorListPlot General i zedBarChart Histogram LabeledListPlot LinearLogListPlot LinearLogPlot LinearScale ListAndCurvePlot LogGridMajor LogGridMinor LogLinearListPlot LogLinearPlot LogListPlot LogLogListPlot LogLogPlot LogPlot LogScale PercentileBarChart pieChart PieExploded PieLabels PieLineStyle PieStyle PiScale PolarListPlot PolarPlot ScaledListPlot ScaledPlot SkewGraphics StackedBarChart TextListPlot TransformGraphics unitScale We see that PolarListPlot is defined by this package. To obtain more information about this command, we use: In[127J:= ?PolarListPlot PolarListPlot[{rl, r2, ...}] generates a polar plot, assuming that the ri are equally spaced in angle. More... Should you want to see the entire package enter ! ! Graphics' Graphics' . As a second example, consider the package Calculus 'VectorAnalysis' and use these commands to create a rule that will relate Cartesian coordinates to spherical coordinates. First, load the package using Needs In[128J:= Needs["Calculus'VectorAnalysis'"] The command CoordinatesToCartesian [pt, coordsys] gives the Cartesian coordinates of the point given in the coordinate system coordsys. The spherical coordi- nates for {x, y, z} are 
1 .4 Packages 25 In[129]:= CoordinatesTocartesian[{r,8,},herical] Out[129]= {r Cos[<t>] Sin[e], r Sin[e] Sin[<t>], r Cos[e]} A rule for converting from Cartesian to spherical coordinates can be consttucted using Thread: In[130]:= x2rRule = Thread [ {x, y, z} - > CoordinatesToCartesian [ {r, 8, } , herical] ] Out[130]= {x-7rCos[<t>] Sin[e], Y-7rSin[e] Sin[<t>],z-7rCos[eJ} Thread threads the rule -> over the components of the lists. For example, In[131]:= x-2 +y-2 + z-2/.x2rRule//Simplify Out[131]= r 2 which is what you would expect. 1.4.2 . Contexts We give only a very brief inttoduction to the command Contexts. We can see the list of all Contexts known to Mathematica: In[132]:= contexts[] Out[132]= {Algebra'Algebraics ' Private' , BoxForm' , BrowserCategoryLoad', Calculus'VectorAnalysis' , Calculus 'VectorAnalysis ' Private' , Chase' , Compile' , Conversion' , Debug' , Developer' , DSolve' , EllipFunctionsDump', We've suppressed some of the output to save space. You can also ask for the Context (singular) of the command polarListPlot using In[133]:= context[PolarListPlot] Out[133]= Graphics'Graphics' Because PolarListplot was defined by Graphics 'Graphics', its context is Graphics 'Graphics'. For a new variable, such as dummy, the context is 
26 Chapter 1 Getting Started In[134]:= Context[d] Out[134]= Global' Essentially all variables that the user creates will be in the Global' context. We can use this information to our advantage in the following manner. Suppose you want to start a new problem, but do not want any definitions created in the previous problem to con- flict with the new problem. The task is to clear all user-defined symbols. This is done by executing the command In[135]:= Clear["Global' *"] Clear :: wrsym : Symbol SuperStar is Protected. This has the advantage of clearing all variables defined by the user in the Global ' context, while not removing any commands defined by our packages because they are in separate contexts such as Graphics' Graphics'. Should you want also to remove all the definitions created by the package Graphics' Graphics' , you can do this with the command In[136]:= Clear ["Graphics' Graphics , *"] The Clear ["Global' *"] command works nicely for cleaning our slate. However, you may not want to erase all the user-defined commands. You can solve this problem using Protect to keep these functions from being erased. For example, we define the function dwnmy and Protect it In[1371:= d[x..] = x; Protect [dWIIIIIY] ; Now we can clear all Global variables: In[138]:= Clear["Global' *"] Clear .. wrsym Symbol dummy is Protected. Clear .. wrsym Symbol SuperStar is Protected. without erasing our definition for dummy, In[139]:= ?dWIIIIIY System'Convert'TeXDump'ConvertMessageText [Global 'dummy] Attributes [dummy] = {Protected} dummy [x.] = x 1.4.3 . Shadowing A common problem is the shadowing of a Mathematica command. For example, let us execute the command EasterSunday before it is properly defined. In[140]:= EasterSunday[2002] Out[140]= EasterSunday[2002] 
1.5 Calculus 27 Now, when we load the package Miscellaneous' Calendar', we obtain a shad- owing warning message. In[141]:= Needs[nMiscellaneous'Calendar,n] EasterSunday :: shdw : Symbol EasterSunday appears in multiple contexts {Miscellaneous'Calendar', ... }; definitions in context Miscellaneous- 'Calendar' may shadow or be shadowed by other definitions. When we tty and use the EasterSunday command, we do not obtain what we want. In[142]:= EasterSunday[2002] Out[142]= EasterSunday[2002] The problem is that there are two EasterSunday commands; one in the Global' context, and one in the Miscellaneous' Calendar' context. In[143]:= Context [EasterSunday] Out[143]= Global' If we Remove the EasterSunday command in the Global' context, In[144]:= Remove[EasterSunday] we are left with the EasterSunday command in the Miscellaneous' Calendar' context: In[145]:= Context [EasterSunday] Out[145]= Miscellaneous'Calendar' Now this works as expected. In[146]:= EasterSunday[2002] Out[146]= {2002, 3, 3l} 1.5 . CALCULUS 1.5.1 . Derivatives and Integrals We will now examine some common techniques using derivatives and integrals. The gen- eral command for differentiation is D [f, {x, n}] . Here are a variety of ways to compute the first derivative of the function f [x] =xAn; they are all equivalent. In[147]:= f[x.] =xAn; {D[xAn, {x,l}],D[xAn,x],D[f[x],x], f' [x] } Out [147] = {nx. 1 + n , n x- 1 + n , nx. 1 + n , n x- 1 + n } 
28 Chapter 1 Getting Started The second derivative of xAn can also be written in a variety of ways. In[148J : = {D[xAn, {x, 2}], D [f' [x], x], f" [x]} Out[148J= {(-1 +n) nx. 2 + n , (-1 +n) nx- 2m , (-1 +n) nx.2+n} Mixed derivatives are computed using the form: D [f , {x, n} , {y, m} ] . In[149J:= term1 = x A 3 y A 4 + yxAS + x/y A 3; D [term1, {x, 2}, y] Out[149J= 20x 3 + 24xy 3 Its mixed derivative is of order two in x and order one in y. The syntax of the integration command for a definite integral is Integrate[f[x], {x,xO,xl}], and Integrate[f[x],x] for an indefinite integral. For example: In [150J : = eq1 = Integrate [x", {x, 0, 1}, GenerateConditions -+ True] 1 1 1 Out[150J= If [ Re[a] >-1, -, xadlx ] 1 + a 0 Note that Mathematica realizes the generic form of the answer is only ttue for particular conditions. In particular, when a=-l, the integral is a logarithmic function. In [151 J : = eq2 = Integrate [X-I , x] Out[151J= Log[x] If you want only the generic form of the integral, you can tell Mathematica not to generate conditions. In [152J := eq1 = Integrate [x", {x, 0, 1}, GenerateConditions -+ False] 1 Out[152J= l+a You can also explicitly tell Mathematica that Re [a] > -1: In[153J:= Integrate [x", {x, 0, 1}, Assumptions -+ {Re [a] > -1}] 1 Out[153J= 1 + a The command :Integrate will also perform multiple dimensional integrals. Consider the following example. In[154J:= Integrate [1, {x, 0, 1}, {y, 0, -../1 -x'l }] J[ Out[154J= 4 
1.5 Calculus 29 The outer variable y is integrated first, followed by the integration over x. If an analytic solution is not found and you know the values of all the parameters, then you can numerically integrate the function using NJ:ntegrate. Consider the example: In [1551 := N:Integrate[Sin[z Sin[xy]], {x, O,l}, {y, 0, x}, {z, 0, x y}] Out[1551= 0.0142666 1.5.2 . Differential Equations Mathematica can numerically and (in some cases) analytically solve differential equations. Consider the harmonic oscillator equation, In[1561:= eql = y" [t] + (,)2 y[t] == 0; (Note, we indicate the second derivative using two single quote marks, y' , [t], not a double quote mark, yn [t]) with the initial conditions In [1571 := initial = {y[O] == yO,y'[O] == vO}; Appending the oscillator equation to the initial conditions, you get the list In[1581:= eq2 = Append [initial, eql] Out[1581= {y[o] ==yO,y'[O] ==vO,w 2 y[t] +y"[t] ==O} The analytic solution of eq2 follows from applying DSol ve to the list: In [1591: = eq3 = DSolve [eq2, {y [t]}, t] / /I!'latten { yOw Cos[tw] +vO S in[tW] } Out[1591= y[t]-> w The command Flatten removed one set of {} brackets in the result of DSolve. 1.5.3 . Changing Variables and Pure Functions It is often useful to express functions in a pure form when changing variables in a differ- ential equation. For example, consider the differential equation In [1601:= eql = ax" [t] + bx' [t] + c x[t] == 0; Express this equation in terms of a new function y[t] defined by x[t]=y[t]+2. The sttaightforward substitution x[t]->y[t]+2 does not generate what you want as it does not ttansform the derivatives of x. In[1611:= eql/.{x[t] -+y[t] +2} Out[1611= c (2+y[t]) +bx'[t] +ax"[t] ==0 The substitution works if you express the change in its pure form: In[1621:= eql/.{x-+ (y[#] +2&:)} 
30 Chapter 1 Getting Started Out[162J= c (2 +y[t]) + by' [t] + ay" [t] == D Note the parenthesis outside the symbol &:, which delimits the Function. An alternate form that produces equivalent results is: In[163J : = eq1/. {x -+ Function [{t}, y[t] + 2] } Out[163J= c (2+y[t]) +by'[t] +ay"[t] ==D You can use DSol ve to easily get the correct form of a pure function. In[164J:= DSolve[{x[t] ==y[t] +2},x,t] //Flatten Out [164J = {x.... Function [ {tL 2 + y [t] ] } 1.5.4 . Numerical Solutions of Differential Equations If a numerical solution is required, then NDSol ve can be used. Consider the coupled differential equations, In[165J:= eq1 = {x"[t] == -x[t] -x[t] y[t]-2, y" [t] == -y[t] - x[t] y[t] -2}; along with the initial conditions, In[166J:= initial = {x[O] == 2, x' [0] == 0, y[O] == 1, y'[O]==O}; The numerical solution of eql for t=O to 20 is given by: In [1671 := ndsol = NDSolve[Join[eq1,initial], {x,y}, {t, 0, 20}][ [1]] Out [167J = {x.... InterpolatingFunction [ {{D., 2D.}L <>J,y.... InterpolatingFunction[{{D.,2D.}}, <>]} The numerical data are expressed by an :InterpolatingFunction, whose values are found by interpolation. The graphs for x [t] and y [t] are: In[168J:= Needs[nGraphics'Legend,n] In[169J : = plot [{x [t], y[t]} / .OOsol / /Evaluate, {t, 0, 20}, PlotStyle -+ {{}, {Dashing[{0.02}], Thickness[0.008]}}, plotLegend -+ {nx[t] n, ny[t] n}, LegendPosition -+ {1, O} 
1.5 Calculus 31   \ 20 , , . , , '': -Graphics- Here we have loaded the package Graphics'Legend' to make a legend for this plot. The solid curve is the x[t] coordinate and the dashed curve is the y[t] coordinate. We modified the line style of the graph with the PlotStyle command; this is a list contain- ing the empty list, {}, which generates the solid curve, and {Dashing[{O.02}], Thick- ness[O.008]}, which generates the thick dashed curve. The command Evaluate is required to force the substitution of the ndsol rule. You can also plot the solution in the {x, y} plane using parametricPlot: In[170]:= ParametricPlot[ {x[t], y[t]}/ .ndsol / /Evaluate, {t,0,20}]; We ended the plotting command with a semicolon; this prevents "-Graphics-" from being displayed below the figure. Compare with the previous figure without the semicolon. One interesting feature of an :InterpolatingFunction is that you can tteat it just as any other analytic function; in particular, you can differentiate it. Below, we plot the first derivatives of x [t] and y [t] : In[l71] : = Plot [{x' [t], y' [t]}/ .ndsol / /Evaluate, {t, 0, 20}, PlotStyle -+ {{}, {Dashing[{0.02}], Thickness[0.008]}}]; 
32 Chapter 1 Getting Started 2 1 , , .1 ' ,,,' .2 1.6 . GRAPHICS 1.6.1 . Using the Plot Command We have already used the graphic commands Plot and ListPlot in the previous exam- ples. Let us return to Plot to learn more details about the command. The command works for singular, discontinuous, interpolating, conditional, and interpolating functions, and can be embellished with various options. To view the options for Plot enter: In[172]:= Options[Plot] Out[172]= { . 1 AspectRato -> . , GoldenRato Axes -> Automatic, AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> Automatic, Background -> Automatic, ColorOutput -> Automatic, Compiled -> True, Defaul tColor -> Automatic, Epilog -> {}, Frarne -> False, FrarneLabel -> None, FrarneStyle -> Automatic, FrarneTicks -> Automatic, GridLines -> None, ImageSize -> Automatic, MaxBend -> 10. , PlotDivision -> 30., PlotLabel -> None, PlotPoints -> 25, PlotRange -> Automatic, PlotRegion -> Automatic, PlotStyle -> Automatic, Prolog -> {}, RotateLabel -> True, Ticks -> Automatic, Defaul tFont :-7 $Defaul tFont, DisplayFunction :-> $DisplayFunction, ForrnatType:-7 $FormatType, TextStyle:-> $TextStyle} Numerous rules can be used to control the output. In this example, we use the option Plot Style to change the thickness and color. 
1.6 Graphics 33 In[173]:= ptl= Plot[1/(1-x-2), {x, -10, 10}, PlotStyle- > {Hue [0.8], Thickness [0.008] }]; 6 4 5 .5 5 7.5 10 2 4 6 Note that although this function is infinite at x={ +1, -1}, Mathematica has no diffi- culty drawing it. While you cannot see the color of the line in this black and white book, it is still useful to know how to deal with colors. In our own notebooks, we often find it useful to define the following commands: In[174]:= colors = {red, green, blue, cyan, magenta, yellow} = {RGBColor[l, 0, 0], RGBCOlor[O,l, 0], RGBColor [0, 0, 1], CMYKColor [1, 0, 0, 0], CMYKcolor[O,l, 0, 0], CMYKColor[O, 0,1, O]}; A quick way to see these different colors is with the command: In[175]:= Plot [Table[i x, {i, 6)] //Evaluate, {x, 0, 1}, PlotStyle -+ colors] ; 6 5 4 3 0.2 0.4 0.6 0.8 1 2 1 (You will have to execute this on a color monitor to see what these lines really look like.) For a wider range of colors, you can use the function Hue [h] where the parameter h ranges between 0 and 1. Hue provides a simple way to generate an arbittary number of 
34 Chapter 1 Getting Started different colors. The following example will generate n colors, where n can be as large as you like. In[176]:= n = 13; hues = Table [Hue [i/n] , {i, n}]; Plot[Table[i x, {i,n}] //Evaluate, {x, 0, I}, Plot Style- > hues] ; 1.6.2 . Animated Plots A very powerful feature of Mathematica is the ability to animate plots. The basic idea is that you first generate an array of graphics, and then Mathematica will display them sequentially to simulate motion. The package Graphics' Animation' has some useful commands that help display animations. We load this with the Needs command. In[177]:= Needs[DGraphiCS'Animation'D] This package contains the command Animate, which we can use to animate a traveling wave. Here, we generate a number of plots that can then be animated. We set frames=l here simply to save space; the command will work for arbittary frames. In[178]:= frames = 1; Animate [Plot [Cos [27T(X - t)], {x, -2, 2}, PlotRange- > {-I, I}, Axes- > False] , {t, l/frames, 1, l/frames}] 
1.6 Graphics 35 A more interesting example is demonsttating how a standing wave is composed of two individual plane waves moving to the left and the right. This package contains the command Animate, which we can use to animate a ttav- eling wave. Here, we generate a number of plots that can then be animated. We set frames=l.l here simply to save space; the command will work for arbittary frames. In[179J:= frames=l.l; Animate [ Plot [{Cos [27T(X - t)], Cos [27T(X + t)], COS[27T(X- t)] + Cos[27T(X+ t)]}, {x, -2, 2}, PlotRange.... {-2, 2}, PlotStyle .... {blue, green, {red, Thickness [0.008] }}, Axes.... False], {t, l/frames,l, l/frames}] In \his figure, the green and blue curves represent ttaveling waves moving to the left and right. The red curve is the sum of the blue and green, and represents a standing wave. 1.6.3 . Vector Field Plots A useful two-dimensional plot for physics applications is PlotVectorField. We define a two-dimensional vector field as follows: In[180J:= vector = {l/x,l/y); We then load the package Graphics' PlotField ' . In[181J:= Needs[RGraphics'plotField'R]; The package Graphics' PlotField' contains the command PlotVectorField. For example, we have: In[182J:= plotVectorField[vector, {x,-5,5,2}, {y,-5,5,2), ScaleI'uDction.... (1&:), Plotpoints .... 20] ; 
36 Chapter 1 Getting Started , '." " , '-..---.-- '\ "<, "'\ '" ' '"'' --- ----- " " '\ " "'-,' .. .........,----- \ \ , , "" ','--- '\ \ \ "", "'.--- \ \ \ "",'-......-. . \ \ \ , , '" '..- \\\.\\" \\\\\.\\,: t \ \ \ \ \ \ \ \,', ! ! , i I i 11/ i Iii i 1/ / I i Iii/I / /-- I I 1 1 I I / / ----- 11/1////--' //1/ / /;"'--_. 11/ / /",,,,-'-'-- / / / / '" _..-.---"-- / / / / ;"' .. --- .---...- / / / / -- ---_.._- ---------/..... ----" / / /' / / ___-..-.---""" /..... >" /" /' /JI' /' / ----- ------"/ '" /' , / /' ______/....... ./" /" /JI' /' / .I l ___----""'"/...../' /" / / ;' II .____-' / / /f / l / .I __..../ -" I I / ! I I ,,;lll..I. ./ " '. I j I j j j /{ j j i ; j j I : j /' "I I I I I ... \ \ \ \ \ \ --,\\,\\,\\ '......." ... \ \ \ , , , "'- '" ... ... \ \ , \ , ---...-......'"  '" ", \ \. \ " -----"'....', \, '" ',- \. \ '\ -"--'-... ",', '" ", , \ ---------...."'...  " ", \,-, " ",- -----....----..... ",- ", '", '" ", "- -------- -- -'.............. '",,- x""" '" , The option ScaleFunct ion is a function used to determine the length of the vectors. Here we have set this function equal to a constant (one) so that all the vectors are the same length; this is sometimes useful when the function has singular values such as we encounter in the case of a point charge. (As an exercise, re-generate this plot without the ScaleFunction option.) You can also plot a three-dimensional vector field with the package: Graphics- 'PlotField3D' . In[183]:= Needs[nGraphics'plotField3D,n]; In[184]:= plotGradientField3D[ l/Sqrt [x A 2 + yA2 + zA2], {x, -5, 5, 2}, {y, -5, 5, 2}, {z, -5, 5, 2}, ScaleFunction.... (1&), VectorH_ds .... True] ; 
1.6 Graphics 37 Because this function is singular at the origin, it is particularly useful to set Scale- Function to a constant. (Again, re-generate this plot without the ScaleFunction option.) 1.6.4 . Three-Dimensional Graphics Using Plot3D and ParametricPlot3D To illusttate the use of three-dimensional graphics, we plot the imaginary part of the Sqrt function. In [185J : = Plot3D [Sqrt [x + J: y] / /'I:JD., {x, -1, I}, {y,-l,l}, Plotpoints .... 25, AspectRatio .... 1, AxesLabel.... {RRe D , R'I:JD.D, R R}] ; This clearly illusttates the branch cut running along the negative real axis. A better way to illusttate this is with the CylindricalPlot3D command defined in the Graph- ics' parametricPlot3D' package. In[186J:= Needs[RGraphics'parametricPlot3D'R] In [1871 : = Cylindricalplot3D [Sqrt [r Exp [J: e] ] / /:rm, {r, 0, 10}, {e, -7r, 7r}, Plotpoints .... 25, AspectRatio .... 1] ; 
38 Chapter 1 Getting Started 10 Another useful plotting command from the Graphics' parametricPlot3D' package is the SphericalPlot3D command. We will use this to view the Spheri- calHarmonicY functions. In[188]:= SphericalPlot3D[ SphericalHarmonicY [2, 0, e, t/J] II Abs II Evaluate, {e, 0, 7I"}, {t/J, 0, 271"}, PlotPoints.... 50, Boxed.... False, Axes.... False]; We used several options to enhance the plot. The last example that we give is a parametric curve in space. In[189]:= ParametricPlot3D[ {Cos [2t + 71"/4] + t/lOO, 2Cos [2t] + t/200, Cos [3t]}, {t, 0, 100}, Plotpoints- > 3000]; 
1 .7 Exercises 39 0.5 2 1.7 . EXERCISES The solutions to many of these exercises can be found at our web site. 1.1 Real Expressions (a) Reduce the following expression and show it is a real number: 1/( {3 + i)6. (b) Find the roots for the cubic equation, and show they are real: 22-lOx-20r + lli3 == O. 1.2 Series (a) Find the first ten nonzero terms of the Taylor series expansion of Cos [x] and Sin [x] . (b) Detennine the general expression for the nth term, and reconstruct the series by summing this infinite series. 1.3 Integration Integrate the function eX (1 - t)-I-a+c (-I+a over the variable t for {t, O,l} with the assump- tions: {Re[a]>O && Re[-a+c]>O && Re[x] <O}. 1.4 Superposition of Waves Consider two oscillations of slightly different frequencies described by: Cos[(w+8w)t] + Cos[w t]. Plot the superposition of these two functions along with the enveloping curve for your choice of parameters. 1.5 Tables of Zeros for Several Functions Consider the functions HermiteH [n,x], BesselJ[n,x] , LegendreP [n,x], and LaguerreL [n, x] . (a) Plot these functions for the first four integer values of n. 
40 Chapter 1 Getting Started (b) Use FindRoot to find the first zeros for each of these functions for the first four integer values of n. Assume x is positive. Make a table of the zeros. (c) Confirm the results in part b by using NSol ve to find all the zeros. 1.6 Plot of Roots Consider the equations In[190]:= eq1 = x A 7 + x A 3 + x A 2 + 1 == 0; Plot the roots in the complex plane using x for the real axis and y for the complex axis. 1.7 Coupled Equations Consider a unit circle (xl + I' = 1) and a parabola (x = 41' - 1). Find the intersection of these two curves with the help of the package Graphics'ImplicitPlot'. Graph the solution. 1.8 Statistical Data Consider a list of 1000 integers that have values between 1 and 20. In[191]:= r = Tab1e[RaDdom[J:nteger, 1,20],1000]; Find the mean value of the list. Use the command Frequencies found in the Statis- tics' DataManipulation' package to get a list of the distinct e]ements in the list. Also find the frequencies with which they occur. Make a BarChart (found in Graph- ics' Graphics' ) of the frequencies. 1.9 Differential Equations Consider the differential equationm z' I [t] ==-m g-b z' [t]. Find the so]ution and p]ot z [t] and z I [t] using suitab]e numerical values for {m, g I b}. 1.10 Coupled Differential Equations Consider the two coup]ed differential equations x" [t] ==-a x[t] +b y' [t] and y' I [t] ==-a y[t] -b x' [t]. Form one complex equation using the variable u=x+J: y and solve. 1.11 Trajectories and Vector Field Plots for Coupled Differential Equations Consider the coupled equations y'[t] = y[t] - x[t] and x'[t] = 5y[t] - 3x[t]. Solve the equations with arbitrary initial conditions. Plot the trajectories {x, y} for several different starting points. Compare the trajectories with a vector field plot of {y - x, 5y - 3x}. 1.12 Heat Equation Consider the heat equation u, - c u xx = 0 in the region 0 < x < 1 and for t > O. Here, the subscript notation on u represents a derivative with respect to either time (t) or space (x). Assume the boundary conditions, u(x, 0) = a Sin(21T x), u(O, t) = u(l, t) = O. (a) Solve the equation using Laplace transforms. (b) Numerically solve the equation for a=l and c=l. (c) Compare and comment on the solutions to parts a and b. 1.13 Wave Equation Consider the wave equation utI -2u xx = 0 in the region 0 < x < 1 for t > O. Here, the subscript notation on u represents a derivative with respect to either time (t) or space (x). Assume the boundary conditions u(x, 0) = a sin(21T x), u,(x, 0) = 0, u(O, t) = u(l, t) = 0 and (a) Solve the wave equation using Laplace transforms. (b) Numerically solve the equation for a=l and c=l. (c) Compare and comment on the solutions to parts a and b. 
1.7 Exercises 41 1.14 Fit to Data Consider the data table: In[192]:= data = Table [ {x, 5 Sin[3 7T x] + Random[R_l, {-O .2,0 .2}]}1 IN I I Chop[#, 10 - 3]&:, {x, 0, 0.5, 0.05}]; (a) Fit the data to a power series in x. Plot the data points and the fitted curve to the data on the same graph. (b) Use NonlinearFit (found in the package Statistics 'NonlinearFit \) to fit the data to the function a Sin [b x]. Plot the fit and data on the same graph. 1.15 Rules Used to Solve Problems Consider a list of 13 random integers between 0 and 100: In[193]:= list = Random [Integer , {O, 100}]&:/@. Range [13] ; Find a rule that returns the four numbers in the sequence that sum to 100, or determine no such solution exists. 1.16 Procedures to Select Numbers Consider a list of 30 random numbers in the range from 0 to 20. In[194]:= list = Table [Random [R_l, {O, 20}], {i, 30}]; Write a procedure that retains only those elements in the list that have values between 6 and 15, and rank these elements from largest to smallest. (Hint: use Select and Sort.) 1.17 Procedure to Select Certain Pairs of Points Consider 1000 random pairs of real numbers in the range 0 to 1. In[195]:= pairs = Table [Random[] ,1000,2]; Select from the a list of pairs {x, y} those that satisfy the condition y > x. (a) Plot the points above the line with one color, and those below with another. (b) Use Module to make a user-defined function to select those points above the line. Com- pute the percentage of pairs above the line, and compare with your theoretical expectation. 1.18 Change Make a procedure to count change. Initially, you may use U.S. currency, where a quarter is 25 cents, a dime is 10 cents, a nickel is 5 cents, and a penny is 1 cent. Given any amount of money, determine how many quarters, dimes, nickels, and pennies are required for the change. Apply it to several examples. Generalize this problem so that a quarter, dime, nickel, and penny have a value equal to an arbitrary number of cents, and solve (e.g., quarter = 37 cents, dime = 13 cents, nickel = 8 cents, penny = 1 cent). For simplicity, assume quarter > dime > nickel > penny = 1 cent. 1.19 Toss of a Die The random roll of a die can be simulated by Random [ Integer, { 1, 6} ] . 
42 Chapter 1 Getting Started (a) Compute the average value of the throws of a die as a function of the number of throws, and plot the result. Compare this with the theoretical expectation of the average of 3.5. (b) Generate 25 sets each of 10 throws, 100 throws, 1000 throws, and 10000 throws. For each set of 25 throws, display a bar chart displaying the frequency of each number thrown {I, 6}. (c) For each set of 25 throws, compute the standard deviation of the average value of the sets. How does this standard deviation compare to.yn, where n is the number of throws? 1.20 Three Dice (a) Find the probability that when three dice are tossed, the sum of the numbers is 14. (b) Generalize the above to the case where the sum of the numbers is n. (c) Find the probability that in throwing a die three times in a row, you get a sequence of ascending numbers, e.g., {2, 3, 5}. 1.21 Playing Darts and the Calculation of 1£ We can compute 1£ using a Monte Carlo technique by throwing a dart at a square dart board, and counting the number of times the dart lands within an inscribed circle. The ratio of these areas is 1£/4. (a) Generate 10,000 pairs of {x, y} points within a square centered at the origin with length 2 for each side. In[196]:= list = Table[{Random[Real, {-I, I}] , Random[R_l, {-I, I}] }, {i, lO}]; For this list, compute the number of pairs which lie within the unit circle centered at the origin. The ratio of this number to the total number of pairs is our estimate of the ratio 1£/4. (b) Plot the {x, y} pair, and color the pairs inside the unit circle a different color than those outside the unit circle. 1.22 Dropping Needles Buffon's needle problem, first stated in 1777, involves dropping a needle on a lined sheet of paper and detennining the probability of the needle crossing one of the lines on the page. Assume the length of the needle is one unit, and the distance between the lines is also one unit. (a) How often will the needles hit the lines? (b) Graph the simulation. 1.23 Pascal's Wager If you throw a single die, the probability is 1/6 that a 1 will appear on the die. If you throw two die, the probability is (1/6)2 = 1/36 that a 1 will appear on both dice. This might lead one to believe that given 18 throws of the dice, the probability is 18/36 = 1/2 that we get a 1 to appear on both dice. This logic is flawed. (a) Generate 1000 pairs of numbers in the range 1 to 6 to represent the throws of two dice. In[1971:= pairs = Table [Random [J:nteger, {I, 6}], {lOOO}, {2}] Compute the percentage of pairs that have a 1 appear on both dice. 
1 .7 Exercises 43 (b) Solve the problem analytically, and find the number of throws necessary so that the proba- bility of obtaining pairs that have a 1 to appear on both dice is 1/2 = 50%. Compare this result with part a. 1.24 The Birthday Problem Consider a random group of n persons. What is the minimum value of n such that there is at least a 50% chance that two of the people in the group have the same birthday? (That is, the day and month of their birthdays match, not the year.) Hint: the answer is smaller than most people would guess. 
CHAPTER 2 44 General Physics 2.1 . INTRODUCTION A brief view of the Mathematica language was presented in Chapter 1. In Chapter 2, we use Mathematica to solve simple problems encountered in undergraduate physics. We choose problems from classical mechanics, electricity and magnetism, and modern physics. The simplicity of the problems allows the reader to concenttate on the Mathematica commands; the more difficult problems are inttoduced in subsequent chapters. This chapter is divided into four sections-Newtonian Mechanics in Inertial Frames, Newtonian Mechanics in Rotating Frames, Electricity and Magnetism, and Modern Physics. At the beginning of each section, a brief overview of the topic is presented. A few remarks and an outline of the solution is given after the statement of the problem. Suggested exercises are found in final section. As in the previous chapter, we start by turning off the spell checker. In[i]:= Off [General :: spelll]; Off [General: : spell]; 2.2 . NEWTONIAN MECHANICS IN INERTIAL FRAMES 2.2.1 . Overview Basic to any presentation of mechanics is Newton's Second Law, which states that an external force acting on a particle will cause the momentum of the particle to change: -'" dp F=- dt where p = m  is the momentum. In the special case of constant mass, this takes the more familiar form F = m . The force and momentum are vector quantities, and are rep- resented by lists in Mathematica. The second law represents a set of three, second-order differential equations for three-dimensional problems. As these are second-order differen- tial equations, their solution requires the initial values of the position and velocity vectors. Velocity and acceleration must always be defined relative to some frame of reference. An inertial reference frame is one in which Newton's laws hold. All frames of reference moving uniformly (no acceleration) relative to an inertial reference frame are likewise 
2.2 Newtonian Mechanics in Inertial Frames 45 inertial. There is no preferred reference frame; this principle led to Einstein's theory of relativity. One of the simpler classes of problems is the motion of particles moving in a constant gravitational field. The equations of motion for a particle moving in the {x, y} plane are x"[t] = 0 and y"[t] = -g, where y is the projectile height, and x is the horizontal distance. Once launched, objects such as baseballs, golf balls, or bullets are subject only to the downward acceleration of gravity (if air resistance is neglected). In practice, however, the air produces a resisting force. For low speeds the resisting force is proportional to the speed. In other cases it may be proportional to the square of the speed, or some other power. The equations of motion can be simplified if the force is conservative; that is, if it can -->. -->. be written as F = - VV, where V is the scalar potential. In a conservative force field the total mechanical energy is conserved. An example of a conservative force is Newtonian gravity between a particle of mass m and another of mass M separated by a distance r. The gravitational force is F = _G m ; . The total energy, kinetic energy plus potential energy, is conserved. . PROBLEM 1 Escape Velocity. Neglect air resistance and consider a particle tossed up- ward from the surface of the Earth. From the conservation of energy it follows that the sum of the kinetic and potential energies are constant. Use the conservation of energy to show that the escape speed for the particle is about 7 miles/sec, or 11 km/sec. Remarks and Outline The solution follows from applying energy conservation at the Earth's surface and at infinity. The gravitational potential energy is U = - GM . The numer- ical evaluation illusttates the use of the add-on packages Miscellaneous' physical- Constants' and Miscellaneous 'units'. Solution As explained in Chapter 1, we clear any Global' variables that may have been previ- ously defined in Mathematica. In [2] : = Clear [nGlobal' * n] ; The kinetic energy T, potential energy U, and total energy of the particle at the Earth's surface is In[3]:= T = (ll2)m v-2; t1 = -G II m/r; energy = T + t1 mv 2 GmM Out[3]= 2 -  If a particle just escapes from Earth's gravitational field, then the energy at infinity is zero. The conservation of energy gives the equation energy=O, which can be solved for the velocity v, 
46 Chapter 2 General Physics In[4]:= sol = Solve [energy == 0, v] [[2]] Out[4]= {V-7 y'2.yM } where v is the escape velocity. Note we have kept only the positive solution by selecting the second solution returned by Solve. We now use the package Miscellaneous' Physica1Constants ' In[5]:= Needs["Misce11aneous'physica1Constants,n]; to evaluate the physical constants. We can see what constants are defined in the add-on package using the command: In[6]:= ?Misce11aneous'Physica1Constants'* We've suppressed the output to save space. We define a rule values to make the substitutions of the physical constants: In [7] : = values = {G.... Gravitationa1constant, r ....l!:arthRadius, M.... l!:arthMass, Newton.... Ki10gramMeter ISecond A 2} ; Now we apply the substitutions to the result for the velocity: In[8] := vO = vi .sol/ I .va1uesl IPowerExpand 11180.7Meter Out[8]= Second We use the command PowerExpand to help cancel out the units; this command should be used with care as it can lead to incorrect expressions when it expands noninteger powers. The escape speed can be converted to different units with the command Convert found in the package Miscellaneous 'UDits'. In[9]:= Needs["Misce11aneous'Units,n]; We can find the syntax and related information for the Convert command as follows. In[lO]:= ?Convert Convert [old, new] converts old to a form involving the combination of units new. More... We now convert the escape speed to km/s In[ll]:= Convert [vO, Ki10MeterlSecond] 11. 1807KiioMeter Out[ll]= Second 
2.2 Newtonian Mechanics in Inertial Frames 47 and also to British units. In[12]:= Convert [vO, Mile/Second] 6. 94736Mile Out[12]= Second . PROBLEM 2 Projectile in a Uniform Gravitational Field. Consider a particle of mass m moving in a constant gravitational field. Assume the motion is in the {x, z} plane. The equations of motion are x"[t] = 0 and z"[t] = -g where z is the projectile height, and x is the horizontal distance. Z (Xo,Zo) x (X f ,Zf) a. Solve the equations of motion for the ttajectories that have the same initial and final position but different final times. Plot the ttajectories for several different final times. b. Solve the equations of motion for ttajectories with a given initial speed and angle. Find the position of maximum height. Plot the ttajectories for different initial angles, and find the angle e that yields the maximum height. Remarks and Outline We use DSol ve to give the analytic solution for the equations of motion. The boundary conditions (i.e., initial position and velocity) will allow us to determine the constants of integration. There are several ways to plot the results and we invite the reader to explore possibilities other than those presented here. Solution In[13]:= Clear [oGlobal ' * 0]; a. The equations of motion for a particle of mass m moving in a constant gravitational field are In[14]:= eql = {mx"[t] == O,mz"[t] == -mg}; where z is the projectile height, and x is the horizontal distance. If the position at time t= 0 is {x,z}={O,O} and the final position at time t=tl is {xl,zl} then the boundary conditions are In[15]:= initiall={x[O] ==O,x[tl] ==xl,z[O] ==O,z[tl] ==zl}; 
 48 Chapter 2 General Physics Joining eql with initiall and applying DSolve to the equations of motion, you get In [16] : = dsoll = DSolve [Join [eql, initiall], {x[t], z [t] }, t] / /Flatten [16] { txl -gtlt 2 + g t1 2 t+2Z1t } Out = x(t) -> U' z(t) -> 2tl Simplifying the results by grouping the terms in powers of time, you get In [17] : = Map [Collect [', t] &, dsoll, {2}] { txl t (gt1 2 + 2z1) _ g 2 t2 } Out[17]= x(t)->U,z(t)-> 2tl The Map function applies the Collect function to the argument (dsoll) at level {2}. This is complicated to say, but easier to understand with an example. Let's tty the same command, but replace the Collect function with a fake function "collect" (low- ercase) so we can see where Map maps this function. In[18]:= Map [collect [., t]&, dsoll, {2}] Out[18]= {collect (x(t), t) -> collect ( ttl , t), [ -gtlt2 + gt1 2 t + 2z1t J } collect (z (t) , t) -> collect 2tl ' t Plotting several curves on a single graph is a good way of observing the dependence on a specific parameter such as the final time tl. Let us plot the ttajectories for three different final times U= {5, 10, 15} seconds, and for values ofthe parameters given by: In[19]:= valuesl= {xl....300,zl....O,g....9.8}; We could just use the command Plot (enter ?Plot to see its definition), but instead we display the curves by plotting the projectiles at discrete time values; this is more work, but the separation between the plot points allows us to infer the velocity at that position. We plot the ttajectories evaluated at discrete time points using ListPlot. The coordinates as a function of t for these values become In [20]:= coord1 [t_, tL] = {x[t], z [t]}/ .dsoll/ .values1 [ ] { 300t 9. 8tt1 2 - 9. 8t 2 tl } Out 20 =' 2tl The path depends on the variable tl. We choose time values from 0 to tl in steps of 0.5 seconds, and form a table of discrete points along the ttajectories. In[21]:= points [tL] := Table [coord1 [t, t1], {t, 0, t1, 0 .S}] A graph for the discrete points follows immediately from ListPlot. 
2.2 Newtonian Mechanics in Inertial Frames 49 In [22] := plotl[tL] := ListPlot [points [tl]//Evaluate, PlotStyle.... {Rue [0.8], PointSize [0 .02] }, GridLines .... Automatic, DisplayFunction.... :Identity] The command plotl [tl] generates one plot for each value of tl. Note here that we include the option DisplayFunction  Identity to suppress the individual plot generated by plotl from appearing separately. The best way to see what this does is to execute the following command with and without this option in plotl. A list ofthree plots with times tl= 5, 10 and 15 is generated by: In[23]:= Show[{plotl[S],plotl[lO],plotl[lS]}, Epilog- > { Text ["tl = 5", coordl[S/2, 5], TextStyle.... {PontWeight .... "Bold"}], Text ["tl = 10", coordl [10/2, 10], TextStyle.... {pontWeight .... "Bold"}], Text ["tl = 15", coordl[lS/2,lS], TextStyle.... {pontWeight .... "Bold"}]}, Displayl!'unction- > $DisplayFunction, PlotRange.... All] ; 5 .1 Ii... ..' . . . . . . . . .t4. 310. . . . . . . . . . . . . . .tl 5. . . . . . . . . . 50 1 a 1 a 2 a 2 a 3 a 25 20 15 10 where the command Epilog was used to add labels to the curves. Notice we use a very pow- erful feature of Mathematica to place the text to label the curves. The coordinate of each text label is computed by Mathematica individually; this ensures that if we later change the values of specific parameters that the labels will be correctly placed in the new plot. Also note that we must include the option DisplayFunction $DisplayFunction to output the complete plot to the notebook, since we defined the plotl function with the option Di splayFunct ion  Identity. b. Let us solve the equations of motion with initial speed vO and angle e. In [24] : = initia12 = {x[O] == 0, x [0] == vOCos [9], z [0] == 0, z' [0] == vOSin[9] }; The solution of eql with these initial conditions is: 
50 Chapter 2 General Physics In[25]:= dso12 = Dsolve [Join [eql, initia12], {x, z}, t] / /Flatten Out [25] = {x -7 Function [{t}, tvO Cos (9) ] , z -7 Function [{t},  (2tvO Sin (9) - gt 2 ) ]} Notice in the above result for dso12 the solutions are returned in the form of a Func- tion; this is because we asked for solutions of {XI z} rather than {x [t] I z [t]}. (Com- pare with the previous result for dsoll.) This has the advantage that it makes substitutions easier when dealing with derivatives, as we will now demonsttate. The time it takes to reach the highest point follows from taking the time derivative of vertical coordinate z [t] and setting this to zero: In [26] := eq2 = z' [t] == O/.dso12 2 1 . Out [ 6] = "2 (2vO Sm (9) - 2gt) == 0 Note, the above substitution for z' [t] would not have worked if the solutions of {XI z} were not returned as functions. Specifically, this does not work using the dsoll solution. In[27]:= z'[t] == O/.dsoll Out[27]= z' (t) == 0 Continuing with the solution for the time it takes to reach the highest point, we solve eq2 for the time: In[28]:= tsol = Solve [eq2, t]//Flatten { vOSin(9) } Out[28]= t -7 g The position of maximum height is obtained by evaluating {XI z} at this time: In[29]:= {x[t],z[t]}/.dso12/.tsol//Simplify Out[29]= { V0 2 Cos (9) Sin(9) , v0 2 Sin 2 (9) } g 2g Let us plot three ttajectories that have e equal to {11/8, 211/8, 311/8}. The positions of the ttajectories are plotted at discrete time points. We choose the numerical parameters, In[30]:= values2 = {g- > 9 .8, vO- > lOO}; and find that the coordinates for the trajectory with angle e are In[31]:= coord2 [t_, EL] = {x[t], z [t]}/ .dso12/ .values2 Out[31]= {lOOtCOS(9), (200tSin(9) -9.St 2 )} Again we plot discrete time points along the ttajectories for times from 0 to 20 seconds in steps of 1/2 sec. We first define a function plot2 that will generate a graph for a specific value of e: 
2.2 Newtonian Mechanics in Inertial Frames 51 In[32]:= p10t2 [9_] := ListP10t[ Tah1e[coord2[t,9], {t,0,20,1/2}]//Eva1uate P10tSty1e .... {Hue [0.8] , PointSize [0.02] } , GridLines .... Automatic, Disp1ayFunction.... :Identity] The graphs for e equal to {11/8, 211/8, 311/8} are given by: In[33]:= Show[p10t2[#]&/@{/8,2/8,3/8}, Epilog- > { Text ["9 = /8", coord2 [5, /8], TextSty1e.... {FontWeight .... "Bold"}], Text ["9 = 2/8", coord2 [5, 2/8], TextSty1e.... {FontWeight .... "Bo1d D }], Text ["9 = 3/8", coord2 [5, 3/8], TextSty1e.... {FontWeight .... DBo1d D }]}, P10tRange.... HO, 1000}, {O, 500}}, Disp1ayFunction- > $Disp1ayFunction, FrameLahe1.... {DX[t]", DZ [t]"} ] ; 500 400 . . 300 200 . . . 200 400 600 800 1000 Note that e = 211/8 = 11/4 gives the largest range of these three values of e. We can prove this value of e is optimal as follows. First, we set our solution for {x, z} equal to the point of maximum horizontal distance: {xMax, O}. In [34] := eq3 = coord2 [t, 9] == {xMax, O}//Thread out [34] = {lOOt Cos (9) == xMax,  (200t Sin (9) - 9. 8t 2 ) == O} and solve for {t,xMax}: In [35] : = so13 = Solve [eq3, {t, xMax}] Out[35]= {{xMax....O.,t....O.}, {xMax.... 2040.82 Cos (9) Sin (9) , t.... 20.4082 Sin (9) }} 
52 Chapter 2 General Physics The second solution corresponds to the physical one: In[36]:= xMax=xMax/.so13//Last Out[36]= 2040.82Cos(S) SinISI We find the exttemum by finding where the derivative of xMax is zero. In [37] : =  / . Solve [D [xMax, 9] = = 0, 9] / /Rationalize 7!' Out[37]= { - %' -,, %} We find the values of (Jhr that maximize the horizontal distance are {- 3/4, -1/4, 1/4, 3/4}. For our situation, (J/1r = 1/4 represents our physical solution. . PROBLEM 3 Reflecting Trajectories. A girl stands a distance xO from a vertical wall and throws a ball. The ball leaves the girl's hand at a height yO above the ground with initial horizontal velocity vxO; assume the initial vertical velocity, vyO, is zero. When the ball hits the wall, the horizontal component of velocity is reversed and the vertical component remains unchanged. Solve for the motion. Plot the motion for several different initial velocities. (X o ' Yo) y VxO x Solution In [38] : = Clear ["Global' * "]; Let the coordinates of the particle be {x[t) ,y[t)}, where x[t) describes the hori- zontal motion and y [t) describes the vertical motion. The initial position of the particle at time t=O is {xO,yO}, and we will take the wall to be at position x=O. The general equations of motion in the {x,y} plane are given by: In[39]:= {xEq, yEq} = {X[t] == xO + vxOt + !.axt 2 , 1 2 y[t] == yO +vyOt + "2ayt2}; rules = {vyO .... 0, ax.... 0, ay.... -g}; {xEq, yEq} = {xEQ:, yEq} /. rules { gt2 } Out[39]= x(t) ==tvxO+xO,y(t) ==yO-T 
2.2 Newtonian Mechanics in Inertial Frames 53 In the above, we have made substitutions to reflect the fact that the initial vertical ve- locity is zero (vyOo), the horizontal acceleration is zero (axo), and the vertical accel- eration is due to gravity (ay -g). Since the wall does not affect the vertical motion, we can find the solution for y [t] immediately. In[401 := ySol = DSolve[yEq, y, t] / /I!'latten Out[401= {Y-> Function [{t}, yO _ g2 ]} The wall does change the sign of the velocity in the x-direction; therefore, the following equation for x only is applicable before the ball hits the wall. In[411:= xSol = DSolve[xEq:, x, t] / /I!'latten Out [411 = {x -> Function [ {t}, tvxO + xO] } After the ball hits the wall, the horizontal velocity is reversed. Since we have placed the wall at x=O, we can simply flip the sign of the x-component of position and velocity. We do this with an :If statement based upon whether the time is less than or greater than the time the ball hits the wall, tWall. In [421 := position[t.] := J:f[t <tWall, {+x[t],y[t]}, {-x[t],y[t]}]/.ySol/.xSol The time at which the ball hits the wall is when x [t] =0. In[431:= tWall=t/.Solve[x[t] ==O/.xSol,t] [[1]] xO Ou t [ 431 = - vxO We choose some arbittary numerical values for the parameters, In[441:= values = {xO -+ -100, g-+ 9.8,yO -+ 100} Out[441= {xO->-100,g->9.8,yO->100} and we define a function that generates a plot for a specific value of the horizontal velocity, vxO. In [ 45 1 : = plot [v _] : = parametricPlot [ position[t] / / . values/ . {vxO -+ v}/ /Evaluate, {t, 0, 5}, Displayl"unction -+ J:dentity] ; We now plot the ttajectories for a range of horizontal velocities. 
54 v= z' -hz' mg Chapter 2 General Physics In [461: = Show [Table [plot [v], {v, 5, 50, 5}], DisplayFunction -+ $DisplayFunction, PlotRange-+ {{-125, O}, {O,lOO}}, Epilog -+ {Thickness [0.02] , Hue [1.] , Line[{{O, O}, {O,lOO}}]} ] ; Notice how we used the Epilog command to draw a colored line to represent the wall. . PROBLEM 4 Falling Projectile with Linear Air Resistance Drag. A particle of mass m is subject to the constant pull of gravity (with acceleration g) and the force of air resistance. The particle is dropped from a point x=O and z=zO. The initial velocity is zero. The force of the air resistance is assumed to be linearly dependent on the speed. The motion of the projectile is described by the equation: mz"[t] = -mg - bz'[t] where -m g is the gravitational term, and -b z' [t] is the air resistance term. Assume that b is greater than or equal to zero. m 3. Solve the equations of motion for the particle's position and velocity if the initial conditions are z' [0] =0 and z [0] =zO. Find the terminal velocity. Take the limit of the solution as bO (Le., no air resistance) to find the free fall solution. b. Plot the particle's position as a function of t for b={0,1/2,1}. c. Plot the particle's speed as a function of t for b={0,1/2,1}. d. Consttuct an artificial table of data points for {t, z [tJ} with an experimen- tal error in z [t] of 10%. Use NonlinearFit from the package Statis- tics' NonlinearFi t' to determine the coefficient of drag b from the data points. Assume the form of the nonlinear fit is a1 + a2 t + a3 Exp [-a4 t] . Remarks and Outline This problem illusttates the use of the commands Limit, Series, and NonlinearFit found in the add-on package Statistics 'Non- linearFi t '. DSol ve gives the analytic solution for the equations of motion in a constant gravity field. Graphic options are used to embellish the plots. 
2.2 Newtonian Mechanics in Inertial Frames 55 Solution In[47J := Cl_r[RGlobal' * R]; a. The motion of the projectile is described by the equation: In[48J:= eql = {m z" [t] == -m g - b z' [t]}; Assume the initial position and velocity are In[49J:= initial = {z[O] == zO, z' [0] == OJ; The speed and position of the falling particle follow from applying DSa! ve to eq1 with the appropriate initial conditions: In [50J := z[t.] = z[t]/.DSolve[Join[eql,initial], {z}, t] / /I!'irst / /Si.m;plify ZOb 2 +gIn( -e-m+m-bt) Out[50J= b 2 In[51J:= v[t.] = z' [t] //Siq>lify ( - 1 H. ) gIn Out [51J = b Obviously, we require bO for a physical solution so that the exponential term remains finite. We can find the terminal velocity by taking the limit of the velocity as too. Note we first rescale the time by defining the positive parameter T=b t/m, and then take the limit. In [52J := v'l'erminal = Limit [v[t] /. {t -+ 1: mlb}, 1: -+ 00] Out[52J= - gIn b The terminal velocity is finite because as a falling object picks up speed due to the con- stant gravitational force, the resistive force grows in magnitude. Eventually the two forces cancel, resulting in zero vertical acceleration, and thus constant downward component of velocity. Our solution reduces to the standard free-fall solution in the limit bO. To show this, take the limits of zf and vf as bO. In[53J:= {zff,vff} =Limit[{z[t],v[t]},b-+O] { gt2 } Out[53J= ZO-T,-gt The parameters {zff, vff} are the speed and position for the case of zero air resistance. b. Plot the vertical position z [t] versus t for b={ O,1/2,2} and for the following values of the parameters: 
56 Chapter 2 General Physics In[54]:= values = {g-+9.8,m-+1,zO-+0}; For b nonzero, the time and position {t, z [t] } are given by In[55]:= pointZ[b.,t.] = {t,z[t]}/.values Out[55]= {t, 9.8(-bt2e.bt+l) } Note that this definition of point will be indeterminant when b=O; therefore, for the special case b=O, we define: In[56]:= pointZ[O,t_] = {t,zff}/.values Out[56]= {t,-4.9t 2 } Note that while the general definition of point [b_] will be ill-defined for b=O, Math- ematica always applies specific definitions first; therefore, when b=O, the second definition will always be used rather than the first. For convenience, define a function to make a plot of {t, z [t] } for arbittary values of b: In[57]:= plotZ [b_, hue.] .- ParametricPlot[pointZ[b,t], {t,O,10}, PlotStyle -+ {Hue[hue],Thickness[0.008]}, Displa.y!'unction -+ J:dentity ] ; The arguments for the plotZ are b and the hue of the curve. To view the results we apply Show with the option DisplayFunction$DisplayFunction. Let us plot several paths with different values of b. The list of plots for b={ 0,1/2,1 } is: In[58]:= part1 = Show[Table[plotZ[b,b/2], {b, 0, 1, 1/2}], DisplayFunction -+ $DisplayFunction ] ; -50 -100 -150 .200 -250 
2.2 Newtonian Mechanics in Inertial Frames 57 We next define the text for the graphics. In [59] := textZ = { Text [I!'ontl!'orm [nb = 0 n, {nTimes - Bold n , 12}], pointZ [0,7]], Text [I!'ontl!'orm [nb = 1/2 n , {nTimes - Bold n , 12}], pointZ [0 .5,7]], Text [I!'ontl!'orm[nb = 1 n , {nTimes - Bold n , 12}], pointZ [1,7]] }/ /Graphics; Note how we compute the placement of the text labels dynamically with the point function; this ensures that they will be properly placed even if we change parameters and generate different curves. Combining the graphs and text, we obtain: In[60]:= Show[{part1,textZ}, Frame -+ True, GridLines -+ Automatic, I!'rameLabel -+ { n time n, nheight n , nBffectofAirResistancen, nn}, RotateLabel -+ False, DisplayFunction -+ $Displa.yl!'unction ] ; Effect of Air Resistance o -50 -100 height -150 -200 -250 -300 0 2 4 6 time 10 We have included some Options in the Show command to enhance the plot. c. We next plot the velocity as a function of time for b= {O , 1/2, 1}. For b nonzero, the time and position {t, z [t]} are given by: In[61]:= pointV[b_, t_] = {t, v[t]}/ . values { 9.8 (-1 + e. bt ) } Out[61]= t, b Note that this definition of point V will be indeterminant when b=O; therefore, for the special case b=O, we define: 
58 Chapter 2 General Physics In [62] := pointv[O, t.] = {t, vff}/ . values Out[62]= it, -9.8t} Again, note that while the general definition of pointV [b_] will be ill-defined for b=O, Mathematica always applies specific definitions first; therefore, when b=O the sec- ond definition will always be used rather than the first. For convenience, define a function to make a plot of {t, v [t] } for arbittary values of b: In [63] : = plotV [b., hue.] .- parametricPlot[pointV[b,t], {t,O,10}, PlotStyle -+ {Hue[hue],Thickness[0.008]}, DisplayFunction -+ J:dentity ] ; Let us plot several paths with different values ofb. The list of plots for b={0,1/2,1} is: In[64]:= part2 = Show[Table[plotV[b,b/2], {b, 0, 1, 1/2}], DisplayFunction -+ $DisplayFunction ] ; .40 -20 -60 -80 We next define the text for the graphics. In[65]:= textv= { Text [I!'ontl!'orm ["b = 0", {"Times - Bold", 12}], pointv[O, 7]], Text [I!'ontl!'orm[nb = 1/2", { "Times - Bold n , 12}] , pointy [0.5, 7] ] , Text [I!'ontl!'orm[nb = in, {"Times - Bold n , 12}], pointV[l, 7] ] }//Graphics; 
2.2 Newtonian Mechanics in Inertial Frames 59 Note how we compute the placement of the text labels dynamically with the point function; this ensures that they will be properly placed even if we change parameters and generate different curves. Combining the graphs and text, we obtain: In[66]:= Show[{part2, textV}, Frame -+ True, GridLines -+ Automatic, FrameLabel -+ {ntime n , nspeed n , nBffectofAirResistancen, nn}, RotateLabel -+ False, Displa.yl!'unction -+ $Displa.yl!'unction ] ; Effect of Air Resistance o speed .20 -40 -60 -80 -100 0 2 4 6 time We have included some Options in the Show command to enhance the plot. d. For the specific case b=1/2, let us consttuct an artificial table of data points for the time and position {t, zb} with a 10% Gaussian experimental error to simulate an actual experimental measurement. We will use the command NormalDistribution, which is found in the package Statistics 'NormalDistribution'. In[67]:= «Statistics'NormalDistribution' We define the command gaussian that will generate a table of random numbers cen- tered about 1 with a standard deviation of 0.1. In[68]:= gaussian := Randam[NormalDistribution[l,O.l]] Table[gaussian, {i,lO}] Out[68]= {0.93877, 1.02, 0.971886, 1.00302, 1.12965, 1.06752,0.816305,0.969329,1.05662,1.20211} We next generate a table of data centered about z [t] with a gaussian error distri- bution. 
60 Chapter 2 General physics In [69J := data = Table [{t, z [t] gaussian}, {t, 0,40, 1}] I. values 1 . {b -+ 1/2}; listplot = ListPlot [data, Plot Style -+ {PointSize [0.03] } ] ; 20 30 40 -800 ... .... . .. ... . . ...... . III. . . . . -200 -400 -600 Let us see if we can reproduce the analytic expression by fitting the data with some function. We load the package Statistics' NonlinearFi t " which contains the command NonlinearFi t. In[70J:= «Statistics'NonlinearPit' We are interested in the command NonlinearFit and we can see the command usage by entering: In[71J:= ?NonlinearPit We've suppressed the output to save space. We will now fit the data table to the functional form: a1+a2 t+a3 Exp [-a4 t]. In[72J:= fit = NonlinearPit [data, al + a2t + a3Bxp[-a4t], {t}, {al, a2, a3, a4}] Out [72J = -21. 0617t - 80. 8972e.o.069815t + 93.0795 To see if this fit is close to the analytic solution, we plot the two results: In [73 J : = fitPlot = Plot [{fit, z [t] } 1 . values 1 . {b -+ 1/2}11 Evaluate, {t, 0, 40}, PlotStyle -+ {{ RGBColor [0, 0, 1] }, {RGBColor [1, 0, 0], Thickness [0.008]}}] ; 
2.2 Newtonian Mechanics in Inertial Frames 61 -400 -200 -600 The curves match so closely, it is better to examine the ratio: In [74J : = Plot [fit/z [t] / .values/. {b -+ 1/2} / / Evaluate, {t, 0, 40}]; 1 0.5 10 20 30 40 -0.5 -1 We see the ratio matches very precisely except where z [t] is approximately zero, as expected. Finally, we overlay all the plots: In[75J:= Show[listplot,fitPlot, GridLines -+ Automatic, Frame -+ True, FrameLabel -+ {Rtime R , Dheight R , RExperimentalData D , Dft}, RotateLabel -+ False ] ; -600 10 20 time 30 -200 height -400 -800 o 
62 Chapter 2 General Physics . PROBLEM 5 Falling Projectile with Quadratic Air Resistance Drag. A particle of mass m is subject to the force of gravity (with acceleration g) and the force of air resistance. The particle is tossed upward and then allowed to drop back to earth. Also, assume the particle is consttained to move only along the direction of the gravitational force. Assume the force of the air drag is opposite the direction of motion, and proportional to the square of the speed. The motion of the projectile is described by the equations Upward motion " [ ] b ' [ ] 2 zt=-g--zt m Downward motion z"[t] = -g+ Z'[t]2 m where we assume b is positive. The two cases are necessary to ensure the drag is opposite the direction of motion. v v m m F drag F gravity F drag a. Solve for the particle's upward position and velocity. b. Find the time for the particle to reach the top of its ttajectory, and then solve for the downward position and velocity. c. Plot the particle's motion and compare with the motion when there is no air resis- tance. Remarks and Outline This problem is more complicated than the previous problem with linear drag. This problem has both upward and downward motion that must be tteated separately because the direction of the drag is opposite the particle's direction of motion; hence, the equations of motion are also more difficult to solve. Solution In[76]:= Clear[OGlobal' * 0]; a. The motion of the projectile is described by the equation: In[77]:= eql[sign.] = {m z"[t] ==-m g-sign b Z'[t]2}; 
2.2 Newtonian Mechanics in Inertial Frames 63 where we insert the parameter sign to allow for upward (sign=+l) or downward (sign=-l) motion. Assume the initial position is zO, and the initial velocity is vzO . We can solve for the position using DSol ve. In[78]:= dso1U'p = DSo1ve[Join[eql[+1], {z'[O] ==vzO}], {z}, t] / /First / /Simplify Out [78] = {z -7 Function [ {t}, yrnTan- 1 [ YJo'1m bC 2 + mLog [ Cos [ m b "'''' ] ] ]} Here, we discovered (by trial and error) that Mathematica found it easier to solve \his equation with only a single boundary condition, z' [O]==vzO. We now substitute \his solution into the remaining boundary condition, In [79] := 02s01 = Solve[z[O] == zO/.dso1U'p, 02]//First// Simplify m Log [ 1 ) ) bV;;2 +1 { C 2 -7 zO - b } Out[79]= and find that the final constant c 2 is related to the initial height zOo We make \his replace- ment in dsolUp: In[80]:= dso1U'p = dso1U'p/ .02s01; The solution for the position and velocity in the case of upward motion is: In [81] : = {zU'p, vUp} = {z [t], z' [t] } / .dso1U'p/ / FullSimp1ify Out [81] = {[ bzO + mLOg ( b:0 2 +1 J + [ [ Ybygt [ YbvzO ] ] ] ] mLog Cos ym - Tan. 1 ygym , . 19ymTan ( Ybygt - Tan. 1 ( YbvzO J J "V '" yrn ygyrn } Yb 
64 Chapter 2 General Physics As a check, we verify that the result reduces correctly to the free-fall case without air resistance. In[82] : = {zU'pO, vUpO} = Limit [{zU'p, vUp}, b  0] { gt2 } Out[82]= -T+vzOt+zo,vzO-gt b. The solution for downward motion can be obtained from the previous result by re- versing the sign of the sign parameter. We can solve for the position using DSol ve. For the case of downward motion, the boundary conditions are slightly different; when the projectile reaches the top of the ttajectory at time timeTop, the velocity is initially zero (z' [timeTop] =0), and the position is equal to zMax (z [timeTop] =ZMax). In [83] := dso1Down = DSo1ve[Join[eql[-1], {z'[timeTop] == O}], {z}, t] / /First / /Simplify Out[83]= {z -> Function [{t}, b L [ C h [ YbygtirneTop-Ybygt ) ) c 2 - m og os ym b ]} Again, we discovered (by trial and error) that Mathematica found it easier to solve this equation with only a single boundary condition, z' [timeTop] ==0. We now substitute this solution into the remaining boundary condition, In[84]:= 02s01 = Solve [z [timeTop] == zMax/ .dso1Down, O 2 ] / / First//Simplify Out[84]= {c 2 -> zMax} and find that the final constant c 2 is simply the maximum height zMax. We make the replacement in dsolDown: In [85] := dso1Down = dso1Down/ .02s01; The solution for the position and velocity for the case of downward motion is: In[86]:= {zDown, vDown} = {z[t],z'[t]}/.dso1Down//Fu11Simp1ify mLog [ Cosh [ Ybyg(teTop.t) ) ) Out[86]= {zMax- b ygymTaIJh [ Ybyg(t:;.eTop.t) ) Vb } 
2.2 Newtonian Mechanics in Inertial Frames 65 As a check, we verify that the result correctly reduces to the free-fall case without air resistance: In[87]:= {zDownO, vDownO} = Limit [{zDown, vDown}, b  0] Out [87] = {ZMaX - g (t - timeTop) 2, g (time Top - t) } We can also find the terminal velocity by first re-scaling the time variable, and then taking the limit as time becomes infinite. In [88] : = v'l'erminal = Limit [vDown/. {t  _ j;-"t },"t  00] 'V b.yg /gym Out[88]= - Vb. c. We plot the vertical position z [t] versus t for the following values of the parame- ters: In [89] := values = {g  9.8, m 1, zO  0, b  0.1, vzO+20}; The time the projectile reaches the top is determined when the upward (vUp= 0) velocity is zero: In[90]:= timeTop = t/. Solve[vUp == O/.values, t]llP'irst Out[90]= 1.12246 We can use this result to determine the maximum height (zMax), In[91]:= zMax = zU'p1 .values/. {t  timeTop} Out[91]= 8.12816 We now create functions that yield the full position and velocity results for any given time: In [92] := zP'ull[t:In_] := :If [t:In < timeTop, zU'p, zDown] I . values I . {t  t:In} vP'ull [tJ:n..] : = :If [t:In < timeTop, vUp, vDown] I .values/. {t  t:In} Likewise, we create a similar set of functions that yields the position and velocity in the case where there is no air resistance; for this simpler case, we need not distinguish upward- and downward-going solutions. In[93]:= zP'ullO[t:In..] :=zU'pO/.values/.{tt:In} vP'ullO [t:In_] : = vUpOI .values/. {t  t:In} 
66 r " j 1 '=N, Chapter 2 General Physics We now compare graphically the full solution with and without air resistance. In[94] : = Plot [{zl'ull [t], zl'ullO [t] }, {t, 0, 7}, PlotStyle  {{Thickness [0.008]}, O}]; 20 -20 -40 -60 -80 -100 Similarly, we compare the full solution for the velocity with and without air resistance. In [95] : = Plot [{vFull [t], vFullO [t] }, {t, 0, 7}, PlotStyle  {{Thickness [0.008] }, {}}]; Clearly, the case with air resistance (thick line) has a terminal velocity that we find to be: In[96]:= {vFull[lOO],vTermdnal}/.values Out[96]= {-9.89949, -9.89949} . PROBLEM 6 Rocket with Varying Mass. A rocket is fired vertically upward with a mass loss of -dm[tV dt due to exhaust. At time t, it has velocity v relative to the Earth (inertial frame). The exhaust leaves the rocket with velocity u relative to the Earth (inertial frame). Let ve be the exhaust speed relative to the rocket or u= (v-ve). The sign of ve has been chosen to be positive, so the exhaust velocity is directed toward Earth. The change in mass -dm[tVdt is a loss so it has a negative value (-dm[tVdt < 0). a. Show that the rocket's equation of motion is: dv dm m dt = +vedi" -mg 
2.2 Newtonian Mechanics in Inertial Frames 67 b. Assume a constant mass loss, and use DSol ve to find x and v. Find the height of the rocket when all the mass of the rocket has been used as fuel. c. Plot the distance versus height for different exhaust speeds. d. Solve the rocket equation by assuming it can be written as a power series in t. Remarks and Outline The equations of motion are obtained by applying Newton's sec- ond law, d pI dt = F, to the combined Rocket +exhaust system. The solution of the differen- tial equation is given by DSolve, and the results are plotted using parametricPlot. The solution can also be obtained by assuming a power series expansion in t. The series solution reduces to a set of algebraic equations, and the exact solution is recovered after summing the infinite series. Solution In[97]:= Clear [oGlobal ' * 0]; a. Let v and m be the velocity and mass of the rocket at time t, ve be the exhaust velocity relative to the rocket, and u be the velocity of the exhaust gas relative to the Earth, i.e., u= (v-ve). At time t the mass is In, and at time t+6t, the rocket mass is (m-6m) and the exhaust mass is (+6m). The momentum of the rocket -exhaust system at time t and at t+6t are: In [98] := p[t] = m[t]v; p[t+c5t] = (m[t] -c5m) (v+c5v) + (+c5m) (v-ve); In the expression for the final momentum, p [t+6t], the first term represents the rocket's momentum with the new mass value (m[t] -15m) and new velocity (v+6v). The second term represents the momentum of the exhaust of mass (+6m) moving with velocity u= (v-ve) in Earth's inertial frame. The differential relations are In [99] := c5v = x" [t]c5t; c5m= -m[t]c5t; The momentum change is: In[100]:= c5p= (p[t+c5t] -p[t])//EXpandAll Out[100]= m' (t)x" (t)6t 2 +vem' (t)6t +m(t)x" (t)ot Applying Newton's second law, dpldt = F, we set the rate of momentum change equal to the external gravitational force, F=-m g, and take the limit 6tO: In[101]:= eql = -m[t]g == c5p/c5t//ExpandAll Out[101]= -gm(t) ==vem'(t) +otx"(t)m'(t) +m(t)x"(t) In[102]:= eql = eql/ .c5t  0 Out[102]= -gm(t) ==vem'(t) +m(t)x"(t) 
68 Chapter 2 General Physics where m' [t] is the rate of decrease of rocket mass. We observe that eql is the desired equation of motion. b. If we take the rate of mass change to be m' [t] = + &It and the initial mass at time zero to be m [0] =mO, then the time dependence of the mass of the rocket is: In[103]:= dsoll = DSolve[{m'[t] == -l>m,m[O] ==mO},m,t]// Flatten Out [103]= {m -7 Function [{t}, mO - tLlm]} The dsoll is expressed in pure form so that this substitution will work for derivatives ofm. We use dsoll to eliminatem[t] andm'[t] in eql: In[104]:= eq2 = eql/.dsol1//Simplify au t [ 104] = (gt + ve) LIm + (tLlm - mO) x" (t) = = groO and we then solve for x' , [t]: In[105]:= eq3 = (Solve [eq2, XU [t] ] / / First / /First) /. Rule  Equal Out[105]= x"(t) == groO- (gt+ve)LIm tLlm - mO The substitution RuleEqual changes the rule to an equation. Applying DSol ve to eq3 with the initial conditions x [0] ==0 and x' [0] ==0, the solution for x [t] follows: In[106]:= position = x[t]/.DSolve[{eq3,x[O] ==O,x'[O] ==O), x, t] / /First / /FullSimplify 1 Out[106]= 2L1m (t(2ve-gt)LIm+ 2ve (mO - tLlm) (Log (mO - tLlm) - Log (mO) ) ) The speed follows from the time derivative of the position: In[107]:= speed = D[Position, t] / /Simplify Out[107]= -gt +veLog(mO) -veLog(mO - tLlm) Notice, all the rocket's fuel is consumed after a time t=mO / &It. The rocket's height when this occurs is In[108]:= height = Limit [position, t- >mO/l>m] [ 8 mO (groO - 2veLlm) Out 10 ]= - 2 2L1m 
2.2 Newtonian Mechanics in Inertial Frames 69 C. We use the command parametricPlot to plot position versus speed for different values of the exhaust speed ve. We choose the arbittary parameters: In[109]:= values = {mO100,l>m10,g9.8}; and let t vary between t=O and t=tf, where the time tf=mO / &It is the time it takes for the rocket's mass to be consumed: In[110]:= tf = (mO/l>m)/.values Out[110]= 10 A plot command that graphs the position and speed for a given value of ve is In [111] : = plotl [ve:In_] : = parametricPlot[ {position,speed}/.values/. {ve  ve:In} / /Evaluate, {t, 0, tf}, PlotStyle  Thickness [0 . 01] , DisplayFunction  :Identity The value of veIn is input for the plotl function, and the rule veveIn is used to replace ve in the expressions for {position, speed}. We next use the Graphics primitive to place a line at the elevation when the fuel is exhausted. In[112]:= elevation[ve_] = {Thickness [0.004], Hue[0.8], Line [{{height, O}, {height, 10000}}]} /. values//Graphics; Superimposing the graphs for ve={lOO, 200,300, 400} and adding grahics options, we get In[113]:= Show[Table[{elevation[ve],plotl[ve]}, {ve,100,400,100}], Frame  True, FrameLabel  {Rposition D , Dspeed D , 1111 I nil}, RotateLabel  False, PlotRange  {{O, 4000}, {O, 4000}}, DisplayFu.nction  $DisplayFunction ] ; 
70 Chapter 2 General Physics 4000 3500 3000 2500 speed 2000 1500 1000 500 d. We expand the equations of motion given by eq3 in a time series expansion and solve for the unknown coefficients. We retain terms up to sixth order; this is sufficient to demonsttate the pattern, and it is easy to increase the order. We take the following initial conditions: In[114]:= initial = {x[O] O,x'[O] O}; order = 6; We move the right-hand side of eq3 to the left-hand side and perform a Series expansion in time: In[115]:= eq4 = Series [eq3 [[1]] - eq3 [[2]], {t, 0, order}] /. initial//Simplify Out[115]= ( veLlm " ) ( ( 3 ) ) veLlm 2 ) g--+x (0) + X (0 -- t+ mO m0 2 [ 1 veLlm 3 ) [ 1 veLlm 4 ) _X(4) (0) _ - t 2 + _x(S) (0) _ - t 3 + 2 m0 3 6 m0 4 [ 1 6 veLlm S ) -x() (0) -- t 4 + 24 mO s [ x(7) (0) _ veLlm 6 ) t s + 120 m0 6 [ 1 veLlm 7 ) 6 _X(8) (0) - - t +O(t 7 ) 720 m0 7 The solution of this differential equation now reduces to a set of algebraic equations by setting the coefficient of each power of time to zero. We must solve for these variables: In[116]:= variables = Table [D[x[t], {t, n}], {n, 0, order + 1}] /. {t  O} Out[116]= {x(O), x' (0), x" (0), x(3) (0), X(4) (0), x(S) (0), X(6) (0), x(7) (O)} The solution for the coefficients of t are given by 
2.2 Newtonian Mechanics in Inertial Frames 71 In[ll?]:= so11 = Solve [eq4 == 0, variables] [[1]] Solve :: svars : Equations may not give solutions for all "solve" variables. { veLlm - groO 3 veLlm 2 Out[ll?]= x"(O) -> mO ,xl) (0) ->' 2veLlm 3 6veLlm 4 x(4) (0) ->_,x IS ) (0) ->-, m0 3 m0 4 (6) 24veLlm S (7) 120veLlm 6 } x (0)-> S ,x (0)-> 6 mO mO The series expansion solution for x [t] is In[118]:= seriesl = (x[t] + O[t] -order) I .so111 . initial I I ExpandA11 ( veLlm g ) 2 veLlm 2 t 3 2mO -"2 t + 6m0 2 + veLlm 3 t 4 veLlm 4 t S + + O(t 6 ) 12m0 3 20m0 4 Out[118]= You can sum this expansion to get an exact solution by noticing that the nth term has the form t D + 1 ve (  ) D In[119]:= term[n_] = mO n (n + 1) except for the leading term that contains an extta factor: - (1 / 2 ) 9 t 2 . Let us verify that our expression matches the original series. In [120] : = series2 = - (1/2) $I t-2 + Sum [term [n] , {n, 1, order - 2}] ; seriesl == series2 l/Norma1 l/EXpandA11 Out[120]= True We sum the infinite series to get the exact solution: In [121] : = exact2 = - (1/2) $I t-2 + Sum[term[n], {n, 1, oo}] I I FullSimp1ify t (2ve - gt) LIm + 2ve (mO - tLlm) Log (I - ) 2L1m Out[121]= which agrees with the previous solution obtained analytically in the previous section. In[122]:= «position==exact2) lIMapA11[Together,#]& l/PowerExpand liFullSimp1ify Out[122]= True 
72 Chapter 2 General Physics . PROBLEM 7 Keplerian Orbits. Consider the nine planets of our solar system. a. For each of the nine planets of our solar system, verify Kepler's third Law, which states: 4 a 3 Jr2  = M Sun + MPlanet '" M Sun TG Here, a is the semi-major axis, T is the period, and G is Newton's gravitational constant. b. Plot the orbits of the planets; let the unit of distance be one Asttonomical Unit. To make the plots readable, plot the inner four planets on one graph, and the outer five on another graph. Remarks and Outline While this problem is sttaightforward to compute for any single planet, Mathematica is adept at handling lists, so we can use this problem to show off this feature. Specifically, we use the arrays {mass, axes, period, e} to simplify this calculation. Note how Mathematica threads most operations over lists automatically; in a Fortran or C program, you would have to write a loop to perform the same operation. Solution In[123]:= Clear ["Global ' *"]; a. We start by defining the following variables containing the necessary data. (Don't type this data table in by hand; get the input files from our web site listed in the preface.) In[124]:= (* Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto period 0.241, 0.615, 1., 1.881, 11.86, 29.42, 83.75, 163.7, 248., mass = {3.3 * 10 A 23, = {4.87 * 10 A 24, = {5.974 * 10 A 24, = {6.419 * 10 A 23, = {18.99 * 10 A 26, = {5.68 * 10 A 26, = {8.68 * 10 A 25, = {10.2 * 10 A 25, = {1.27 * 10 A 22, axes 0.5791 * 10 A ll, 1. 0821 * 10 A ll, 1.496 * 10 A ll, 2.2794 * 10 A ll, 7.784 * 10 A ll, 14.27 * 10 A ll, 28.71 * 10 A ll, 44.98 * 10 A ll, 59.506 * 10 A ll, e *) 0.206); 0.007); 0.017); 0.093); 0.048}; 0.054); 0.047}; 0.009}; 0.249}; This table lists the mass in kilograms, the semi-major axis in meters, the period in years, and the eccentricity. You can consolidate the data for the nine planets by combining the nine lists: In [125] := data = {Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto); It is also convenient to define a list of names of the planets: In[126]:= names = {"Mercury", "VenusO, °EarthO, "Mars", "JUpiter", " Saturn ° , "Uranus", "Neptune",Opluto"}; 
2.2 Newtonian Mechanics in Inertial Frames 73 Now we can display this data in a convenient TableForm. In[127]:= TableForm[data, TableHeadings -+ {names, {RMassR, RAxes R , Rperiod R , Re R }}] Out[127]= Mass 3 .3 x 10 23 4.87 x 10 24 5.974 x 10 24 6.419 x 10 23 1.899 X 10 27 5.68 X 10 26 8.68 x 10 25 1. 02 X 10 26 1.27x10 22 Axes 5.791 x 10 10 1.0821 x 1011 1.496x10 ll 2.2794x10 ll 7.784x10 ll 1. 427 x 10 12 2.871 x 10 12 4.498x10 12 5.9506 x 10 12 Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto Period 0.241 0.615 1. 1.881 11.86 29.42 83.75 163.7 248. E 0.206 0.007 0.017 0.093 0.048 0.054 0.047 0.009 0.249 By ttansposing the data table, we can define the following variables: In[128]:= {mass, axes, period, e} = Transpose [data] ; For example, we display the array period: In[129]:= period Out[129]= {0.241, 0.615, 1., 1.881,11.86,29.42,83.75,163.7, 248.} We load the package Miscellaneous 'Units' to help us with conversion of units, and we also load the package Miscellaneous' Physical Constants " which con- tainsGravitationalConstant. In[130]:= «Miscellaneous'units' «Miscellaneous'physicalConstants' We collect some useful substitutions into values: In[131]:= values = { year2sec -+ Convert [Year, Second] , G -+ GravitationalConstant, Newton -+ KilogramMeter /S8Oond 2 , Astronomicalunit- > Convert [Astronomicalunit, Meter] }; values//TableForm Out[131]= year2sec -+ 31536000Second 6.673 x 10. ll Meter 2 Newton Kilogram 2 KilograroMeter Newton -+ Second 2 AstronomicalUni t -+ 1. 49598 x 10 ll Meter G-+ 
74 Chapter 2 General Physics Kepler's third law states: 4a 3 1f2  = M Sun + MPlanet '" Msun TG where the mass of the sun is M Sun = 1.99 x 10 30 kg, and Newton's gravitational constant is -11 Nm 2 G = 6.67 x 10 ----yo kg The data for the ratio 4a 3 1f2/T 2 G for each planet follows from: In[132]:= kep1er = 4a3 /. {a -+ axes * Meter, TG T -+ period * year2sec}/ / .va1ues Out[132]= {1.98908 x 10 30 Kilogram, 1.99286 x 10 30 Kilogram, 1.99168 x 1030 Kilogram, 1.99118 x 10 30 Kilogram, 1.99464 x 1030 Kilogram, 1.99716 x 10 30 Kilogram, 2.00704 x 1030 Kilogram, 2.02016 x 10 30 Kilogram, 2.038 x 1030 Kilogram} We define solarMass to be the mass of the sun, Msun = 1.99 x 1 0 30 kg, and compare each element in the list kepler with this value: In [133] : = solarMass = 1.99 * 10 30 Ki1ogram; [ kep1er Tab1eForm , solarMass Tab1eHeadings -+ {names} ] / / paddedForm[#, {4,3}]& Out[133]= Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto 1. 000 1. 001 1.001 1.001 1. 002 1. 004 1.009 1. 015 1.024 The results agree fairly well with the mass of the Sun for all the planets, and they would be even closer if the parameters we input in the data table for the planets were more accurate. b. The relation between the radius, r, of the orbit and the angle, 0, depends on the semi-major axis a, and the eccentricity, e: a(1 - e 2 ) r= (1 + ecos[O]) 
2.2 Newtonian Mechanics in Inertial Frames 75 As Mathematica is adept at handling lists, it is trivial to perform the computation for all this planets at once. Note how we use the arrays {mass,axes,period,E} to simplify this process. Out[134]= In[134]:= r= a(l- e 2 ) I. (1 + eCos[8]) {a -+ axes * Meter, T -+ period * year2 sec, e -+ e)1 I .va1ues { 5.54525 x 10 10 Meter , 0.206Cos(e) +1 1.08205 x 10 11 Meter 1.49557 x 10 11 Meter 0.007Cos(e) +1 0.017Cos(e) +1 2.25969 x 10 11 Meter 7.76607 x 10 11 Meter 0.093 Cos (e) +1 0.048Cos(e) +1 1.42284 x 10 12 Meter 2.86466 x 10 12 Meter 0.054Cos(e) +1 0.047Cos(e) +1 4.49764 x 10 12 Meter , 5.58166 x 10 12 Meter } 0.009Cos(e) +1 0.249Cos(e) +1 We can convert from {r,B} coordinates to {x,y}={r Cos[O], r Sin[BJ} as follows: In[135]:= points = OUter [ #1 * #2&:,  . ' Astronom1calUU1t {COS[8],Sin[8])]/.values [ 0.370677 Cos (e) 0.370677 Sin (e) Out[135]= 0.206Cos(e) + 1 0.206Cos(e) + 1 0.723304 Cos (e) 0.723304 Sin (e) 0.007 Cos (e) +1 0.007Cos(e) +1 0.999725 Cos (e) 0.999725 S in (e) 0.017Cos(e) +1 0.017 Cos (e) +1 1. 51051 Cos (e) 1. 51051 S1n (e) 0.093Cos(e) +1 0.093Cos(e) +1 5.19129Cos(e) 5.19129S1n(e) 0.048Cos(e) +1 0.048Cos(e) +1 9.51109 Cos (e) 9.51109 S1n (e) 0.054Cos(e) +1 0.054Cos(e) +1 19.1491 Cos (e) 19.1491 S1n (e) 0.047Cos(e) +1 0.047Cos(e) +1 30.0648 Cos (e) 30.0648S1n(e) 0.009Cos(e) +1 0.009Cos(e) +1 37.3111 Cos (e) 37.3111 Sm (e) 0.249Cos(e) +1 0.249Cos(e) +1 Here, we use the command Outer to multiply the list of r values with the list of coordinates{x,y}={r Cos [B], r Sin[B]}. Finally, we can display the orbit of the planets as follows: 
76 Chapter 2 General Physics In[136]:= plot1 = parametricPlot [ points [[{l, 2, 3, oiL}]] / /Evaluate, {e, 0, 27f}, PlotRange -+ All, AspectRatio -+ 1]; The previous plot displays the first four orbits, and the next plot displays the outer five orbits. In[137]:= plot2 = parametricPlot [ points [[ {5, 6,7,8, 9}]] / /Evaluate, {e, 0, 27f}, PlotRange -+ All, AspectRatio -+ 1] ; 40 -40 You can display both plots side by side with the command GraphicSArray, 
2.3 Newtonian Mechanics in Rotating Frames 77 In[138]:= Show[GraphicsArray[{plotl,plot2}]]1 . 2.3 . NEWTONIAN MECHANICS IN ROTATING FRAMES 2.3.1 . Overview An inertial reference frame is one that is not accelerating; in such a special reference frame, Newton's laws apply. In many cases, it is useful to discuss the motion of a particle, or sys- tem of particles, relative to a rotating coordinate system-this is a noninertial reference frame. In this case, Newton's laws must be modified to yield correct results in the nonin- tertial reference frame. For example, Newton's second law in a rotating coordinate system becomes: ->. ->. ( d  ->. ) ->. ->. ->. ->.->. m a = F - m "dt x r - 2m( wx v ) - mwx( wx r ) where  is the angular velocity of the moving system and (; is the acceleration relative to the moving coordinates. If the angular velocity  is assumed to be constant, the second term on the right-hand side (proportional to d/dt) vanishes. The last two terms are called the coriolis and centripetal forces, respectively. The following terminology is often used. Transverse force = -m((d/dt)x-;) Centrifugal force = -mx(x -;) (directed away from the center) Centripetal force = +mx(x -;) (directed toward the center) Coriolis force = -2m(x-;). These forces are referred to as "fictitious forces" because they are a consequence of the nonintertial frame; they are not present when using an inertial coordinate system. . PROBLEM 1 Projectile Motion as Measured by an Observer on Earth. Assume the Earth is a sphere rotating about the z-axis with constant angular velocity o' 
78 Chapter 2 General Physics N ro z Inertial Reference Frame a. Find the equations of motion for a projectile as measured by an observer on Earth's surface. Solve the equations by assuming a series expansion in time. Make a two- dimensional plot of the approximate results for ttajectories in the Northern and Southern Hemispheres. b. Solve for the exact answer at the North Pole and make a three-dimensional plot of a ttajectory. c. Solve for the exact answer at the equator and make a three-dimensional plot of a ttajectory. Remarks and Outline The equations of motion follow from Newton's second law as expressed in a rotating coordinate system. In general the solution is very complex; however, an approximate solution can be obtained by assuming a power series in time. The equation can be solved exactly using DSolve for the special cases in which the motion is at the poles or at the equator. This problem illusttates the use of vector products, the time series expansion of differential equations, and three-dimensional graphics. Solution In[139}:= Clear["Global' *"]; a. Assume the Earth is a sphere rotating about the z-axis with constant angular velocity wO. Choose a coordinate system on Earth with the z-axis along the vertical, the x-axis pointing south, and the y-axis pointing east. The position vector -; and the Earth's rotation vector  in this rotating coordinate system are In[140}:= r[t_] = {x[t],y[t],z[t]}; w[t_] = {-wOSin[8], 0, wOCos[8]}; where the angle e is the colatitude, and i - e is the latitude. Here, we write w [t] since this is in general a function of t. For the present problem, w [t] is a constant and w' [t] =0. We simply compute each term in the modified form of Newton's second law: -->. ( -->. ) ( d -->. ) -->. -->. -->. -->.-->. ma = F. . - m - d x r - 2m(wxv) - mwx(wxr) Inertial t 
2.3 Newtonian Mechanics in Rotating Frames 79 We begin with the fictitious forces. The ttansverse force vanishes because we have a con- stant angular velocity: In[141]:= fTransverse = -mCross [I.LI' [t], r[t]] Out[141]= {a, 0, O} The coriolis and centrifugal forces are: In[142]:= fCoriolis = -2m Cross [1.LI[t], r' [t]] Out[142]= {2mwOCos (8)y' (t), -2m (wO Cos (8) x' (t) + wO Sin (8) z' (t) ) , 2mwO Sin (8) y' (t) } In[143]:= fCentrifugal = -mCross [I.LI [t], Cross [I.LI [t], r[t] ] ] I I Simplify Out[143]= {mw0 2 Cos(8) (Cos(8)x(t) +Sin(8)z(t)), mw0 2 y(t), mw0 2 Sin(8) (Cos (8)x(t) + Sin(8) z (t))} Finally, the inertial force is In[144]:= fInertial = {O, 0, -mg}; Combining all these terms into Newton's second law, we obtain the equations of motion: In[145]:= eql = m r" [t] - fInertial- fTransverse- fCoriolis - fCentrifugal Out[145]= {-mCos(8) (Cos(8)x(t) +Sin(8)z(t))w0 2 - 2mCos(8)y' (t)wO +mx" (t), -my(t)w0 2 + 2m(wOCos(8)x'(t) +wOSin(8)z'(t)) +my"(t), -mSin(8) (Cos(8)x(t) +Sin(8)z(t))w0 2 - 2mSin (8)y' (t) wO + gm + mz" (t) } For the initial conditions, we take: In[146]:= initialRule = Thread/@{r[O] -+ 0, r' [0] -+ {l, 0, ODII Flatten Out[146]= {x(O) -+ 0, y(O) -+ 0, Z (0) -+ 0, x' (0) -+ 1 , y' (0) -+ 0, z' (0) -+ O} We consttuct a time series solution in t to order nOrder for arbittary e. In[147]:= nOrder = 0; Note that we use a low-order expansion here to keep the expressions simple; it is trivial to redo the calculation for higher orders. The expanded equations of motion become 
80 Chapter 2 General Physics In[148]:= eq2 = (Series [eq1/m, {t, 0, nOrder}] == 0 I. initia1Ru1eliNorma1 II Thread I I Simplify) Out[148]= {x"(O) ==0,2wOCos(8) +y"(O) ==O,g+z"(O) ==O} The variables for which we must solve are: In[149]:= vars = Tab1e[D[{x[t],y[t],z[t]}, {t,i}], {i, 2, nOrder + 2}] I.t ... 011 Flatten Out[149]= {x" (0), y" (0), z" (O)} and the solution is In[150]:= sol = Solve [eq2, vars] II First Out[150]= {x"(O) O,y"(O) -2wOCos(8),z"(O) -g} We create a function point that gives the {x, y, z} coordinate of the ttajectory as a function of time and angle. To the prescribed order, this expression is: In[151]:= point [t., B.] = Series [r[t], {t, 0, nOrder + 2}] I .sol/. initia1Ru1eliNorma1 { gt2 } Out[151]= t, -t 2 wOCos (8), -2 Notice the rotation modifies the motion along the y-axis. For Cos[O] > 0 the deflection is clockwise, and for Cos[O] < 0 the deflection is counterclockwise. To visualize the motion, we plot the ttajectory in the {x, y} plane. Let us compare the paths of a particle in the Northern Hemisphere (0 = ) with a particle in the Southern Hemisphere (0 = ). We define a plot function (lowercase to distinguish this from Mathematica's Plot function) that will show the ttajectory as a function of the angle O. In[152]:= plot [B_] : = parametricP10t [ point[t, B] [[{1, 2}]]/. {wO ... 1, g... 9 .S}I I Evaluate, {t, 0, 20}, Plot Sty1e- > {Thickness [0.016] }, AxesLabe1... {"x, South", ny, East"}, P10tRange... {{O, 20}, {+200, -200}}, Ticks... False, Disp1ay!'unction- > Identity] We apply the plot function to a particle in the Northerm Hemisphere (0= , wO= 1) and to a particle in the Southern Hemisphere (O=, wO=I). Displaying the results, we get 
2.3 Newtonian Mechanics in Rotating Frames 81 In[153]:= {plot[/4],plot[3/4]}// GraphicsArray / / Show; y,East K-..,ou'" y,East  ..,ou," In the Northern Hemisphere (plot on the left), the ttajectory is deflected to the right of its initial path relative to the Earth's surface. In the Southern Hemisphere (plot on the right), a horizontally moving particle is deflected to the left of its original direction of motion. b. Next, we solve the equations of motion for the exact solution at the North Pole (0 = 0) with the following initial conditions: In[154]:= initial = Thread/@ {r[O] == 0, r' [0] == {vxO, 0, OD// Flatten Out[154]= {x(O) == 0, y(O) == 0, z (0) == 0, x' (0) == vxO, y' (0) == 0, z' (0) == O} The equations at the North Pole are In[155]:= eqllorth = Join [Thread [eql == 0], initial]/. 8-+0 Out[155]= {-mx(t)w0 2 -2my'(t)wO+mx"(t) ==0, -my(t)w0 2 + 2mx' (t)wO + my" (t) == 0, gm+z"(t)m==O,x(O) ==O,y(O) ==0, z(O) ==O,x'(O) ==vxO,y'(O) ==O,z'(O) ==O} An exact analytic solution is In[156]:= solNorth = DSolve [eqllorth, {x [t], y[t], z [t]}, t] / / First//FullSimplify Out[156]= {X(t) -> tvxOCos (twO), gt 2 } y(t) -> -tvxO Sin (twO), z (t) ->-2 To generate numerical results, we choose some arbittary parameters: In[157]:= values = {g -+ 9.8, zO -+ 500, vxO -+ l}; The {x, y, z} coordinates of the ttajectory at the North Pole are: 
82 Chapter 2 General Physics In[158]:= pointNorth[t.,I.LIO.] = r[t]/.solNorth/.va1ues Out[158]= {tCos(twO), -tsin(twO) , -4.9t 2 } We use ParametricPlot3D to graph the general space curve {x, y, z} at the North Pole for zero rotational velocity (wO = 0): In[159]:= p1ot1 = parametricP1ot3D[ pointNorth[t,O]//Eva1uate, {t,O,10}, BoxRatios -+ {1, 1, 1}]; 1 o 10 We make a similar plot, but this time with a nonzero rotational velocity (wO = 0.01). We also include some style information {Thickness [ .02] } to distinguish this curve. In [160] : = p1ot2 = ParametricP1ot3D [ Join [pointNorth [t, 0.01], {Thickness[0.02]}]//Eva1uate, {t, 0, 10}, BoxRatios -+ {1, 1, 1}] ; 
2.3 Newtonian Mechanics in Rotating Frames 83 o o 2.5 5 10 Finally, we use Show to overlay the plots so we can compare the effect of the rotating reference frame. In[161]:= Show [ {plotl, plot2}, FaceGrids- > {{O,l, O}, {-1, 0, O}}, BoxRatios- > {1, 1, 1}, ViewPoint- > {1.5, -1., 0.7}, AxesLabel- > {.x - south., -west-, n z _ vertical _ } ] ; 10 o -200 z-vertical -1 The thin ttajectory on the right is for no rotation (w o = 0), and the thick ttajectory on the left is with rotation (w o = 0.01). c. We now solve the equations of motion to obtain an exact solution at the equator (e = ) with the same initial conditions as in Part b. The equations at the equator are 
84 Chapter 2 General Physics In [162] := eqEquator = Join [Thread [eql == 0], initial] /.9 -+ 71"/2 Out[162]= {mx" (t) == 0, -my(t)w0 2 + 2mz' (t)wO + my" (t) == 0, -mz (t) w0 2 - 2my' (t) wO + gm + mz" (t) == 0, x(O) == 0, y(O) == 0, z (0) == 0, x' (0) == vxO, y' (0) == 0, z' (0) == O} and the solution is In [163] : = sol Equator = DSolve [eqEquator, {x[t], y[t], z [t]}, t] / / First//FullSimplify { g (Sin (twO) - twO Cos (twO) ) Out[163]= x(t) -> tvxO, y(t) -> w0 2 ' g(Cos(twO) + twO Sin (twO) -1) } z (t) -> - w0 2 The coordinates of the ttajectory are In[164]:= pointEquator[t_, 1110_] = r[t]/.solEquator/.values Out [ 164 ] = { 9.8(Sin(twO) -twOCos(twO)) t, wo 2 ' 9.8(Cos(twO) +twOSin(twO) -1) } w0 2 Here, we must exercise care to correctly obtain the limit wO-+O: In[165]:= pointEquator[t_, 0] = Limit [pointEquator [t, 1110],1110 -+ 0] Out[165]= {t, 0, -4.9t 2 } Again, we use parametricPlot3D to plot the general space curve {x, y, z}. While this problem is virtually identical to Part b above, we will use a slightly more sophisticated approach to generate the plots. We define a function plotEquator that takes arguments for the angular velocity wO and the style (style) of the line. In[166]:= plotEquator[IIIO_, style_] := ParametricPlot3D[ Join [pointEquator [t, 1110], {style}]/. values//Evaluate, {t,O,lO}, BoxRatios -+ {l, 1, l}, DisplayFunction -+ Identity] ; The plots for ttajectories with rotation (wO = 0.01) and without rotation (wO = 0) are shown. 
2.3 Newtonian Mechanics in Rotating Frames 85 In[167]:= Show[ {plotEquator[O, {Thickness[0.02],Hue[0.6]}], plotEquator[O.Ol, {Thickness [0.01], Hue[0.4]}]}, FaceGrids- > {{O, -1, O}, {-1, 0, O}}, BoxRatios- > {1, 1, 1}, ViewPoint- > {1, 0.7, 0.7}, AxesLa.bel- > {.x - South., .y - East. , nz_Upn}, nisplayFunction- > $nisplayFunction] ; o The thick ttajectory on the left is for no rotation (wO = 0) and the thin ttajectory on the right is with rotation (wO = 0.01). . PROBLEM 2 Foucault Pendulum. Assume the Earth is a sphere rotating about the z- axis with angular velocity woo Its rotation and gravity are assumed to be constant. Choose a coordinate system with the z-axis along the vertical, the x-axis pointing toward the south, and the y-axis pointing toward the east. 
86 Chapter 2 General Physics N ro z z T  x Inertial Reference Frame Earth Reference Frame a. Find the equations of motion for a pendulum as measured by an observer on the Earth's surface. Simplify the equations in the limit of small oscillations by neglecting w terms and assume the motion is confined to the horizontal plane. Show that in this approximation, the motion of the bob is described by the two equations x"[t] = -w 2 x[t] + 2w o cos[8]y'[t] y"[t] = -w 2 y[t] - 2w o cos[8]x'[t] where w 2 = f is the frequency-squared of the pendulum bob (a result familiar from inttoductory physics). b. Combine the real coordinates x [t] and y [t] into the single complex variable u [t] =x [t] + I Y [t] , and show that the equations in Part a reduce to one com- plex equation for u [t] : w 2 u[t] + 2iw o cos[8]u'[t] + u"[t] = 0 Solve the u [t] equation and find expressions for x [t] and y [t]. Assume the initialconditionsarex[O]=O, x' [0]=0, y[O]=yO, andy' [0]=0. c. Plot the motion of the pendulum at three angles: 8 = 0 (North Pole), 8 =  (Equator), and 8 = 7T (South Pole). Remarks and Outline French physicist Jean Bernard Foucault designed a pendulum in 1851 to prove that the Earth rotated about an axis. The pendulum consisted of a large weight suspended by a long cable attached to a ceiling several stories high. The slow ro- tation of the plane of oscillation was the evidence Foucault needed to prove the Earth's rotation. It is based on the concept that when a body is set in motion, it will move contin- uously in a sttaight line provided no outside forces alter the direction. Hence, the Foucault pendulum must swing in a constant direction. If the Foucault pendulum is initially swing- ing toward a specific star, its direction will remain pointed toward that star until acted on by an outside force. The rotation of the plane of oscillation is the result of the Earth rotating in this plane. The equations governing the Foucault pendulum are complicated. Mathematica can solve the general system of equations, but to help make the physics evident, we will ex- amine the solution in the limit of small oscillations. Specifically, we reduce the coupled 
2.3 Newtonian Mechanics in Rotating Frames 87 equations of motion into a single complex equation. We then graph the ttajectory of the pendulum for the case of the equator and the North and South Poles. The graph of the ttajectory can also be computed from the original equations of motion without any simpli- fications if the command NDSol ve is used to get a numerical answer; we leave this as an exercise to the reader. Solution In [168] : = Clear [RGlobal ' * n] ; a. Assume the Earth is a sphere rotating about the z-axis with constant angular velocity wOo Choose a coordinate system on Earth with the z-axis along the vertical, the x-axis pointing south, and the y-axis pointing east. The position vector -; and the Earth's rotation vector  in this rotating coordinate system are In[169]:= r[t_] = {x[t],y[t],z[t]}; lII[t.] = {-IIIOSin[B], O,IIIOCOS[B]}; where the angle () is the colatitude, and }- () is the latitude. Here, we write w [t] since this is in general a function of t. For the present problem, w [t] is a constant and w' [t] = O. We simply compute each term in the modified form of Newton's second law: --" ( --" ) ( d --" ) --" --" --" --"--" ma = F. . -m -xr -2m(wxv)-mwx(wxr) mertlal dt We begin with the fictitious forces. The ttansverse force vanishes because we have a constant angular velocity: In[170]:= fTransverse = -mCross[III' [t], r[t]] Out[170]= {O, 0, O} The coriolis and centrifugal forces are: In[171]:= fCoriolis = -2mCross[lII[t], r' [t]] Out[l71]= {2mwOCos (e)y' (t), -2m(wOCos (e) x' (t) + wO Sin (e) z' (t)), 2mwO Sin(e)¥ (t)} In[172]:= fCentrifugal = -mCross [III [t] , Cross [III [t] , r [t] ] ] / / Siq>lify Out[172]= {mw0 2 Cos(e) (Cos(e)x(t) +Sin(e)z(t)), mw0 2 y(t), mw0 2 Sin (e) (Cos (e)x(t) + Sin (e) z (t))} The inertial forces are the force of gravity plus the tension force in the sITing: In[173]:= fGravity = {O, 0, -mg}; fTension = tension({O, 0, l} - r[t] /L}; fInertial = fGravity + fTension 
88 Chapter 2 General Physics { tensionx(t) tensiony(t) . ( z (t) ) } Out[173J= - L ,- L ,tenson 1----r:- -gm Combining all these terms into Newton's second law, we obtain the equations of motion. In[174J:= eql = o == m r" [t] - fInertial - fTransverse- fCoriolis - fCentrifugal/ /Thread Out[174J= {O == -mCos(S) (Cos(S)x(t) +Sin(S)z(t) )W0 2 _ tensionx(t) 2mCos (S)y' (t) wO + L + mx" (t) , 2 tensiony(t) O==-my(t)wO + L + 2m(wOCos(S)X'(t) +wOSin(S)z'(t)) +my"(t), 0== -mSin (S) (Cos (S) x(t) + Sin (S) z (t) ) w0 2 - 2m Sin(S)y'(t)wo+gm-tension(l- zt) ) +mz"(t)} For the initial conditions, we take: In[175J:= initialRule = Thread/@{r[O] -+ 0, r' [0] -+ {l, 0, O}} / / Flatten Out[175J= {x(O) -> 0, y(O) -> 0, Z (0) -> 0, x' (0) -> 1, y' (0) -> 0, Z' (0) -> O} We assume the motion is confined to the horizontal plane, so we eliminate the z-dependence via the rule In[176J:= zSol=Dsolve[{z[t] ==O},z,t]//First Out [176J= {z -> Function [{t}, 0] } Additionally, if the motion is confined to the horizontal plane we can (to leading order) set Sin [8] to zero. Furthermore, to simplify the calculation, we keep only linear terms in wO by setting w0 2 to zero. Applying these simplifcations to the equations of motion we obtain In[177J:= eq2 = eql/. {W0 2 _ > 0, Sin [a] -+ o}/ .zSol { tensionx(t) " Out[177J= 0== L -2mwOCos(S)y'(t) +mx (tL tensiony(t) " 0== L +2mwOCos(S)x (t)+my' (t), o == gm - tension} We solve these equations for x' , [t] and y' , [t] and also eliminate the tension. 
2.3 Newtonian Mechanics in Rotating Frames 89 In[178J:= eq3 = Solve [eq2, {x" [t], y" [t] }, tension] /. {Rule -+ Equal} / / First Out[178J = { " gx(t) - 2LwOCos (e)y' (t) x (t) == L ' " gy(t) + 2LwOCos (e) x' (t) } Y (t) == - L Finally, we will find it convenient to inttoduce w 2 = g/L. In [179 J : = eq4 = eq3/. {g -+ 1I)2 L }/ / SiDwlify Out[179J= {x(t)w 2 +x"(t) ==2wOCos(e)y'(t), y(t)w 2 +2wOCos(e)x'(t) +y"(t) ==O} While Mathematica can actually solve this system of equations with DBol ve, the so- lution is long and complex, and not terribly useful in this format. We give the command below, but do not display the result. In [180J : = DSolve [eq4, {x, y}, t] ; (*Not Displayed*) We will find a better way to handle these equations in the following section. b. The solution is much simpler if we tteat the above equation of motion as a single complex equation. We take the second equation from eq4 and multiply this by I to form the imaginary equation (imEq): In [181J : = imEq = :r eq4 [[2]] / /'l'hread [I, Equal] Ii: Out[181J= i(y(t)w 2 +2wOCos(e)x'(t) +y"(t)) ==0 We take the first equation from eq4 for the real equation (reEq), In[182J:= reEq=eq4[[1]] Out[182J= x(t)w 2 +x" (t) == 2wOCos (e)y' (t) and combine the two into a single complex equation, eqS. In[183J:= eq5 = reEq+ imEq//Thread[l, Equal]Ii:// Siq>lify Out[183J= x(t)W 2 +x"(t) +i(y(t)w 2 +2woCos(e)x'(t) +y"(t)) == 2wOCos (e)y' (t) We inttoduce the complex variable u [t] =x [t] + I Y [t], and obtain a simplified complex equation: 
90 Chapter 2 General Physics In[184J:= eq6 = eq5/.DSo1ve[u[t] ==x[t] +Iy[t],x,t] [[ 1]] //SiD\plify Out [184J = u (t) w 2 + 2iwO Cos (e) u' (t) + un (t) == 0 If we assume the initial conditions {x[O] =0, x' [0] =0, y[O] =yO, y' [0] =O}, this is equivalent to In[185J:= initial = {u[O] ==1 yO,u'[O] ==O}; The solution for the equations of motion are given by DSol ve: In[186J:= dso1 = DSo1ve[Join[{eq6},initia1], {u[t]},t]// First Out[186J= {U(t) -7 1 2 -) _w 2 - W0 2 COS 2 (e) ( ( t ( .2iWOCOS(8).2 Y .W2.W02COS2(8) ) yO e wOCos (e)-  t ( 2 Y _w2 -w0 2 Cos 2 (8) -2:iwO Cos (8) ) e wOcos( . t ( -2:iWO Cos (8) .2 Y .w 2 .w0 2 Cos 2 (8) ) e) + 1e -) _w 2 - W0 2 COS 2 (e) + ie  t ( 2 y .w 2 .w0 2 Cos 2 (8) .2:iwO Cos (8) ) -) _w 2 - W0 2 COS 2 (e) ) ) } If we keep only the leading terms in wO we find: In[187J:= uSo1 = (u[t] /.dso1 / .wO-2 -+ 0 //powerExpand //EXpToTrig / /EXpandAll) 
2.3 Newtonian Mechanics in Rotating Frames 91 Out[187J= iYO Cos (tw - twO Cos (e) ) + 2 iyOwO Cos (e) Cos (tw - twO Cos (e) ) 2w 1, 21YO Cos (tw + twO Cos (e) )- iyOwO Cos (e) Cos (tw + twO Cos (e) ) 2w 1 . 2YO SJ.n(tw - twOCos (e))- yOwO Cos (e) Sin (tw - twO Cos (e) ) 2w yO Sin (tw + twO Cos (e) )- 2 yOwOCos (e) Sin(tw + twOCos (e)) 2w + + The real part of the equation is x [t] Out[188J= In[188J:= x=reSol=uSol/.{Complex[a_,b_] :-+a} -YOSin(tw - twOCos (e))- 2 yOwO Cos (e) Sin (tw - twO Cos (e) ) 2w 1 . 2YO SJ.n(tw + twOCos (e))- yOwOCos (e) Sin(tw + twOCos (e)) 2w + and the complex part is y [t] . In[189J:= y= imSol = (usol-reSol)/I//Simplify Out [189J = yO Cos (tw) Cos (twO Cos (e) ) + yOwOCos (e) Sin(tw) Sin(twOCos (e)) w Let's combine these solutions to describe the {x, y} ttajectory of the pendulum. In[190J:= point = {x,y}; Notice that the terms with the coefficient wOlw are comparatively small; if we make this simplifying assumption, the sttucture of this solution is apparent. . { IIIO }/ .. In[191J:= p01nt/. -;--+0 /PullS1q>l1fy// TableForm Out[191J= yOCos (tw) Sin(twOCos (e)) yOCos (tw) Cos (twOCos (e)) 
92 Chapter 2 General Physics In this simplified form of the solution, the physical aspects of the problem are apparent. First, we observe that both coordinates {x, y} oscillate with angular frequency w = ...; g/L , which is the well-known result for a simple pendulum. The plane of this pendulum oscil- lation rotates with an effective angular frequency weffective = wO cos(8). The plane rotates in the clockwise direction when viewed from above the Earth in the Northern Hemisphere (Cos[fJ]>O), and rotates in the counterclockwise direction when viewed from above the Earth in the Southern Hemisphere (Cos[8]<0). c. Let us examine graphically the precession of the pendulum for three angles: 8 = 0 (North Pole), 8 =  (Equator), 8 = 7T (South Pole). We choose the following arbittary parameters. In [192] := values = {III -+ sqrt[g/L], L-+ 1, g-+ 9.8, 1110 -+ 1/10, yO -+ 1}; We define the plot function: In[193]:= plot [Bin_, options_: 0] .- ParametricPlot[ point/ / .values/. {B -+ Bin} / /Evaluate, {t, 0, 10}, Ticks -+ False, PlotStyle -+ {options}, PlotRange -+ {{ -1, 1}, {-1, 1}}, AxesLabel -+ {"x-axis, south" , "y-axis, east n}] ; The plot function plots the motion of the pendulum bob in the {x, y} plane for colatitude 8. We display the precession at the North Pole (8=0), In[194]:= plot[O]; y-axis, east x-axis, south 
2.4 Electricity and Magnetism 93 the South Pole (e = 11), In[195]:= plot[]; y-axis, east x-axis, south and the equator (e=1T/2). In[196]:= plot[/2,Thickness[O.02]]; y-axis, east x-axis, south Note that the precession in the Northern Hemisphere is in a clockwise direction, and in the Southern Hemisphere the precession is in a counterclockwise direction; at the Equator . there is no precession. 2.4 . ELECTRICITY AND MAGNETISM 2.4.1 . Overview Electric forces arise between objects having an electric charge. Consider two point charges, ql and q2' in a vacuum separated by a distance r. The electtostatic force experienced by one charge due to the other is given by Coulomb's law, F = k(ql qlr-), where k is a constant with appropriate units. (In MKS units, k = (l/41TE O )') While this formula is similar to Newton's gravitational law, F = G(m l mlr-), an important difference is that Coulomb's law can be both atttactive and repulsive (as charges can be positive or negative) while Newton's gravitational law can only be atttactive (as masses can only be positive). If ql and q2 have the same sign, the two charges repel; if they have opposite signs, then they atttact. 
94 Chapter 2 General Physics A nonzero electric field, E, exists at any point where a test charge, if placed at that point, would experience an electrical force. The direction of the electric field is the same as the direction of the force experienced by a positivtest charge placed at the point. If a charge q is placed at a point where the electric field is E, the charge will experience a force .....Jo. .....Jo......Jo. .....Jo. .....Jo. F given by F = q E; hence, we can define the electric field via the relation E = F I q. In the simple case of a point charge q, the electric field has only a radial component and its magnitude is E = k(qlr-). The electtostatic force is conservative, and so can be represented by a potenti funcon, V = k(qlr). If we know the potential, we can find the electric field from it via E = - V V. We can also calculate the electric field with Gauss' law, which states (in integral form) <1>£ = J; E . "is = Qenclosed Y EO In words, this states that the electric flux, <1>£, defined by f E . "is, is proportional to the charge enclosed by the surface, Qenclosed' up to a proportionality constant (l/E O ) that varies with the particular units chosen. Gauss' law is particularly useful to calculate the electric field when there is a high degree of symmetty. The motion of a charged particle in an electric and magnetic field is described by the Lorentz force law: F=qE+q-;XB. Combining this with Newton's second law, F = m-;;, we obtain the equations of motion: m -;" = F = qE + q-; X B. In the case of magnetostatics, B can be derived from a vector potential A by the relation .....Jo. .....Jo. .....Jo. .....Jo. B = V X A. A sple example illustrating this relation is the computation of B from a vector potential A for a small current element. For an infinitesimal current segment of length (it)' carrying a current I located at (-;)', the infinitesimal magnetic vector potential -' -' dA at position r created by the current element is dl' dA = I -' . ,-; -r'1 Integrating along the current gives the total magnetic vector potential. We shall present an example of this later in the text. . PROBLEM 1 Charged Disk. A disk of radius R is uniformly charged with a constant surface charge given by density (T = (Q/1TR 2 ), where Q is the total charge. 
2.4 Electricity and Magnetism 95 R a. Find the potential and electric field along the axis of the disk. b. Take the limit Roo to get the field for a uniformly charged plane. Remarks and Outline This simple problem illusttates the use of the command Grad found in the package Calculus 'VectorAnalysis'. Solution In [197] : = Clear ["Global' * n] ; a. Consider an infinitesimal charged ring of thickness dr, charge dq, and radius r centered around the origin of the disk. The potential at position z along the z-axis produced by this ring is: dq In[198]:= dV=k ; '¥Z2 + r 2 The charge on the ring is related to the surface charge by In [199] := dq = 2:11" r dr u; where a- is the surface charge density. Recall, a- = q/ A, so da- = dq/ dA. Since A = 1Tr-, then dA = 21Trdr, then da- = dq/(21Trdr). Because the distance from the ring to the field point on the z-axis is the same for all points on the ring, the potential from the differential ring is dv dr 2knra vr 2 + z2 In[200] := Out[200]= To get the total potential on the axis of the disk, integrate dv/ dr from r= 0 to R: In[201]:= diskpotential = Integrate [ :; I {r I 0 I R} ] / / PowerExpand Out[201]= 2kn( -VR2+z2 -z)a Note, we use the PowerExpand command to reduce W to z. 
96 Chapter 2 General Physics The electric field on the axis is obtained from the gradient of the potential; the gradient command Grad is found in the package Calculus 'VectorAnalysis'. In[202]:= Needs[nCalculus'vectorAnalysis,n]; The electric field is then In [203] := Ed.isk = -Grad[diskPotential,Cartesian[x,y,z]] Out[203]= {o, 0, -2kTr(  -1) a} b. To get the electric field for a plane, let the radius of the disk go to infinity. Taking the limit of the z-component of the electric field, we get In[204]:= Eplane = Limit [Ed.isk, R-+oo] Out[204]= {0,0,2kTra} It follows from the symmetty of a plane that the electric field has only a z component. For those familiar with MKS units, we make the replacement k  (1/411"E O ) to obtain the familiar result: In[205]:= Eplane/. { k-+  } 4:11"6 0 Out[205]= {O, 0, } 2Eo . PROBLEM 2 Uniformly Charged Sphere. Consider a sphere of uniform charge den- sity and radius R. a. Find the electric field for r>R and r<R and plot the results. b. Find the potential for r>R and r<R and plot the results. c. Make a two-dimensional plot of the equipotential surfaces and the electric field on the same graph. d. Make a three-dimensional plot of the potential surfaces and electric field. 
2.4 Electricity and Magnetism 97 Remarks and Outline This problem illusttates the use of discontinuous functions. The electric field has only a radial component, and its value is obtained from Gauss's law. The potential is obtained from integrating the electric field. We illusttate how to combine different graphics with the Show command. Solution In [206] : = Clear [nG10ba1' * n] ; a. By symmetty, the only nonzero component of the electric field is the radial compo- nent. In this simple case, Gauss's law becomes E A = Q, where A is the surface area of the sphere, Q is the charge enclosed by the surface, and E is the radial component of the field. When Gauss's law is applied to a spherical surface of radius R, we get two equations depending on whether the field point r is less than or greater than R. In[207]:= eq1 = { 4071T 2 Eoutside == q'rota1 (*r > R*), 4071T 2 Einside == qEnc10sed(*r <R*)}; The notation (*... *) was used to embed a comment into the equation. The total charge and the enclosed charge are given by: 401!R 3 In[208]:= qTota1 = p; 4071T 3 qEnc10sed = p; where p is the volume charge density (QIV) of the sphere. Solving eql for the radial component of the electric field, we get In [209] := sol = Solve [eq1, {Einside, Eoutside}] II First { . R 3 P " r p } Out[209]= Eoutsde  3r 2 ,Ensde  :3 where Eoutside is the electric field for r>R and Einside is the electric field for r<R. The general radial electric field for all r is: In[210]:= eFie1d[rr., RR_ :1, pp. :1] .- :If [rr:s RR, Einside, Eoutside] I .sol/. {r.... rr, R....RR, p.... pp} Note we use the dummy variables rr, RR, and pp as arguments of the eField func- tion. The values of r, R, and p are then replaced by the input values of rr, RR, and pp, respectively. 
98 Chapter 2 General Physics The plot of the radial component of the electric field (for the default R=l and p = 1) follows from In[211]:= p1 = Plot [eField[r],{r,10- 6 ,3}]; 0.5 1 1.5 2 2.5 3 We can enhance the plot by adding a color region to distinguish the inside and outside of the sphere: In [212] := medium! = {Rue[O.2], POlygon[{{l, O.51}, {1, O}, {3, O}, {3,O.51}}]}; medium2 = {Rue[O.5], Polygon[{{O, O.51}, {O, O}, {1, O}, {1, O.51}}]}; Putting the plots together, we have In[213]:= Show[ {Graphics[{ medium1, medium2 , Text ["Inside", {O.5, O.4o}], Text ["Outside n , {2., O.4o}] }] , p1 }, AxesLahel .... {nDistance", "ElectricField"}, Axes.... True] ; Electric Field 0.5 0.4 0.3 0.2 0.1 Distance 
2.4 Electricity and Magnetism 99 Note that the plot pl is listed last so that it is shown on top of the shaded polygons. b. The potential is obtained from integrating the radial component of the electric field from infinity to r: V[r] = - IE. d1. For r>R, we get In [214] : = vOut [r., IL] = - Integrate [Eoutside/ .sol, {r, rD, r}] R 3 p Out[214]= 3r For the case r<R, the region of integration must be done in two parts. The first part re- quires an integration of Eoutside fromr ={ oo,R}. This term is given byVOUt [R,R]. The second term is an integration of Einside from r ={R, r}. The potential for r<Ris a combination of these two terms and it follows that V[r] = V[R] - J: E . d1. Therefore, In[215]:= vIn[r_, R_] = (vOut [R, R] - Integrate [Einside/ . sol, {r, R, r}]) //Simplify 1 2 2 Out[215]= -6 (r - 3R )p The potential for all r is In [216] := v[r., IL] := If[r <R,vIn[r, R], vOut [r, R]]; Here, use the If construction to define potential in a piecewise manner. The plot of the potential for p = 1 and R = 1 is In [217] : = p2 = Plot [v [r, 1] /.p.... 1, {r, 10- 6 ,3}] ; 0.5 0.3 0.4 0.2 0.5 1 1.5 2 2.5 3 Overlaying the plot with colored regions, you have 
100 Chapter 2 General Physics In[218]:= Show[{ Graphics[{ mediuml, medium2, Text [nInside n , {0.5, 0.3}], Text [nOutside", {2., 0.3}] }], p2 }, AxesLabel .... {nDistance n , npotentialField n }, Axes.... True ] ; Potential Field 0.5 0.4 0.3 0.2 0.1 C. We use ContourPlot and PlotGradientField to make a two-dimensional plot of the equipotential surfaces and the electric vector field. The potential in Cartesian coordinates is In [219] := vv[x_, y., z. : 0, R. : 1, pp_ :1] .- If [r < R, vIn[r, R] / /Evaluate, vOut [r,R]//Eva luate]/. {r- > " x 2 + y" + Z2, P .... pp} and we have replaced r=  y} + -I + i!-. An If statement has been used to choose between the inside and outside solution found in Part b. The default parameters are z=O, R=l, and p = 1. The graphics for the equipotential surfaces are given by vPlot: In [220] := vPlot = ContourPlot [vv[x, y], {x, -2, 2}, {y,-2,2}, plotPoints.... 30, ColorFunction .... Hue, ContourSmoothing.... True, Displa.yPunction.... Identity] ; The plot has been suppressed with the option DisplayFunctionIdentity. The graphics for the electric field are given by ePlot with the help of PlotGradi- entField, which is found in the package Graphics' PlotField ' . In[221]:= Needs["Graphics'PlotPield'"]; 
2.4 Electricity and Magnetism 101 In [222] : = eplot = PlotGradientl!'ield [- vv [x, y] , {x, -2,2}, {y, -2, 2}, ScaleFunction.... (1&:), DisplayI!'uDction.... Identity] ; Combining the electric field and equipotential surfaces, we get: In[223]:= Show[{vPlot,ePlot}, DisplayI!'uDction .... $DisplayI!'uDction] ; Of course, the colors are not visible in this black and white book. d. We can display the three-dimensional electric field using the command PlotGra- dientField3D, found in Graphics' PlotField3D'. In[224]:= Needs[nGraphics'Plotl!'ield3D'n]; In [225] := ePlot3D = plotGradientl!'ield3D[ -vv[x,y, z], {x, O,2}, {y, O,2}, {z, 0, 2}, VectorHeads .... True, Scalel'wlction.... (1&:), DisplayFunction.... Identity] ; . The equipotential surfaces are calculated in two steps. First, we define the radial position vector: In[226]:= point[r.,IL:l].- {rSin [8] Cos [Ip], rSin[8] Sin[Ip], rCos [8] } The equipotential surfaces are formed by rotating the position vectors to form spherical surfaces: 
102 Chapter 2 General Physics In [2271 := potPlot3D[r_] := ParametricPlot3D[ point[r]//Evaluate, {8,O,/2}, {II', 0, /2}, PlotPoints.... 12, DisplayFunction.... Identity] Set the equipotential surfaces at r equal to {o. 5, 1. 0, 1. 5, 2. O}. Displaying the superposition of the electric field and equipotential surfaces, we get: In[2281:= Show[ ePlot3D, Tahle[potPlot3D[r], {r, 1/2,2, 1/2}], PlotRange.... {O, 1}, DisplayFunction .... $DisplayFunction] ; . PROBLEM 3 Electric Dipole. Consider a dipole that consists of a positive and a nega- tive charge of equal magnitude separated by a distance d. -q +q d a. Find the potential, and plot the equipotentiallines in the y=O plane. Make a three- dimensional plot of the electric field. b. Express the potential in spherical coordinates and expand in powers of d/r, keeping only the leading order term. Calculate the electric field. c. Animate the static electric field of a rotating dipole. That is, consider a dipole which is rotating about the y-axis with angle e, and plot the electric field of this dipole in the {x, z} plane for a sequence of e. Remarks and Outline This problem illusttates the use of commands found in the packages Calculus 'VectorAnalysis', Graphics' PlotField', and Graph- 
2.4 Electricity and Magnetism 103 cs 'P1otField3D'. The electric field is computed from the potential using the relation E = -VV. Solution In[2291:= Clear[nGlobal' *n]; a. It is useful to define the potential for a monopole charge q located at the point {x, y, z}. Using the superposition principle we can build up complex multipole systems from this simple function. We define In [2301: = monopole [q_, pO. : {O, 0, O}, pL :{x,y,z}] := q '" (pO - p1) . (pO - p1) monopole gives the potential for a point charge q located at the point {x, y, z}. A dipole can then be formed by combining two monopoles: In[2311:= dipole = (monopole [-q, {O, 0, -d/2}] + monopole [+q, {O, 0, +d/2}]) Out[2311= q q  x2+y2+(_Z)2  x2+y2+(__z)2 The plot of the equipotentiallines in the plane y=O for q=l and d=l is In [2321 := ContourPlot [dipole/. {q -+ 1, d -+ 1, Y -+ O}/ / Evaluate, {x, -2, 2}, {z, -2, 2}, Plotpoints -+ 45, Contours -+ 21, ColorFunction -+ Rue, Axes -+ True, AxesLabel -+ {"x-axis n, n z-axis n}] ; z-axis x-axis 
104 Chapter 2 General Physics The plot of the electric field is given by the command PlotGradientField3D, found in the package Graphics' PlotField3D': In[233]:= Needs["Graphics'PlotField3D'"]; In[234] := plot = plotGradientField3D[ -dipole/. {q -+ 1, d -+ 1}/ /Evaluate, {x, -0.5, 0.5}, {y, -0.5, 0.5}, {z,-l.,1.}, Plotpoints -+ 6, ColorFunction -+ Rue, VectorHeads -+ True, ScaleFunction -+ (1&:), BoxRatios -+ {1, 1, 2) ] ; Note that ScaleFunction (1&:) is used to rescale the length of all vectors by the trivial function (1&:); i.e., they will all have length one. This is useful when you encounter singularities; otherwise, most of the vectors will appear to have zero length, except for those near the singularity. (The best way to understand what the ScaleFunction (1&:) command does is to reexecute the command without this option.) We can adjust the ViewPoint to tty and get a better look at this plot: In [235] := Show [plot, ViewPoint- > {O, 3, O}]; 
2.4 Electricity and Magnetism 105 141\\\ \\\JII 4'n b. To express the potential in spherical coordinates, we make use of the command Co- ordinatesToCartesian found in the package Calculus 'VectorAnalysis'. In[236J:= Needs[nCalculus'VectorAnalysis,n]; The CoordinatesToCartesian[point] command gives the Cartesian coordi- nates of point in the default coordinate system. Using this command we can make the handy replacement rule: In [237J := x2rRule = Thread [ {x, y, z} -+ coordinatesToCartesian [ {r, e, /II}, Spherical]] Out [237J = {x -+ rCos (cp) Sin (9) , Y -+ rSin(9) Sin(cp) , Z -+ rCos (9) } It follows from dipole that the potential in spherical coordinates is: In[238J := potential = dipole/ .x2rRule/ /Siqllify Out[238J= 2q ( yld 2 _ 4rco (9) d + 4r 2 - yld 2 + 4rco (9) d + 4r 2 J Expanding to lowest order in l/r, the potential becomes: In [239J := dipoleR = series [potential, {r, 00, 2}] / /Normal / / Siqllify dqCos (9) Out[239J= r 2 
106 Chapter 2 General Physics The electric field is determined by taking the negative of the gradient of the potential, -' -' E = -VV. In [240 J : = eField = - Grad [dipoleR, Spherical [r, 8, Ip] ] [2 _ { 2dQCOS(S) dqSin(S) } Out 40J- r 3 ' r 3 ,0 C. To animate a rotating dipole, locate the charges in the {x, z} plane and rotate the dipole around the y-axis. The expression for a dipole with unit charge and separation of one unit in the {x, z} plane as a function of () is In[241J:= rotDipole[8_] = (monopole [+1, 1/2 (+ Sin [8], 0, + Cos [8] }] + monopole [-1, 1/2{-Sin[8], 0, -Cos[8]}]); We use the Do command to generate a series of plots that Mathematica will then display in sequence to simulate the animation. We show the result here for only a single frame (to save space). In [242J := frames = 1; Do[ plotGradientField[ - rotDipole [8] /. {y -+ O}, {x, -2, 2}, {z, -2, 2}, Plotpoints -+ 14, VectorHeads -+ True, ScaleFunction -+ (1&:)] , {8,2/frames,2,2/frames}] ......."" \ \ \ I I I / / /_-- _.......,' "- \ \ t / / / /..-- __..," \ \ t I / /..--_ .--------.---, "- \ ! / / -------.......... //.---_--' \ I /.__..................... 1/ / //---- ........-............. '-..." \ illlill \\\\\\\ \\\\\\\1111/11 \,,'-........ ........:; X::///I .....................- 1\ ---.---// ........ -------/ / // "- ,-----.--- ____// I I j  \ ",.......___ ..--// / / / \ \ "- ".......- ..--/ / / II I \ \ \ " "....... You can display the animation in Mathematica's front end by selecting the graphics cells and using the "Animate Selected Graphics" command from the front-end menu. 
2.4 Electricity and Magnetism 107 . PROBLEM 4 Magnetic Vector Potential for a Long Straight Wire. Consider a long straight wire of length 2 L with a current io. -L ,  +L . 10 a. Determine the magnetic vector potential along a line perpendicular to the midpoint of the wire. Assume L is sufficiently large so that end effects can be neglected. b. Calculate the B field from B = V x A and take the limit as L goes to infinity. --" c. Plot the B field of the infinitely long wire in both two and three dimensions. --" d. Calculate the B field of an infinitely long wire in cylindrical coordinates. Remarks and Outline This problem illusttates the use of command Curl in both Cartesian and Cylindrical coordinates. The Curl command is found in the pack- age Calculus 'VectorAnalysis'. The vector potential is obtai!!ed from integrating over the length of the wire. The curl of the vector potential gives the B field. Solution In[243]:= Clear["Global' *"]; a. Choose the origin of the coordinates at the midpoint of the wire, and let the z-axis be along the direction of the wire. It follows from symmetty that the vector potential along the line perpendicular to the midpoint of the wire has only a z-component. The z-component of the vector potential is obtained at a distance r by integrating over the current running along the z-axis from -L to +L. That is, I L . 10 Az= _dz, -L V Z2 + ,2 or more precisely: In[244]:= Az [r_] = :Integrate [  , {z, -L, L}] Z2 + r 2 Out[244]= IO(LOg(L+ L2+r2 ) -LOg( L2+r2 -L)) 
108 Chapter 2 General Physics The magnetic vector potential A in Cartesian coordinates {x, y, z} is In[245J:= A[x_,y.,z_] ={O,o,Az[ -v'r+r ]} Out[245J= {o,o, IO ( Log (L + -/ L 2 + x 2 + y2) - Log ( -/ L 2 + x 2 + y2 - L) ) } b. The magnetic field follows from taking the Curl of the vector potential B = V xA . Curl is found in the package Calculus 'VectorAnalysis'. In[246J:= Needs["Calculus'VectorAnalysis'"]; B[x_, y_, z.] = Curl [A [x, y, z], Cartesian [x, y, z]] / / Siq>lify Out [246J = { - 2IOLy (x 2 +y2) -/ L2 +x2 +y2' 2IOLx } ,0 (x 2 +y2) -/ L2 +x2 +y2 The B field in the limit Loo becomes In[247J:= Ba>[x...,y_,z_] =Limit[B[x,y,z],L-+co] { 2IOy 2IOx } Out[247J= -,, 0 X +y X +y c. For a current of :1:0=1, the three-dimensional plot of the magnetic field is obtained with the command PlotVectorField3D, which is found in the package Graph- ics 'PlotField3D'. In[248J:= Needs["Graphics'PlotField3D'"]; In [249J := pi = PlotVectorField3D[ Bco[x,y, z]/.IO -+1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Plotpoints -+ 6, VectorHeads -+ True, ViewPoint -+ {1, 1, 3}, ColorFunction -+ Rue, ScaleFunction -+ (1&:), ViewPoint -+ {2, 2, 16} ] ; 
2.4 Electricity and Magnetism 109 The two-dimensional plot of the magnetic field in the {x, y} plane is obtained by tak- ing only the first two components of the Boo vector field (using the Part command, [ [{ 1,2}]]) and using the command PlotVectorField (found in the package Graphics' PlotField '): In[250}:= Needs[nGraphics'plotField,n]; plotVectorField[ Boo[x,y, z] [[{1, 2}]]/.IO -+ 1, {x, -3, 3}, {y, -3, 3}, Plotpoints -+ 20, VectorHeads -+ True, ColorFwlction -+ Rue, ScaleFwlction -+ (i&:) ] ; A'A - . - -- -    ,  /  ;.';. ,# -.,. ',........,. - .. .... ",. "'" "" "'" " " " )I ;. ..  /  ..-- "" _ ,. ..... ...., ....., " " '. '" jI ,/ ; .. /; ... .. A. "'* -- -- .... .. " \0" " '" \:  .... ..... \0, \0, \  \'      \ \ \ \ 4    " \. \. \, \, \. \ \- \.  ..  ..    .. }. .. f<   -' i. j ... 4 j ... .. .i d J j 1  .. i . 4 .4 J ,/,,;//.## , ,: ; , , ,;.' ,# 4 4  ,"I'P. ,,;,trl' r , " , t t /' ,. , , " t .. ' , , , /' ' , " , , , , , , , r ,,, t f r f , ,. 't 'f , , '1 , , , '{  .' " " "\  '"  w -# of " <4 . ,f  -if ". t' -I' 4 " I , , " '" ...  " , '  _ w   ,,/,1'4 , , , , " ... , '" too ...- y ff',.# JI" /" ¥ <1,-' " " " " "...... ... ... - - .... po ... " " ;#'  /" <I / ","...--------,,,<I "'" ....', ',', .... ... ','.... " " .... "'" .... .... . - - or' .... ... " ¥  #  
110 Chapter 2 General Physics d. The magnetic field in cylindrical coordinates follows from taking the Curl of the vector potential in Cylindrical coordinates. The vector potential expressed in cylin- drical coordinates {r, (), z} is obtained trivially from the {x, y, z} coordinate representation because this problem has only a z-component, which is the same in both Cartesian and Cylindrical coordinates. In[251J:= Acylind[r_] = {O, 0, Az[r]} Out [251J = {o, 0, IO ( Log (L + -VL 2 + r2 ) - Log ( -VL2 + r 2 - L) ) } Taking the Curl of Acylind in Cylindrical coordinates, and taking the limit as Loo, we get In [252J := Bcylind[r.] = Curl[Acylind[r],Cylindrical[r,e,z]]// Limit [I, L -+ 00] &: { 2 IO } Out[252J= O,,O As expected, Bcylind has only a () component. . PROBLEM 5 Motion of a Charged Particle in a Uniform B Field. Consider the mo- tion of a charged particle in a constant magnetic field. Combining Newton's second law,       F = ma, with the Lorentz force law, F = Eqv x B (assuming E = 0), the motion is described by the equation: -->. -->. -->. r"[t] =!!i r'[t] x B where B is the magnetic field. Assume that B is constant and is along the z-direction. a. Solve the equations of motion. Let the initial position be {x, y, z} = {O, 0, OJ. b. Graph the resulting ttajectory along with the magnetic field. Solution In [253J := Clear [nGlobal ' * n]; a. Define the acceleration, velocity, and magnetic vectors, In[254J:= acceleration = {x" [t], y" [t], z" [t]}; velocity = {x' [t], y' [t], z' [t] }; magneticField = {O, 0, B}; The equations for the components follow from 
2.4 Electricity and Magnetism 111 In [255] := eql = acceleration == q/mCross[velocity, magneticField] II Thread B ' ( t) B ' ( t) Out[255]={X"(t)== qym ,y"(t)== qxm ,Z"(t)==O} We will find it convenient to inttoduce w implicitly defined by the relation w=B q/m. In[256]:= eql=eql/.{B-+m/q "'} Out[256]= {x" (t) == wy' (t), y" (t) == -wx' (t), z" (t) == O} The initial conditions are: In [257] := initial = { x[O] == 0, x' [0] == vOx, y[O] == 0, y' [0] == vOy, z [0] == 0, z' [0] == vOz}; The solution for the variables is: In [258] := dsol = DSolve[Join[{eql,initial}], {x[t], y[t], z [t]}, t] I I Flatten I I FullSimplify { - Cos (tw)vOy + vOy + vOX Sin (tw) Out[258]= x(t) -> , w vOx(Cos(tw) -1) +vOySin(tw) } y(t) -> , z (t) -> tvOz w b. The ttajectory can be plotted using the command ParametricPlot3D. We arbi- ttarily choose the values In [259] := values = {B -+ m/q "', '" -+ 1, vOx -+ 1, vOy -+ 1, vOz -+ 1/10} ; Note, we take vOz to be relatively small compared to vOx and vOy (different values to see the effect of this parameter). The graphics for the ttajectory are given by In [260] : = plot 1 = parametricPlot3D [ {x[t], y[t], z [t], {Thickness [0 .02]}}/. dsol/.valuesllEvaluate, {t, 0, 87r}, Plotpoints -+ 100]; 
112 Chapter 2 General Physics This ttajectory can be combined with the magnetic field using the command PlotVec- torField3D found in the package Graphics' PlotField3D'. Note the magnetic field is a constant in the z-direction, so we plot the vector field {O, 0, I} to represent this. In[261]:= Needs[RGraphics'plotField3D'"] plot2 = PlotVectorField3D [ {O, 0, l}//Evaluate, {x, -2, 2}, {y, -2, 2}, {z, 0, 2}, VectorHeads -+ True, Plotpoints -+ 4 ] ; Combining the graphics, we have: In[262]:= Show[plotl,plot2]; 
2.4 Electricity and Magnetism 113 2 . PROBLEM 6 Motion of a Charged Particle in a Uniform B Field and Time Varying f Field. Consider the motion of a charged particle in a uniform magnetic field with a time --" --" varying electric field. Combining Newton's second law, F = ma, with the Lorentz force law, F = q E + q -; x B, the motion is described by the equation m -;" = qE + q -;, x B Take the electric field to be in the x-direction with time dependence of the form Ex = EoCos[wt], where w is the applied frequency. Take the magnetic field to be constant and in the z-direction. Solve the equations of motion for a particle that starts from rest and is located at the origin. Plot the results for different values of the parameters {w, E, B}. Solution In [263] := Clear [nGlobal ' * n]; We define force vector F, the position vector -;, the velocity -;, the electric field EF, and --" the magnetic field BF: In[264]:= F = {h, Fy, Fz}; r= {x[t],y[t], z[t]}; EF = {Ex, By, EZ}; BF = {Bx, By, BZ}; v=D[r,t] Out[264]= {x' (t), y' (t), z' (t)} The force on a charged particle in an electtomagnetic field is 
114 Chapter 2 General Physics In[265J:= F=q EF+q CrOSS[v,BF] Out[265J= {Exq+ (Bzy'(t) -Byz'(t))q,Eyq+ (Bxz'(t) -Bzx'(t))q, Ezq + (Byx' (t) - Bxy' (t)) q} and from Newton's second law, F = m a, the nonrelativistic equations of motion are: In [266J := eql = F-m D[r, {t, 2}] == OIIThread; eql IIColumnForm Out [266J= Exq + (Bzy' (t) - Byz' (t) ) q - rnx" (t) == 0 Eyq + (Bxz' (t) - Bzx' (t)) q - my" (t) == 0 Ezq + (Byx' (t) - Bxy' (t) ) q - mz" (t) == 0 The initial conditions are: In [267J := initial = { x[O] == 0, x' [0] == 0, y[O] == 0, y' [0] == 0, z[O] ==O,z'[O] ==O}; For our particular case, the components of the fields are: In [268J := fields = Thread/@{BF-+ {O, O,m 1II0Iq}, EF-+ {EOCos[1II t], 0, O}}IIFlatten { mwO Out[268J= BX->O,BY->O,BZ->q' Ex -> EO Cos (tw) , Ey -> 0, Ez -> 0 } where we have replaced B with (m wO / q) for convenience. We combine all the equations and initial conditions into a single equation list: In [269J := eqs = Join [eql, initial] I. fields Out [269J= {EOqCos (tw) + mwOy' (t) - rnx" (t) == 0, -mwOx'(t) -my"(t) ==O,-mz"(t) ==O,x(O) ==0, x' (0) == 0, y(O) == 0, y' (0) == 0, z (0) == 0, z' (0) == O} The path of the charged particle is given by: In[270J:= dsol = DSolve [eqs, {x[t], Y [t], z [t] }, t] I I FlattenllFullSimplify { EOq(Cos (twO) - Cos (tw)) Out[270J= x(t) -> 2 2 ' m (w - wO ) EOqwOSin(tw) -EOqwSin(twO) ( ) } y(t)-> 3 2 ,zt->O mw - mwwO 
2.4 Electricity and Magnetism 115 Let us plot the orbits for several different choices of w. We take an arbittary choice for the parameters: In[271J:= values = {m-+l,EO-+l,IIIO-+l,q-+l}; We can define the point of the ttajectory in {x, y, z} coordinates as follows: In[272J:= point [t_, 111_] = {x[t], y[t], z [t]}/ .dsol/ . values { COS(t) -Cos(tw) Sin(tw) -wSin(t) } Ou t [272 J = w2 _ 1 ' w3 _ W ' 0 There are two special cases to consider: w = 0 and w=wO. We must use the Limi there to avoid an :Indeterminate expression. In [2 73 J : = point [t., 1] = LiJDit [point [t, III] , III -+ 1] { 1. 1 . } Out[273J= 2tsm(t}, 2(tcoS(t) -SJ.n(t)), 0 In[274J:= point [t_, 0] = Limit [point [t, 111],111-+ 0] Out[274J= {l-Cos(t),sin(t) -t,O} Since Mathematica applies specific rules before general rules, these last two definitions for point will override the general case above-this ensures that we do not encounter any singularities when w  {O, I}. We are now ready to define the plot function. In [275J := plot [111_] := ParametricPlot[ point [t, III] [[{l, 2}]] / /Evaluate, {t, 0, 207\"}, PlotLabel-+ III, 'ricks -+ None, DisplayFunction -+ Identity] ; Note, we select the first and second elements of point as we are making two- dimensional plots in the {x, y} plane. We can now generate a table of plots In [276J : = table = 'rable [plot [III], {III, 0,4, 1/3}] ; and display the orbits. In[277J:= Show [GraphicsArray [Partition [table, 3]]]; 
116 Chapter 2 General Physics . 113 213 ffi @ 1 413 513   2 EB 713 813 *  3 8 1013 UI3 . . . 2.5 . MODERN PHYSICS . PROBLEM 1 Carbon Dating. The decay rate of radioactivity is n[t] = noe- at , where a = 1fT is the decay constant related to the half-life by 1 log[2] a = - = -. T Tl/ 2 The half-life of radioactive carbon-14 e 4 C) is Tl/ 2 = 5750 years. If measurements show the fraction of radioactive carbon left in a fossil is (n[tVno) = {0.1, 0.2, ..., I}, then how old is the fossil? Display the result as both a table and a graph. Solution In[278]:= Clear [oG10ba1' * 0]; The decay rate for 14C is n[t] = nOe- at . In [279] := n[t.] = nO Exp[-at] Out[279]= e.atnO We can relate a to the half-life T1/2 = 5750 years by noting that when the time t = T 1/2 = 5750 years, the concenttation will be half the original concenttation. In[280]:= eq1 = 1/2 n[O] == n[5750] Out[280]= nO == e.5750anO 2 We then find the solution for a: In[281]:= a801 = 801ve[eql, a] II Flatten { Log ( 2) } Out[281]= a- 5750 
2.5 Modern Physics 117 and substitute this back into the original equation: In[282J:= n[t_] =n[t]/.aSo1 Out[282J= 2-t/5750nO As we are more interested in the relative concenttation of 14C, we eliminate nO=n [0] and nl=n [t] in favor of ratio=nl/nO: In [283J := eq2 = Eliminate [{n1 == n[t], ratio == n1/nO}, nO] Out[283J= ratio == 2.t/5750 Thus, knowing the ratio, we can find the age of the sample. In [284J := ageRu1e = Solve [eq2, t] //First { 5750Log(ratio) } Out[284J= t....- Log(2) In[285J:= tiJne[ratio.] =t/.ageRu1e 5750Log(ratio) Out[285J= Log(2) To compute a table of ages for the fraction ratio, we compute: In [286J : = data = Tab1e[{ratio,time[ratio]}, {ratio, 0, 1, 1/10}]//N; and then display the results with TableForm. In[287J:= Tab1eForm[data, Tab1eHeadings- > {{}, {RFractioDLeftR, RAge (yrs) R}}, Tab1eAligmnents -+ {Right, Bottom} ] / /PaddedForm [I, {6, 1}] &: Out[287J= FractionLeft 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 Age (yrs) 00 19101.1 13351.1 9987.6 7601.1 5750.0 4237.6 2958.8 1851.1 874.0 0.0 We use the option TableAl ignments together with paddedForm to align the num- ber for easy reading.  
118 Chapter 2 General Physics Next, we graph the output. It will be convenient to work in units of the half-life, to=5750 years; note how we adjust the Ticks and the GridLines to units of the half-life. In[288]:= to = 5750; Plot[n[t] InO, {t, 0, 5tO}, AspectRatio -+ 1, Background -+ Hue [0 .2,0.5,1], Ticks -+ {Range [0, 5tO, to], Table [1/2-i, {i, 0, 3}]}, AxesLabel -+ {RAge (yrs) n, Rratio = n1/nO R }, PlotStyle -+ {Thickness [0.02], Hue [0.9] }, GridLines -+ {Range [0, 5tO, to] , Table [1/2-i, {i, 0, 5}]} ] ; . PROBLEM 2 Stable Isotopes. We will demonstrate the properties of a standard add-on package, Miscellaneous' ChemicalElements '. a. Make a plot of the stable isotopes in {proton, neutton} space. Let the horizontal axis be the proton number and the vertical axis be the neutton number. b. Show the odd-even effect by counting the number of stable nuclei with even protons-even neuttons, even protons-odd neuttons, odd protons-even neuttons, odd protons-odd neuttons. 
2.5 Modern Physics 119 Solution In [289] := Clear [nGlobal ' * n]; a. This problem needs the information found in the add-on package Miscella- neous 'ChemicalElements ' . In[290]:= Needs[nMiscellaneous'ChemicalElements,n] Mercury :: shdw: Symbol Mercury appears in multiple contexts {Miscellaneous'ChemicalElements' , Global'}, definitions in context Miscellaneous'ChemicalElements' may shadow or be shadowed by other definitions. Since we defiried the variable Mercury previously in the Keplerian Orbits prob- lem in Section 2.2, our definition shadows that defined in the package Miscella- neous 'ChemicalElements '. The solution is to Remove the global variable Mer- cury as follows: In[291]:= Remove[Global'Mercury] The commands defined by this package can be displayed with In[292]:= ?Miscellaneous'ChemicalElements'* (*OUtput not ShOWD*) We've not shown the output, to save space. We now demonstrate some of the commands in the package; for example, the element with atomic number 26 (and its standard abbrevi- ation) is given by: In[293]:= {Elements[[26]], ElementAbbreviations[[26]]} Out[293]= {Iron,Fe} and its stable isotopes are In[294]:= StableIsotopes[Fe] Out[294]= {54, 56, 57, 58} Mathematica knows about 112 elements: In[295]:= Length[Elements] Out[295]= 112 The number of neuttons in each isotope of Iron (Fe) is 
120 Chapter 2 General Physics In [296J : = Stable:Isotopes [Fe] - 26 Out[296J= {28,30,31,32} and the number of protons is trivially: In [297J := Stable:Isotopes[Fe] * 0 + 26 Out[297J= {26, 26, 26, 26} We can automate this procedure as follows: In[298J:= neutrons[n_]:= Stable:Isotopes[ ElementAhbreviations [ [n] ]] - n protons [n_] : = Stable:Isotopes[ElementAbbreviations[[ n] ]] * 0 + n (note the trick of multiplying by zero just to get an array of proper length for the protons) and define the function pairs In [299J := pairs[JL] := Transpose[{protons[n],neutrons[n]}] pairs[26] Out[299J= 26 26 26 26 28 30 31 32 Let us plot the isotopes in {proton, neutton} space: In[300J:= ListPlot[pairs[26]//Evaluate, PlotStyle -+ PointSize [0.03], AxesLabel-+ {Rproton R , Rneutron R }, PlotLabel -+ R:Iron(Fe) R ] ; neutron 32 Iron (Fe) . 31 . 30 . 29 10 20 30 40 50 proton 
2.5 Modern Physics 121 We can easily do the same for all the elements. The array data contains all stable pairs {protons, neuttons}. In[301]:= data" Table[pairs[i], {i,Length[Elements]}]// Flatten[#,l]&:; The plot in {proton, neutton} space is: In[302]:= plotl"ListPlot[data, PlotStyle -+ PointSize [0.015] , AxesLabel -+ {Dproton D, Dneutron D }, PlotLabel -+ DAllElements D , AspectRatio -+ 1, DisplayFUnction -+ $DisplayFunction, Epilog-+Line[{{O, O}, {lOO,lOO}}] ] ; neutron All Elements 80 60 80 proton 120 100 The solid line is the (neutton-number = proton-number) line. The Coulomb repulsion makes it more favorable for the nuclei to have more neuttons than protons. Magnifying the middle of the graph, we get a more detailed view: In[303]:= Show[plotl, PlotRaDge -+ {{20, 30}, {20, 40}}]; 
122 Chapter 2 General Physics neutron 40 All Elements 37.5 35 32.5 30 22 24 26 28 30proton 27.5 25 22.5 b. The collection of all stable data pairs {protons, neuttons} are stored in the array data. We start by computing the number of isotopes with an odd number of both protons and neuttons. We use the Select function to exttact the pairs with the given criteria. The actual pairs are shown here: In[304]:= Se1ect[data, (OddQ[#[ [1]] ]&:&:OddQ[#[ [2]] ])&:] 1 1 [ 3  3  ] Out[304]= 57 81 odd protons-odd neutrons: If we are only interested in the count, we can exttact this information with the Length command: In[305]:= Se1ect[data, (OddQ [# [[1]] ]&:&:OddQ [#[ [2]]]) &:] / / Length Out[305]= 5 even protons-even neutrons: The case of even protons-even neuttons is nearly identical: In[306]:= Se1ect[data, (EvenQ [# [ [1] ]] &:&: EvenQ [# [[2]] ]) &:] / / Length Out[306]= 154 odd protons-even neutrons: For the next two cases, we use a different command syntax just for variety; the preceding commands will work just as well. 
2.5 Modern Physics 123 In[307]:= Length[ Cases [data, {:IL, y_} I; OddQ [y] i:i:EvenQ [x]]] Out[307]= 53 even protons-odd neutrons: In[308]:= Length[ Cases [data, {:IL, y _}/; Even.Q [y] i:i: OddQ [x] ] ] Out[308]= 49 Obviously the even-even nuclei are the most abundant, and the odd-odd nuclei are quite rare. . PROBLEM 3 The Bohr Atom. The Bohr theory of the hydrogen atom is a mixture of classical physics and the energy-quantization ideas inttoduced by Planck. The Bohr theory is based on the following three postulates. a. An electton in an atom can move about the nucleus in stable circular orbits without radiating. These are called the discrete stationary states of the atom. b. The allowed stationary states are those for which the angular momentum is quan- tized: 1 = mvr = nli. c. Whenever an electtonjumps from an initial (higher) energy orbit e i to a final (lower) energy orbit e f' a photon of energy hv is emitted such that hv = e i - e f' Consider an electton that is bound to the nucleus with an atttactive force of the form: k(Ze 2 fr-), where e is the elementary unit of charge, r is the distance between the nucleus and the electton, Z is the charge of the nucleus in units of e (i.e., the number of protons), and k is the Couloumb constant (equal to If41TE o in MKS units). Let us assume that the (very heavy) nucleus remains at rest and the electton revolves around the nucleus in a circular orbit. a. Using Bohr's method of quantization, derive the equation for the energy levels in terms of n, where n is the n'th Bohr orbit. Make a plot of the energy levels. b. Derive the frequency of the radiation, w, associated with a ttansition from the Bohr energy level of n i to n f . Remarks and Outline One equation for the parameters is given by equating the centrifu- gal force with the Coulomb force; a second equation comes from the Bohr quantization rule. Solving these two equations gives the quantized expressions for v and r. The energy is the sum of the potential and kinetic energies. 
124 Chapter 2 General Physics Solution In[3091:= Clear [ftGlobal ' * n]; a. We start by using Newton's second law, F = ma, where F is given by the Coulomb force, and the centtepital acceleration a = v 2 /r. Z e 2 In[3101:= coulomb = k; r force = m a; v 2 a= r; eql = coulomb = = force e 2 kZ mv 2 Out[3101=  == -;;- The angular momentum is I = r X p = mvr. In [ 3111 : = angularMomentum = m v r; Quantizing the angular momentum in units of Ii = h/(21f), we have In[3121:= eq:ll = angularMomentum == n Ii Out[3121= mrv == nh where n is a positive integer, n= { 1 , 2 , 3 , ... }. An equation for {v, r} follows from solving the algebraic equations eql and eq2: In[3131:= rulel = Solve [{eql, eq:ll}, {v, r}]//First { n2!J2 e 2 kZ } Out[3131= r->-y-,v->- e krnZ nh The total energy of the nth orbit is the sum of the kinetic and potential energies: In[3141:= kineticEnergy = !m ; :II Z e 2 potentialEnergy = -k-; r totalEnergy = kineticEnergy + potentialEnergy mv 2 e 2 kZ Out[3141= 2 -  Expressing the energy in terms of n, we find In[3151:= energy[n_] =totalEnergy/.rulel//Simplify e 4 k 2 mZ 2 Out[3151= - 2 2 2n !J 
2.5 Modern Physics 125 To make a plot of the energy, we choose the specific values for the constants that can be found in the add-on package Miscellaneous' PhysicalConstants " In[316J:= Needs[RMiscellaneous'PhysicalConstants'R]; In [317J : = values = { e -+ ElectronCharge, m -+ ElectroDMass, k -+ 11 (4:11"eO), eO -+ vacuumPermittivity, Ii -+ PlanckConstantReduced, Z -+ l}; We will define a function that gives the energy in units of electton volts with the help of the Miscellaneous 'units' package: In[318J:= Needs[RMiscellaneous'units'R]; We now define the function In [319J:= energyEV[JL] : = Convert [energy[n] I I .values, ElectronVolt]; Let us check to see if energyEV gives the expected ionization energy for hydrogen: In[320J:= energyEV[1]IINwmberForm[#,3]& Out[320J= -13.6ElectronVolt Pictorially, the energy values of the hydrogen atom in units of electton volts are In [321J := Plot [ Table [ energyI!:V[n] , {n, 10} ] II ElectronVolt Evaluate, {x,O,l}, plotRange -+ All, AxeS -+ {False, True} ] ; o -2 -4 -6 -8 -10 -12 This shows the energy levels in a simple, graphical way. The full quantum wave func- tions for the hydrogen atom are obtained later in the text in Chapter 9. 
126 Chapter 2 General Physics b. The angular frequency, w, of the radiation associated with the ttansition from orbit n; to n j follows from Bohr's postulate, liw = !!.E In [322] := eq3 = Ii w == energy[n i ] - energy [n f ] e 4 k 2 mZ 2 e 4 k 2 mZ 2 Out[322]= wh == 2 2 - 2h n f 2h 2 nf This is trivial to solve for the angular frequency, w. In [323] := Solve [eq3, w] / /First / /Simplify e 4 k 2 mZ 2 (nf -n) Out[323]= {w -> 3 2 2 } 2h nfn i . PROBLEM 4 Relativistic Collision. A particle at rest with mass m 2 is hit by a second relativistic particle with mass m l and speed f31' For convenience, we will express our ve- locities relative the the speed of light, c, so we have f3 = vie. Upon collision, m l and m 2 coalesce into one particle with rest mass m 3 moving with speed f3 3 relative to the observer. Show that m 3 and f3 3 for the composite particle are given by m 3 =  mi + m + 2m l m 2 YI and f3 3 = m l f31 YI m 2 + mlYI where 1 YI =  1 - f3i and f3 - VI 1- C' Remarks and Outline This problem illusttates the use of four-vectors and tensors. The results follow from the conservation of four-momentum and the relation YI = (1/  1 - f3i ). Solution In[324]:= Clear[nGlobal' *0]; The four-momentum for the initial particles are In[325]:= pl=ml yl{l,O,O,/31}; p2 = m2{l, 0, 0, OJ; The momenta is written in four-vector notation: pP = Ie, PX' Py' pz}. The energy of par- ticle with rest mass ml is El=ml yl, and the three-momentum of ml is in the z-direction with magnitude pz l=ml yl f3l. The four-momentum of the final particle is In [326] := p3 =m3 y3{l, 0,0, /33}; 
2.6 Exercises 127 C . ff . th . J1 J1 J1 onservatIon 0 our-momentum gIVes e equatIon PI + p2 = P3: In [327J := eq1 = p1 + p2 == p3/ /Thread Out [327J = {m2 + m1)'1 == m3)'3, True, True, m1/31)'1 == m3/33)'3} We get two nontrivial equations from the conserved four-momentum; two more equa- tions follow from the relation between y and f3: { 2 1 2 1 } In[328J:= eq2 = y3 == ,Y1 ==  ; 1 - /33 1 - /31 The solution for f33 and m3 easily follows from these four equations In [329 J : = eq3 = Join [{eq1, eq2}] / /F1atten Out [329J = {m2 + m1)'1 == m3)'3, True, True, m1/31)'1 == m3/33)'3, )'3 2 ==, )'1 2 ==  } 1 - /33 1 - /31 and we find for f33 and m3, after eliminating y3, In[330J:= sol = Solve [eq3, {/33, m3}, {y3}] [[2]] / / SimplifY { I m1/31)'1 } Out [330J = m3 -> \fm1 2 + 2m2)'lm1 + m2 2 , /33 -> m2 + m1 )'1 We take the second solution (with the notation [[2]]) to obtain a positive solution for m3. . 2.6 . EXERCISES 2.1 Exploding Projectiles A projectile is launched at v=20 mls at an angle of 8=30 degrees with the horizontal. In the course of its flight it explodes, breaking into two fragments, one of which has twice the mass of the other. The two fragments land simultaneously. The lighter one lands x=20m from the launch point in the direction the projectile was fired. (Note, you are not given the time the projectile explodes; while this does affect the specific trajectory, it does not affect the final landing point. You may wish to verify this for a variety of explosion times.) (a) Where does the other fragment land? (b) Plot the motion of the two fragments and the motion of the center of mass point for a variety of explosion times. (c) Make a function that will plot the motion of the two fragments and the motion of the center of mass when the initial velocity, mass of fragments, and position of one of the fragments is given. 
128 Chapter 2 General Physics 2.2 Intersecting Trajectories (Shoot the Monkey) A hunter with a gun wishes to shoot a monkey hanging from a branch. The hunter aims right at the monkey and fires the dart. At the instant the monkey sees the flash of the hunter firing the gun, the monkey lets go of the branch and drops to the ground. (a) Show that the monkey will be hit regardless of the angle of the dart to the monkey and the dart's initial velocity, so long as it is great enough to travel the horizontal distance to the tree before the dart hits the ground. (b) Plot the points for the positions of the dart and monkey when those positions are separated by equal time intervals. Choose the time intervals so the last point is the intersection of the dart and monkey. (c) Display the plot for several different initial values of the dart and for several different heights of the monkey. 2.3 Principle of GaIDean Invariance Two balls are released simultaneously from a platfonn above the Earth's surface. One is merely dropped from rest, while the other is launched with an initial horizontal velocity vO. Graph the stroboscopic images of the two balls at successive instants of time and show that they fall downward in unison, reaching equal heights at the same time. Consider several different values ofvO. 2.4 Elastic Collision A ball moving with nonrelativistic velocity V o makes an off-center, perfectly elastic collision with another ball of equal mass initially at rest. The incoming ball is deflected at an angle 8 1 from its original direction of motion. (a) Find the velocities and trajectories of the balls after the collision. (b) Plot the trajectories and center of mass point for different V o and for different 8 1 . 2.5 Projectile and Earth's Rotation If a projectile is fired due east from a point on the Earth's surface at a northern latitude A, with a velocity of magnitude vo' and at an angle of inclination to the horizontal of a, show that the lateral deflection d when the projectile strikes the Earth is d = 4Vow sin[A] cs[a] sin[a]2 g where w is the rotation speed of the Earth, and g is the gravitational acceleration of 9.8m1s 2 . If the range of the projectile is R for the case w = 0, show that the change of range due to the rotation of the Earth is M = )2:3 W COS[A]( -v'cot[a] _  tan[a]312). 2.6 Projectile Thrown up an Incline Plane An inclined plane makes an angle a with the horizontal. A projectile is launched from the bottom of the incline with speed V o in a direction making an angle f3 with the horizontal. Find the distance where the projectile hits the incline. What angle achieves the maximum distance? 2.7 Falling Object with Air Resistance as Observed from the Rotating Earth An object of mass m, initially at rest, is dropped from height h to the Earth's surface at colatitude 8. Let W be the rotational speed of the Earth. The particle is acted on by a constant pull of gravity 
2.6 Exercises 129 with acceleration g, and by air resistance. The force of the air drag is assumed to be proportional to the speed, v. Find the deflection after time t, neglecting tenns of order u} and higher. 2.8 Projectile Thrown up with Air Resistance A particle of mass m is acted on by a constant pull of gravity with acceleration g and air resistance. The particle is thrown vertically upward with speed vo' The force of the air drag is assumed to be proportional to the speed. Find the maximum height and the time taken to reach this maximum height. 2.9 Quadrupole Consider three charges located on the z-axis. One negative charge of magnitude q, is located at position +s; the other, of the same magnitude, is at position -so A positive charge of magnitude 2q is located at the origin. The field point is at -;, and it is assumed that the separation s of the charges is small compared to the distance r. (a) Find the potential and electric field to leading order in powers of sir. (b) Plot the equipotential surfaces and the electric field lines. 2.10 Motion of a Charged Particle A particle of electric charge q, and mass m moves with velocity v in an electric and magnetic field having electric intensity E and magnetic intensity B. Suppose that B and E are constant and in the directions of the negative y and positive z axis, respectively. Prove that if the particle starts from rest at the origin then it will describe a cycloid in the {x,z} plane. The equation of a cycloid is x = b(O - Sin[O]), z = b(1 - Cos[O]), where 0 = qBtlm, b = mEI(qB 2 ), and t is the time. 2.11 B Field of a Spinning Disk A thin disk of charge density  radius R, and thickness t < R rotates with an angular velocity w about the z-axis. Find the B field on the axis of the uniformly rotating disk and plot the results. 
CHAPTER 3 130 Oscillating Systems 3.1 . INTRODUCTION Vibrations or oscillations of mechanical and electrical systems constitute one of the most important fields of study in all physics. Patterns of movement that repeat over and over again are common in celestial mechanics, mechanical systems, quantum mechanics, and electtodynamics. VIrtually every system possesses the ability to vibrate; a mosquito's wings, for example, vibrate hundreds of times per second and the Earth, after being jolted by an earthquake, vibrates at the rate of about one oscillation per hour. The feature that all such phenomena have in common is periodicity, a pattern of movement or displacement that repeats itself over and over again. In this chapter we study a number of aspects of periodic motions in linear systems. The equations describing oscillating systems are usually complicated. In many cases, they can be analyzed with potential or phase space diagrams. Potential diagrams can be used to analyze the oscillatory motion and to find positions of equilibrium. The system is in equilibrium when the net force acting on it vanishes. If the system is initially at the equilibrium position with zero initial velocity, then the system will remain in equilibrium indefinitely. The equilibrium is stable if a small disturbance of the system from equilibrium results in only small bounded motion about the rest position. The equilibrium is unstable if an infinitesimal disturbance eventually produces unbounded motion. The potential has an exttemum at both of these equilibrium positions. When the exttemum of the potential is a minimum, the equilibrium is stable; when it is a maximum, the equilibrium is unstable. In some cases, it is advantageous to study the motion in terms of its phase plane. For example, consider a system having one degree of freedom that is described by a differential equation of the form, x"[t] + f[x[t], x'[t]] = 0 If you define v[t] = x'[t], then this equation can be expressed as two first-order- equations: v'[t] = -f[x[t], v[t]] and x'[t] = v[t] The {x[t], v[t]} plane is called the phase plane, and the changing state of the system makes a curve in the phase plane called a trajectory. The ttajectory displays the depen- dence between the position and velocity. Equilibrium occurs when the velocity v and force f[x, v] are simultaneously equal to zero and correspond to points in the phase plane where f[x, v] = 0 and v = O. 
3.2 Linear Oscillations 131 The methods used to obtain the solutions in this chapter are not unique; you are encour- aged either to change the Mathematica commands and find procedures that will further illuminate the physics, or to find other commands that will make the calculations faster. The speed of the calculation can be obtained from the command Timing. There are three sections on problems: Linear Oscillations, Small Oscillations, and Oscillating Circuits. At the beginning of each problem section we include an overview of the topic and may include several user-defined functions. This chapter concludes with a section on Exercises. Before starting this chapter you might want to turn off the spell checker: In [lJ : = Off [General: : nspell n ]; Off [General:: nspelll n ]; 3.2 . LINEAR OSCilLATIONS 3.2.1 . Overview Our attention in this section is directed toward linear systems. The physical reason is that linear systems arise in a variety of mechanical systems. They are due to restoring forces that are proportional to the displacement from equilibrium. Such motion is almost always possible if the displacements are sufficiently small. A physical model is a simple harmonic oscillator, where a mass is connected to some elastic object of negligible mass fixed at the other end and consttained so that it may only move in one dimension. The importance of this problem is that equations of a similar form arise when a particle moves through any region whose potential has a local minimum. Similar equations also arise in the study of LCR circuits. The letters L, C, and R refer to the symbols used to identify the electrical in- ductance, capacitance, and resistance, respectively. In many systems it is only approximate but perhaps a close analogy to the ttue motion. A more realistic physical model is one that includes dissipative forces: the damped harmonic oscillator, where the dissipative force is directly proportional to the velocity of the mass and in the opposite direction. This produces another differential equation with an exact solution. We now have an equation that yields different behaviors for different parameter values. Another common mechanical problem arises when a damped harmonic oscillator is driven by some time-dependent external force: the driven harmonic oscillator. The most important case is that of a force that oscillates in a sinusoidal manner. This differential equation also has an exact solution. Much of the discussion in this section will probably be familiar ground, but it is important to be quite certain of it before proceeding to nonlinear systems. It is useful to create user-defined procedures for those calculations that are used re- peatedly in the section. It is not necessary to understand the details of these user-defined procedures until you have done all the problems; then you can go back and examine the procedures. To understand them in detail, go through the steps one at a time. Try to make the procedures more time efficient, add default conditions, and add options to the proce- dures. They can be downloaded on the author's website. The three procedures used several times in this section are phasePlot, timePhaseplot, and doublePlot: 
132 Chapter 3 Oscillating Systems 3.2.2 . Initialization of User-Defined Functions 3.2.2.1 . phasePlot for One-Dimensional System The procedure phaseplot [q , p , tList , opts ] plots the phase trajectory { q,p } where tList gives the starting and stopping times and is of the form {t, tMin, tMax}. The variable opts allows you to include options for Parametric Plot. This routine is simply a specialized use of ParametricPlot; however, you will often find it useful for oscillating systems: In [2J : = phaseplot [q_, p_, tList_List, opts___] : = parametricPlot [ {p, q} II Evaluate, tList, opts, PlotRange -+ All, PlotStyle- > {Hue[Random[]],Thickness[O.Ol]}, Axes -+ False, PlotLabel-+ nphase Trajectoryn, Frame -+ True, FrameLabel -+ {npn, nqn} ] To see how to apply the procedure, consider the harmonic functions q[t] = Sin[2 nt] andp[t] = q' [t]. The phase diagram is In[3J:= phasePlot[Sin[2  t],D[Sin[2  t],t], {t, 0,3}, GridLines -+ Automatic] ; 1 0.5 tJ' 0 -0.5 -1 -6 -4 -2 0 2 p Phase Trajectory 4 6 3.2.2.2 . timePhasePlot: Time Behavior of Phase Plot for a One-Dimensional System The procedure timephaseplot [q, p, tList, opts] plots the time evolution of the phase ttajectory where tList gives the starting and stopping times and is of the form {t,tMin,tMax}. This routine is simply a specialized application of parametric- Plot 3D; however, you will often find it useful for oscillating systems: 
3.2 Linear Oscillations 133 In[4]:= timePhasePlot [1;1_, p., tList_List, opts...] : = ParametricPlot3D[ {p, 1;1, tList [[1]], { Hue[0.8],Thickness[0.003]}} II Evaluate, tList, opts, PlotRange .... All, PlotLahel.... " Phase [t]", AxesLabel.... {"p[t]", "l;I[t]","t "}, Plotpoints .... 300, BoxRatios.... {1, 1, 1}] To see how to apply the procedure, consider the harmonic functions q=Sin [21ft] and p = q' [t]. The time-evolved phase diagram is In[5]:= timePhasePlot[Sin[2 n t],D[Sin[2 n t],t], {t,O,3}]; 1 phase [t] 3 o P [t] t 3.2.2.3 . doublePlot: Combination of the Phase Plot and the Time B Behavior of the Phase Plot The procedure doublePlot [q, p, tList] combines phasePlot and timePhase- Plot with GraphicsArray: 
134 Chapter 3 Oscillating Systems In[6] : = doublePlot [q., p., tList.List] .- Show [ GraphicsArray[ { phasePlot[q,p,tList, DisplayFunction- > Identity, FrameTicks .... None] , timePhasePlot[q,p,tList, DisplayFuDction- > Identity, Ticks .... None] } ] ; To see how to apply the procedure, consider the harmonic functions q [t] = Sin [21ft] and p [t] = q' [t] . The phase plot and time evolution are In[7]:= doublePlot[Sin[2 n t],D[Sin[2 n t],t], {t,O,3}]; tJ' t p p[t] 3.2.2.4 . Protect Commands Finally, we apply Protect to the user-defined procedures to kept them from being deleted with Clear [ II Global' * II ] : In[B]:= Protect[phasePlot,timePhasePlot,doublePlot]; . PROBLEM 1 Linear Oscillator. Consider a linear oscillator described by the equation x"[t] + w6 x[t] = O. a. If the initial conditions are chosen to be x[O] = xO and x' [0] = vO, show that the solution is xOcos[wO t] + vost] . Plot the solution. b. Show the solution can also be written as A cos[wOt + 6], wherex[O] = Acos[c5] and x'[O] = -A wO sin[6]. A is called the amplitude, and 6 is called the phase. c. Use LaplaceTransform to solve the equation. Remarks and Outline DSol ve expresses the solution in terms of two constants. By a proper choice of constants, you can have the solution represented in terms of either a phase and amplitude or in terms of the initial conditions x[O] and x'[O]. Another method used to 
3.2 Linear Oscillations 135 solve the differential equation follows from taking the Laplace ttansform. This method is certainly not practical for this simple example, but may be useful for more complex differ- ential equations. The graphics makes use of the add-on package Graphics' Arrow' . Solution In[9J:= Clear[OGlobal' * 0] a. The linear oscillator equation is In[lGJ:= eqi = x" [t] + (cI02 x[t] == 0 If you let the initial conditions be In [llJ : = initiali = {x [0] == xO, x' [0] == vO}; the solution follows from applying DSolve to eq1: In[12J := dSoli = DSolve[ {eqi ,initiali}//Flatten, x[t], t] //Flatten { xO wO Cos (t wO) + vO Sin (t wO) } x(t) -> wO Out[12J= Let us plot the simple harmonic motion for the values xO = 0, wO = 1 and vO = 1. To embellish the graph we add arrows found in the add-on package, In[13J:= Needs [RGraphicS'Arrow' 0] The commands in this package are In[14J:= ?Graphics'Arrow'* Graphics 'Arrow' Absolute Arrow HeadCenter HeadLength HeadScaling HeadShape HeadWidth Rela- tive ZeroShape We are interested in the command Arrow: In[15J:= ?Arrow Arrow[start, finish, (opts)] is a graphics primitive representing an arrow starting at start and ending at finish. More... Define three arrows at the origin pointing along the tangent to the curve, along the x- axis, and along the y-axis. The graphics for the arrows are In[16J : = arrow = { {Hue[0.2], Arrow[{O, O}, {0.5, 0.5}]}, {Hue[0.4] , Arrow[{O, O}, {2, O}]}, {Hue [0 .6], Arrow [ {O, O}, {O, 0.5}]} }; 
136 Chapter 3 Oscillating Systems The curve for x [t] is In[l?]:= Plot[x[t]/.dSoll/.{xO.... O,(cIO ....1, vO ....1}, {t, -2 1£,2 1£}, Epilog.... arrow] ; Epilog has been used to add the graphics for the arrows. The motion is simple har- monic. b. Instead of expressing the motion with both Sin and Cos terms, we could have con- sttucted a solution with just a Cos term. If we write the initial conditions as In[18]:= initia12= {x[O] ==A Cos[c5], x'[O] == -A (cIO Sin[c5]); then the solution that follows from DSol ve is In[19]:= dSo12 = DSolve [{eql, initia12} II Flatten, x[t], t] II Flatten II Simplify Out[19]= {x(t) ....A Cos (6 + twO)} where 6 is called the phase and A is called the amplitude. c. In this part of the problem we use Lap 1 aceTrans form to solve the differential equation. This is certainly unnecessary for this simple equation, but it does illusttate the use of the LaplaceTransform to solve differential equations. Take the Laplace- Transform of eql: In[20]:= lapTx = LaplaceTransform[eql, t, s] Out[20]= LaplaceTransform[x(t), t, s] S2 -x(O) s+ w0 2 LaplaceTransform[x(t),t,S] -x'(O) ==0 and solve for LaplaceTransform[x[t], t, s]: In[21]:= lapSol = Solve [lapTx, LaplaceTransform[x[t], t, s]] [ [1]] 
3.2 Linear Oscillations 137 { SX(O)+x'(O) } Out[21]= LaplaceTransform[x(t), t, s] -> S2 + w0 2 Taking the inverse using the command :I:nverseLaplaceTransform, you get the solution In[22]:= InverseLaplaceTransform[ LaplaceTransform[x[t],t,s]/.lapSol, s, t] //Apart Sin(t wO) x' (0) Out[22]= Cos (t wO) x(O) + wO . PROBLEM 2 Seri.es Expansion Solution. You may often solve differential equations using a time series expansion. The following procedure automatically performs the neces- sary operations. Enter the user-defined function, In[23]:= Clear[nGlobal' * n] diffSeriesOne [eq., z., t_, initialx_, initialv., order_] ._ Module [ {tempser,tempeq , tempvar, tempsol,tempinit}, tempser = z- > Series [z, {t, 0, order}]; tempeq= «eq[[1]] -eq[[2]]) //.tempser) ==0 ; tempvar = (Table [D[z, {t, j}], {j, 2, order + 2}] /.t- > 0) //Flatten; tempsol = Solve [tempeq, tempvar] / /Flatten; tempinit = {Head[z] [0] - > initialx, Head[z]' [0] - > initialv}; z/.tempser/.tempsol/.tempinit] and protect it. In[24]:= Protect[diffSeriesOne ]; The input eq is a second-order differential equation, z is the function, t is the inde- pendent variable, initialz and initialv are the initial conditions, and order is the order of the series solution. This procedure assumes the solution can be written as a power series. a. Explain how diffSeriesOne works by examining the intermediate steps in the solution of y"[t] + y y'[tf + w 2 y[t] == +a y'[tfy[t] b. Consider the linear oscillator equation x"[t] + w6 x[t] = 0 and find its time series expansion. Get the exact answer by using Sum to sum the terms to infinity. 
138 Chapter 3 Oscillating Systems Solution In [25] := Clear[nGlobal' * n] a. To understand how diffSeriesOne works, examine the intermediate steps. To do this, re-execute a slightly modified command, diffSeriesOne2. This time, however, delete all the local variables in the Module and then re-execute the example. In [26] := Clear[nGlobal' * n] diffSeriesOne2 [eq., z_, t_, initialx., initialv_, order.] .- Module [ { }, teD\Pser = z- > Series [z, {t, 0, order}]; teD\Peq = ( (eq [[1]] - eq [[2]]) //.teD\Pser) == 0 teD\Pvar = (Table [D [z, {t, j}], {j, 2, order + 2}] /.t- > 0) //Flatten; teD\Psol = Solve [teD\Peq, tem;pvar] //Flatten; teD\Pinit = {Head [z] [0] - > initialx, Head [z]' [0] - > initial v}; z/.teD\Pser/.teD\Psol/.teD\Pinit Notice that Module [{}, ...] has been written above so you can access the interme- diate results. Enter the equation In[27]:= eql=y"[t] +y y'[t]-2+ w-2 y[t] == a y' [t] -2 y[t]; and apply the user-defined function In[28]:= diffSeriesOne2 [eql, y[t], t, yO, vO, 2] 1 Out [28] = yO + vO t + - (a yO v0 2 - y v0 2 - W2 yO) t 2 + 0 (t 3 ) 2 The step tempser is the series expansion of y [t] to the appropriate order: In[29]:= teD\Pser 1 Out[29]= y(t) y(O} +y'(O} t+-y"(O} t 2 +O(t 3 } 2 The command tempeq simply takes the two parts of the input equation, puts them on the left-hand side of the equation, and then expands with tempser: In[30]:= teD\Peq//Short [#,3]& 
3.2 Linear Oscillations 139 Out[30]= (y(O) W 2 +yy'(0)2 -ay(O) Y'(0)2 +y"(O))+ (-a y' (0) 3 + w 2 y' (0) + 2 y y" (0) y' (0) _ 2ay(0) y"(O) y'(O) +y(3) (0)) t+ (  y" (0) W2 -  a y' (0) 2 y" (0) + 2 2 y (y" (0) 2 + y' (0) y(3) (0))- ay(O) (y" (0) 2 +y' (0) y(3) (0)) + y(4) (0)) t 2 +O(t 3 ) == 0 The independent variables that you want to solve for are stored in tempvar: In[31]:= t8ll\Pvar Out[31]= {y" (0), y(3) (0), y(4) (O)} The coefficients of t are set to zero and solved in tempsol: In[32]:= teD\Psol//Short[#,7]& Out[32]= {y(4) (0) -72ay(0)3 w 4 -2yy(0)2 w 4 +y(O) w 4 _ 8 a 2 y (0) 3 y' (0) 2 w 2 + 16 a y y (0) 2 y' (0) 2  + 3yy'(0)2 -8 y 2 y (0) y'(0)2w 2 _ 8 a y (0) y' (0) 2  - 6 y3 y' (0) 4 + 6 a 3 y (0) 3 y' (0) 4_ 18 a 2 y y (0) 2 y' (0) 4 _ 7 a y y' (0) 4 + 7 a 2 y(O) y' (0) 4 + 18 a y2 y(O) y' (0) 4, y(3) (0) -7 y' (0) (-2 a y (0) 2 w 2 + 2 y y (0) w 2 _ w 2 + 2 y2 y' (0) 2 + 2 a 2 y (0) 2 y' (0) 2 + a y' (0) 2 _ 4 a y y (0) y' (0) 2) , y" (0) -7 -y(O)  - yy' (0) 2 + ay(O) y' (0) 2} The result follows from substituting this solution, along with the initial conditions, into the series expression for the function: In[33]:= y[t]/.teD\Pser/.teD\Psol/.teD\Pinit 1 Out [33] = yO + vO t + - (a yO v0 2 - Y v0 2 -  yO) t 2 + 0 (t 3 ) 2 This agrees with In[34]:= diffSeriesOne [eql, y[t], t, yO, vO, 2] 1 Out[34]= yO+vOt+- (aYOv0 2 -YV0 2 -w 2 yO) t 2 +0(t 3 ) 2 b. Clear the variables from the previous calculation In[35]:= Clear[nGlobal' * n] The series expansion solution of In[36]:= eq2 = XU [t] + (cI02 x[t] == 0; 
140 Chapter 3 Oscillating Systems follows from the user-defined function diffSeriesOne. Apply diffSeriesOne function to eq2 and evaluate to order 9, and you get In[3?J:= approxsol = diffSeriesOne[eq2,x[t],t, xO, vO,9]11 Collect [#1, {xO,vO}]& [ tS wO s t 6 w0 6 t 4 w0 4 t 2 w0 2 J Out[371= xO 40320 -+-+1 + vO [ wOs t 9 _ w0 6 t 7 + w0 4 t 5 _ w0 2 t 3 + t J 362880 5040 120 6 Terms are kept to order 9 and grouped according to their initial conditions. Notice that this series solution can be expressed in terms of two sums: (_l)D (t(clO)2D In[38J:= termX[n.] = (2 n) I (_l)D (t(clO)2D+l termV [n_] = (cIO (2 n + 1) I as is verified by making the finite sum In[39J:= finitesum = Sum [ (xO termX[n] +vO termV[n]), {n,O,4}]; and comparing it with approxsol In[40J:= finitesum == approxsolllSiDlPlify Out [40J = True To get the exact answer, Swn the terms to infinity: In[41J:= exactSum = SUm [ (xO termX [n] + vO termV [n] ) , in, 0, Q)} ] II PowerExpand II Apart vO Sin(twO) au t [ 41 J = xO Cas (t wO) + wO . PROBLEM 3 Potential and Phase Diagrams for the Linear Oscillator. Consider a linear oscillator described by the equation mx"[t] + kx[t] = O. a. Find the conserved energy by reducing this second-order equation to a first-order differential equation. Identify the expressions for the kinetic and potential energies from the conserved energy. b. Plot the potential energy function and describe the system's behavior. c. Plot the phase diagram using ContourPlot and ShadowPlot3D. 
3.2 Linear Oscillations 141 Remarks and Outline An expression for the conserved energy follows from multiplying the equation of motion by x' [t] and then integrating. The potential and kinetic energy follow from the energy expression. A qualitative description of the motion follows from a plot of the potential energy. Trajectories in phase space follow from plotting the curve {x [ t] , x' [t] }. The relation between x [ t ] and x' [t] follows from the energy ex- pression. ContourPlot and ShadowPlot3D are two graphic commands that can be used to display the phase plots. This problem makes use of the add-on packages Graph- ics 'Fi lledPlot' and Graphics' Graphics3D' . Solution In[ 42]:= Clear [nGlobal' * n] a. The oscillator equation is In[43]:= Force = m x" [t]; Spring = -k x [t] ; eql = Force = = Spring Out[43]= mx" (t) == -kx(t) To reduce the problem to a first integral, multiply by x' [t] , integrate, and set the results equal to a constant (the energy): In[44]:= energy = Integrate[x' [t](m x"[t] +k x[t», t] 1 1 Out[44]= -kx(t)2+- m X'(t)2 2 2 The kinetic energy T follows from integrating Force and the potential energy V follows from integrating Spring: In [45] : = T = Integrate [x' [t] Force, t] ; V = - Integrate [ x' [t] Spring, t] ; {T, V} Out[45]= {%m x'(t)2, %kX(t)2} The conserved energy is the sum of the kinetic and potential energies: In[46]:= energy = T +V 1 1 Out[46]= -kX(t)2+- m X'(t)2 2 2 b. The graph for the potential function follows from applying Plot to V. To embel- lish the plot, use the command FilledPlot found in the add-on package Graph- ics 'Fi lledPlot ' : In[47]:= Needs[nGraphics'FilledPlot,n] 
142 Chapter 3 Oscillating Systems We are interested in In[48]:= ?FilledPlot FilledPlot[function, {var,varmin,varmax}J generates a plot with the area be- tween the curve and the var axis filled. FilledPlot[{fl,f2, ...},range] gen- erates a plot with the areas between curve fl and f2, f2 and f3, etc. filled. The shade of the fill and other specifications can be given by the Fills op- tion. More... The graph for k = 1 and m = 1 is In[49]:= FilledPlot [V/.{x[t] -+ x, k -+ 1,m-+ 1}, {x, -1, 1}, PlotStyle- > {Thickness [0.02] }, Fills- > {Hue[O.S]}, Frame -+ True, RotateLabel -+ False, PlotLabel -+ nv n , FrameLabel -+ {nx - axisn, nPotential n } ]; v Potential x-axis The motion is confined to the white region by the dark potential curve. The motion is bounded for all initial conditions. There is one stable equilibrium position at the minimum of the potential located at x = o. c. ContourPlot and ShadowPlot3D are two graphic commands that can be used to make phase plots. Consider the phase plot that follows from ContourPlot; you get contours of constant energy when ContourPlot is applied to energy. Set the values of m and k equal to 1, and then define the replacements x [t] x and x' [t] v, In[50]:= values = {m-+1,k-+1,x[t] -+x,x'[t] -+v}; it follows 
3.2 Linear Oscillations 143 In[51]:= ptl = ContourPlot [ Evaluate[energy/.values], {x,-l,l}, {v,-l,l}, ColorFunction- > Rue, Contours- > 30, PlotPoints- > 30, ContourStyle - > { Thickness [0.006] }, Axes -+ True, AxesLabel -+ {Ox [t] n, nv[t] n}] ; v [t] 1 0.5 o -0.5 We have used several ContourPlot options. The list of options for ContourPlot follow from entering Options [ContourPlot] . The phase plane {XIV} is filled with nested circles. Each circular phase ttajectory corresponds to a particular value of the conserved energy. The point at the center {x [t ] = o I X I [t] = O} represents the position of equilibrium and corresponds to zero energy. Periodic motion results from all initial conditions except the equilibrium position at the center. A second way you can graph the phase plane is to plot the energy surface as a function of {x [t] I x' [t] } and then project the surface onto the plane {x [t] I x' [t]}. The command for the energy surface follows from ShadowPlot3D found in the package Graphics 'Graphics3D': In[52]:= Needs[nGraphics'Graphics3D'O] In[53]:= ?ShadowPlot3D ShadowPlot3D[f, {x, xmin, xmax}, {y, ymin, ymax}] plots the function f over the the x and y ranges with polygons shaded according to the height of the surface, with a projection of the surface onto the x-y plane. More... Applying ShadowPlot3D to energy, you get 
144 Chapter 3 Oscillating Systems In[54]:= ShadOWP1ot3D[energy/.va1ues, {x,-l,l}, {v,-l,l}, P1otLabe1 -+ DEnergy SUrfaceD, Axes -+ True, AxesLabe1 -+ {nx[t] n, nv[t] n, nenergyn}, ShadOWPosition -+ 1]; 1.5 energy 1 The energy surface is projected onto the plane at the top of the plot and represents the contour plot of the surface. . PROBLEM 4 Damped Linear Oscillator. Consider a damped linear oscillator, where the dissipation is proportional to the velocity. The equation of motion for the damped os- cilla tor is x"[t] + Y x'[t] + w0 2 x[t] = o. The damping is characterized by the coefficient y. a. Solve the equation with initial conditions x[O] = xO, x'[O] = vO, and describe the behavior of the solution for the three cases: (i.) under-damped case, when y2 < 4w0 2 ; (ii.) critically-damped case, when r = 4w0 2 ; and (Hi.) over-damped case, when r > 4w0 2 . b. Plot the solutions for the under-damped and over-damped cases. c. Plot the phase space diagram for the under-damped case. d. Express the second-order damped oscillator equation as two first-order equations x'[t] = v[t] and v'[t] = -y v[t] - w0 2 x[t] 
3.2 Linear Oscillations 145 Let the parameters be y = 0.1, wO = 1 (under-damped case) and use the command PlotVectorField found in the add-on package Graphics' PlotField' to plot the tangent to the ttajectory. Combine the vector field plot with a plot of some ttajectory. e. Use Laplace ttansforms to solve the damped equation. Remarks and Outline The damped harmonic oscillator equation has an exact analytic solution. The solution yields different behaviors for different parameter values. When the damping factor equals zero, the system reduces to the case of the simple harmonic oscil- lator: continuous oscillation at the natural frequency with constant amplitude. When the damping factor is greater than zero the system mayor may not oscillate. Depending on the relation between the damping factor and the natural frequency, there are three cases to con- sider: I. under-damped case, r < 4w<Y; 2. critically-damped case, y2 = 4w0 2 ; and 3. over- damped case, r > 4w0 2 . The general solution follows from DSol ve. The expression for the phase plot follows from the user-defined functions timePhasePlot and phase- Plot. This problem makes use of the add-on package Graphics' PlotField'. Solution In [55] := Clear [PG1oba1 ' * P] a. Consider the damped oscillator equation, In[56]:= eq1=x"[t] +¥ x'[t] + wO-2x[t] ==0; and apply the command DSol ve: In [57] := xso1 = x[t]/. DSo1ve[{eq1, x[O] == xO, x' [0] == vO}, x[t], t] [[1]] / /SiD\plify Out[57]= ( .1 t ( y+ ) e 2 (2 (_ 1+et yy2-4W02 ) vO+ xO ( ,/ 1'2 - 4 w0 2 (1 + et yy2-4W02 ) + (-l+et) 1')) )/(2 '/ 1'2 -4W0 2 ) It is convenient to inttoduce the quantity w: In[58]:= wRu1e= S Olve[w02-  == W'WO] [[2]] Out[58]= {WO.... ,/ y2+4W2} Our solution now reduces to: 
146 Chapter 3 Oscillating Systems In [59J := xsol = xsol l.wRulellExpTOTrig II FullSimplify e-¥ (2xOwCos(tw) + (2vO+xOy) Sin(tw)) Out[59J= 2w The result has been reduced to a form where the interpretation is obvious. Notice the undamped oscillator is recovered in the limit of yO: In [60J: = xsol/.¥- > 01 IPowerExpand II ExpandAll vO Sin(tw) Out[60J= xO Cos(tw) + w For the under-damped case (r < 4w0 2 or w real) the solution is an exp onentially damped amplitude times an oscillating term with angular frequency of w =  w0 2 - . The amplitude of the oscillation is exponentially damped by the factor e-!:f. The critically-damped case (y2 = 4w0 2 or w = 0) has an exponential type of decay In[61J:= Limit [xsol,'1- >2wO] e. twO (xOwCos(tw) + (vO+xOwO) Sin(tw)) Out[61J= w The over-damped case (r > 4w0 2 or w imaginary) is just a continuation of the critically-damped case and the solution just decays without oscillating. b. Consider the under-damped case (r < 4w0 2 or w real). Let In [62J := values = {xo -+ 1, wO -+ 1, vO- > 0, w- >  w0 2 - 'I: } ; The user-defined graphics procedure for the plot of this under-damped case is In[63J:= pt[¥l-/;0<=¥l<2] := Plot [xsoll I. values I . {¥- > '11 } I I Evaluate, {t,O,15}, PlotStyle- > {Rue[Random[]],Thickness[0.03]}, PlotRange- > All, DisplayFunction- > Identity] The plot is a function of the damping constant. A restriction has been placed on the value of the damping constant so that it is defined only for the under-damped case. The solution is plotted for time running from t = 0 to t = 15. An array of under-damped graphics starting at y = 0 and approaching the critical value at y = 2 is 
3.2 Linear Oscillations 147 In [64J := Show[ GraphicsArray [ {{pt[0],pt[0.2], pt[0.4]}, {pt [0.8], pt [1.4], pt [1.9]}} ] ; o. o. 8: O' L 0.6 0.4 0.2 2 4 -0. The oscillations become more and more damped and eventually disappear as y ap- proaches the critical value at 2. Consider the over-damped case (r > 4w0 2 or w imaginary). The plots for several over- damped cases, starting near the critical value y = 2 and ending at y = 6, follow from In [65J:= Plot [ (xsolll.values) I. ¥- >Range[2.000l, 6.0001,0.4] II Evaluate, {t, 0, l5} , PlotStyle- > Table[Eue[i], {i, 0, 1, l/12}]11 Evaluate ] ; The top curve so for y = 2.0001 and the bottom is for y = 6.0001. c. It is useful to plot the two-dimensional phase trajectory and the three-dimensional time evolution of the phase trajectory. Both of these graphs are displayed as a graphics array using the user-defined command doublePlot; 
148 Chapter 3 Oscillating Systems In[66]:= {x, v} = {xsol,D[xsol,t]}//.values/. {y-+ 0.2} Out[66]= {0.502519 e. o .1t (1.98997 Cos(0.994987t) +0.2 Sin(0.994987t)), 0.50251ge- O . 1t (0.198997 Cos(0.994987t)- 1. 98 Sin (0.994987 t) ) - 0.0502519 e. o .1t (1.98997 Cos(0.994987t) +0.2 Sin(0.994987t))} In[67]:= doublePlot [x, v, {t,O.01,30}]; Phase Trajectory q [t Phase [t] t p d. Let US consider a vector field plot of the damped equation and compare it with some ttajectory. Pick the parameters to be y = O. 1, wO = 1 and let the ttajectory have the parameters and initial conditions. In[68]:= values2 = {y-+ 0.1, wO -+ 1, xO -+ 1, vO -+ 0, w- >  w0 2 -  }; The phase plot {x, x'} for this ttajectory is In [69] : = traj = parametricPlot [ {xsol, D[xsol, t] }/ / .values2 / / Evaluate, {t, 0, 60}, PlotStyle -+ {Thickness [0 .008], GrayLevel[O]}, DisplayFunction -+ Identity] ; where the output has been suppressed. Combine the plot of this ttajectory with a vector field plot of the damped oscillator. The second-order damped oscillator equation can be expressed as the two first-order equations: x' [t] = v[t] and v' [t] = -y v[t]- w0 2 x [t]. For the parameters y = 0.1 and wO = 1 (under-damped case) the two first- order equations become: x' [t] = v[t] and v' [t] = -0.5 v[t] -x[t]. The vector field plot follows from applying P1otVectorFie1d (found in the add-on pack- age Graphics' P1otFie1d ') In[70]:= Needs[RGraphics'PlotField,n] 
3.2 Linear Oscillations 149 to the damped equation, In[71]:= Clear [x, v]; ptl = PlotVectorField [ {v, -0.5v - x} //Evaluate, {x, -1, I}, {v, -1, I}, Defaul tColor -+ Hue [0.6] , Plotpoints -+ 20, AspectRatio -+ Automatic, Axes -+ Automatic, AxesOrigin-+ {O, O}, ScaleFunction -+ (1&:), Epilog -+ traj [[1]]]; " .,.,. - .. ... - .... -...  ,,', ',- ..... ',,- , ", , , , ....',.....""", -' .,  - - , , , j . . . . . \ \ \ \ \ \,  ..... -  ..... -<It. ... .... "" We added the particular ttajectory with Epilog. Notice how the arrows are tangent to the path. The match would be even closer if more points were kept in the vector field plot. e. Use Laplace ttansforms to solve for the damped equation given by eql: In [72] := eql Out[72]= x(t) w0 2 +y x'(t) +x"(t) == 0 The LaplaceTransform of eql gives an algebraic equation, In [73] := lapTx = LaplaceTransform[eql, t, s] Out[73]= LaplaceTransform[x(t), t, s] S2_ x(O) S + w0 2 LaplaceTransform[x(t), t, s] + y (s LaplaceTransform [x(t) , t, s] - x (0) ) - x' (0) == 0 You solve for LaplaceTransform[x [t] ,t, s]: 
150 Chapter 3 Oscillating Systems In [74] := 1apSo1 = Solve [lapT.K, Lap1aceTranSform[x[t], t, s]] [[1]] / / Simplify { 5X(O) +y x(O) +x'(O) } Out[74]= LaplaceTran5form[x(t), t, 5] -7 2 2 5 + y 5 + wO Taking the inverse, you get the solution In [75] := sol = InverseLap1aceTransform[ Lap1aceTransform[x[t],t,s]/.lapSo1, s, t] Out[75]= (.-! +. N-"""' ) (( _ 1 .. , ) Y x(O). ( 1 + e t ,;../ -4 wo 2 ) -J y2 - 4 w0 2 X (0) + 2 ( - 1 H t vI)'2.4 wo 2 ) x' (0) ) )j( 2 -J y2 - 4 w0 2 ) . PROBLEM 5 Damped Harmonic Oscillator and Driving Forces. Consider the mo- tion of an under-damped harmonic oscillator with a harmonic forcing term. The motion is described by the equation x"[t] +yx'[t] +w0 2 x[t] = QOcos[wdt] where 4w0 2 > y. a. Solve this equation with arbitrary initial conditions. Separate the solution into those terms that have the coefficient QO and those that do not have this coefficient. The QO terms correspond to the particular solution, and the terms that don't have a QO term correspond to the solution of the homogeneous equation. b. Assume the particular solution can be reduced to the form A Cos [wd t+<p] and solve for the amplitude A and phase <p. c. Plot the solution as a function of wO and t. Plot the amplitude A as a function of wO and y. Notice the resonance behavior at wO= wd. d. Pick parameters to illusttate the ttansient and steady-state behaviors and plot x [t] and its phase ttajectory. Remarks and Outline The driven harmonic oscillator with a harmonic driving term has an exact analytic solution. The solution has two parts: ttansient and steady-state. The ttan- sient portion, which has the same solution as the damped harmonic oscillator and dies out exponentially, depends on the initial conditions. The steady-state portion has an ampli- tude that remains constant and does not depend on the initial conditions. Thus, no matter what initial conditions the oscillator had, it will eventually acquire behavior that is wholly 
3.2 Linear Oscillations 151 dependent upon the driving force. The amplitude that the oscillator eventually acquires de- pends on the relation of the driving frequency to the natural frequency of the oscillator and on the damping factor. The hard part of this problem is not the solution of the differential equation; rather, it is the simplification of the terms. The simplification is done by separating the solution into those terms that contain QO and those that do not have this constant. The QO terms correspond to the particular solution and the other terms correspond to the solution of the homogeneous equation. The simplification of the homogeneous solution is sttaightforward. The simplification of the particular solution follows from noticing that it is of the form A Cos [wd t+<p]. Equating this form to the particular solution you get two algebraic equa- tions when you set the coefficients in front of the Sin [wd t] and Cos [wd t] terms to zero. These equations can be solved for <p and A. The solution is plotted with the com- mand Plot 3D. The plot of the phase ttajectory follows from the user-defined procedures phasePlot and timePhasePlot listed at the beginning of this section. Solution In [76] := Clear [nGlobal , * n] a. The damped harmonic oscillator with a forcing term is In [77] := eql = XU [t] + ¥ x' [t] + w0 2 x[t] == 120 Cos [wd t]; The solution of this equation follows from DSol ve. In[78]:= eq2 = x[t] /. DSolve [eql, x[t], t] / /First / / siDIPlify .! t (Y+ Vy 2 . 4WQ 2 )  t ( Vy2.4WQ2 _y) e c 1 + e c 2 + Out[78]= QO ( (w0 2 - wd 2 ) Cos (t wd) + 'I' wd Sin (t wd) ) w0 4 _ 2 wd 2 w0 2 + wd 4 + '1'2 wd 2 This solution simplifies if you separately consider the homogeneous terms and the terms that follow from the particular solution. The homogeneous terms follow from setting the forcing term to zero, In [79] := eq3 = eq2/.QO- > 0 Out [79]= . t (Y+ Vy 2 . 4WQ 2 )  t ( Vy2.4WQ2 _y) e c 1 + e c 2 where c[ == C[1] and C z == C[2] are arbittary constants. The rest of the terms in eq2 correspond to the particular solution and are proportional to QO In[80]:= eq4 = (eq2 - eq3) //FullSiDIPlify 
152 Chapter 3 Oscillating Systems QO (wO - wd) (wO + wd) Cos (t wd) + QO y wd Sin(t wd) Out[80J= w0 4 + wd 4 + (y2 _ 2 w0 2 ) wd 2 b. The homogeneous solution simplifies if you express the answer in terms of w = ...; w0 2 -  and define two new constants AO and BO by: In[81J:= cRule = Solve [{c]. ==  (AO + iBO), C2== (AO-iBO)},{C[1],C[2)}][[1]] [ 1J { 1. 1. } Out 8 = C 1 .... 2 (AO+:u.BOJ,c 2 ....2 (AO-:u.BO) In[82J:= wRule= s Olve[w02-  == w,WO] [[2]] Out[82J= {WO.... -J y2+4W2} The homogeneous solution becomes: In [83 J : = homogSol = eq3 / / . cRule / . wRule / / ComplexExpand / / Simplify / / powerExpand Out[83J= e-¥ (AO Cos(tw) +BO Sin(tw)) The constants AO and BO are determined by the initial conditions. To simplify the particular solution, we tty reducing eq4 to the form In[84J:= eq5= A Cos[wdt + 1/I]//TrigExpand Out [84J = A Cos (cjJ) Cos (t wd) - A Sin (cjJ) Sin (t wd) How are A and <p related to the original variables? Equating eq4 and eq5, you get In [85J := eq6 = eq4 - eq5 == 0 Out[85J= -A Cos(cjJ) Cos(twd) +A Sin(cjJ) Sin(twd)+ QO (wO - wd) (wO + wd) Cos (t wd) + QO y wd Sin (t wd) w0 4 + wd 4 + (y2 _ 2 w0 2 ) wd 2 == 0 Two independent equations are obtained from eq6 if you consider the orthogonal Sin [t wd] and Cos [t wd] dependence: In[86J:= eq7 = { eq6/. {sin[_ t] - > 0, Cos [. t] - > 1), eq6/.{Cos[_t]- >O,Sin[_t]- >1}} 
3.2 Linear Oscillations 153 Out[86J= { QO (wO - wd) (wO + wd) 4 4 2 2 2 - A Cos (cjJ) == 0, wO + wd + (." - 2 wO ) wd QO ."wd } +A Sin(cjJ) == 0 w0 4 + wd 4 + (.,,2 - 2 w0 2 ) wd 2 Solving these two equations for A and f/J, you get In[87J:= eq8 = Solve [eq7, {A, 4>} ] [[4]] I ISim,plify I I PowerExpand Out[87J= {A-? QO , -J w0 4 - 2 wd 2 w0 2 + wd 4 +.,,2 wd 2 ( W02 - wd 2 ) } cjJ -? Cos. 1 -J w0 4 - 2 wd 2 w0 2 + wd 4 + .,,2 wd 2 where we have kept the positive root for A Further simplification occurs if you replace ArcCos by ArcTan using the rule In[88J:= rule = {cos- 1 (x.) -+ Tan-1 ( "1/1  )}; In [89J := solAt{> = eq8/.rulell Sill\Plify II PowerExpand Out[89J= { QO A-? , -J W0 4 - 2 wd 2 w0 2 + wd 4 +.,,2 wd 2 cjJ -? Tan. 1 ( : wd 2 ) } wO - wd Using this relation for A and f/J, the particular solution becomes In [90J : = partSol = A Cos [wd t + 4>] I. solAt{> QO Cos ( twd+Tan. 1 ( d 2 ) ) Out[90J= wO wd -J w0 4 - 2 wd 2 w0 2 + wd 4 + .,,2 wd 2 The general solution genSol is a superposition of the particular solution part Sol and the homogeneous solution homogSol: In [91 J : = genSol = partSol + homogSol QO Cos ( twd+Tan.l (  )) wO -wd + -J W0 4 - 2 wd 2 wo 2 + wd 4 +.,,2 wd 2 e. Y (AD Cos (t w) + BO Sin (t w) ) Out[91J= This is about as simple as you can get. 
154 Chapter 3 Oscillating Systems c. To plot the solution as a function of wO and t, let In [92} := values = {A-+ 3, QO -+ 1, rdd-+ 1,AO -+ 0, BO -+ 1, w -+  w0 2 - y: }; Applying the command Plot3D to genSol with these values, you get In [93} := P1ot3D[genSo11 I .va1uesl I. {y -+ ° .1}1 I Evaluate, {t, 0, 30}, {wO, 0.5, 1.5}, P1otPoints -+ 40, AxesLabe1-+ {"Time", "won, "x[t]"}, FaceGrids -+ {{O, 1, O}, {O, -1, O}}, ViewPoint -+ {1, 0.4, 0.6}]; a x[t] The oscillations are not simple harmonic but contain ttansient effects. Notice the res- onance behavior at wO = wd = 1. The resonance behavior follows from the form of A: In [94} := P1ot3D [ AI. solA1/>I . values II Evaluate, {y, 0.001, 0.5}, {wO, 0.5, 1.5}, P1otpoints -+ 25, P10tRange -+ {O, 15}, AxesLabe1-+ {"y", "won, "An1P1itude"}, FaceGrids -+ {{ -1,0, O}}, ViewPoint -+ { 0. 5, 1, 0.4} ] ; 
3.2 Linear Oscillations 155 15 0.5 The resonance occurs at wO = wd = 1, and its height diverges as yO. The diver- gence is clipped, since PlotRange is set to {O, 15}. d. To illusttate the ttansient and steady-state behavior of genSol, define the plot func- tion In[95]:= pt[name.,opts...] := Plot [ namell.va1uesll.{y -+ 0.1, wO -+ 2} II Evaluate, {t,O,80}, opts, Ticks -+ None, Disp1ayFunction- > Identity] ; Apply pt to genSol, partSol, and homogSol, In[96]:= Show[ Graphics[{ Rectang1e[{O, O}, {1, 1}, pt [genSo1, P1otSty1e- > Hue [0.8] , Ticks -+ Automatic] ] , Rectangle [{0.6, 0.7}, {I, 1}, pt [partSo1, P1otSty1e- > Hue [0 .4], Background -+ GrayLeve1 [0.9] ] ] , Rectangle [{0.6, O}, {1, 0.3}, pt [homogSo1, P1otSty1e- > Hue [0 .8], Background -+ GrayLeve1 [ 0 .9] ] ] } ] ] ; 
156 Chapter 3 Oscillating Systems 1 0.5 -0.5 -1 We have used the graphic command Rectangle to arrange the positions of the three graphics: In[97]:= ?Rectang1e Rectangle [{xmin, ymin} , {xmax, ymax}] is a two-dimensional graphics pr1m1- tive that represents a filled rectangle, oriented parallel to the axes. Rect- angle [{xmin, ymin} , {xmax, ymax} , graphics] gives a rectangle filled with the specified graphics. More... The main plot is the complete solution, and the inserts are the homogeneous and par- ticular solutions. For t<SO, both the ttansient and steady-state solutions are obvious in the general solution; for t>SO, the solution is dominated by the particular (steady-state) solution. The phase ttajectory follows from the user-defined commands timePhasePlot and phasePlot, which are combined in doublePlot: In [98] := q = genSo1/ / . va1ues/ /. {y -+ 0.1, wO -+ 2}; P = D[q, t]; doub1eP1ot [q, p, {t, 0, SO} ]; Phase Trajectory q[t]phase[t] t p The first plot illusttates the phase plot with both the steady-state and ttansient effects, and the second shows how the ttansient effect dies off with time. After the ttansient effects have become small, the phase plot becomes In[99]:= phaseP1ot[q,p,{t,200,250}, AspectRatio -+ Automatic]; 
3.3 Small Oscillations 157 Phase Trajectory 0.3 0.2 0.1 tJ' 0 -0.1 -0.2 .0.3 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 P . 3.3 . SMALL OSCilLATIONS 3.3.1 . Overview of Small Oscillations and Normal Modes The restoring forces in any actual physical system are only approximately linear functions of displacement. Systems involving sttetching, compressing, bending, or twisting result in nonlinear systems. Nevertheless, it is remarkable that a vast variety of physical systems reduce to restoring forces proportional to their displacement for small displacements and hence lead to simple harmonic vibration. In this chapter we shall consider several examples of such motion. Linear systems with many degrees of freedom, such as coupled oscillators, are most conveniently described by finding the normal modes of the system. Let us consider those linear systems in which the oscillatory motion is described by a potential and the motion takes place in the neighborhood of an equilibrium point. The motion can be described by coordinates qJt](i = 1, 2, 3, ...n), where qi[t] is measured from the equilibrium position. If the forces are linear functions of the displacements, the expressions for the potential V and the kinetic energy T will be quadratic in qJt]: ! V;jqJt]q}t] and ! T;j q;-[t] qj' [t]. The coefficients V;j and T;j form the potential and kinetic energy matrices, respectively. The equations of motion for this system of coupled linear oscillators can be expressed in terms of the potential and kinetic energy matrices: T;jqj[t] + V;jqj[t] = 0 Only for certain initial conditions will the system oscillate at one natural frequency. When it does, we speak of a normal mode of oscillation. Let the parameters WI' w Z ' w 3 ' ..., be the normal frequencies of oscillation. For each Wi' there is a corresponding normal mode of oscillation in the coordinates {qn[t], q;z[t], qi3[t], qi4[t], ...}, where i indicates the eigenmode for particles {l, 2, 3...}. All of the particles in a normal mode vibrate with the 
158 Chapter 3 Oscillating Systems same frequency. A complete solution of the motion involves a superposition of normal modes. You often want to solve for the eigenvalues and eigenvectors for systems in the limit of small oscillations. It is useful to create a user-defined procedure to do this. The user-defined procedure is defined below. 3.3.2 . Initialization of User-Defined Funtions for Small Oscillations and Normal Modes 3.3.2.1 . Eigenvalues and Eigenvectors for Small Oscillating Systems Given the expressions for the kinetic and potential energies of the system, the procedure smallOsc [T, V, {ql [t] , q2 [t] , . . .}, {ql0 ,q20, . . .}, t] finds the eigenfre- quencies and eigenvectors: In[lOO]:= small0sc [T_, V_, coord_List, equlib_List, t. :t] := Module [{q, p, dim, equlibRule, Vij, Tij, matrix, ",2S01, freq, vector, eqs, vSol}, q = coord; p = D[coord, t]; dim = Length[q]; equlibRule = Thread [coord -+ equlib] ; Vij = OUter [D[V, #1, #2]&:, q, q]; Tij = OUter [D [T, #1, #2] &:, p, p] ; matrix = Vij - ",2 Tij l.equlibRu1e; ",2S01 = Sill\Plify [Solve [Det [matrix] == 0, "'2]] ; freq = ",21 .",2S01; vector = Array [a, dim]; eqs = Sill\Plify[ ExpandAll [ Thread[O == matrix.vector]]]; vSo1 = Table [ Solve[Join[eqs/.",2S01[[i]], {vector.vector == 1}] ,vector] [[2]], {i, 1,dim}]; {freq, vSo1} ] Protect the user-defined procedure from being deleted with In[lOl]:= Protect[sma110sc]; To see how to apply the procedure consider the kinetic and potential energies, 1 1 In [102] := T = - m q1' (t}2 + - m q2' (t}2; 2 2 1 V= -k1 (q2(t) _q1(t}}2; 2 Applying the user-defined procedure, we get 
3.3 Small Oscillations 159 In[lG3]:= smallOsc [T, v, {ql [t], q2 [t]}, {O, O}, t] Out[lG3]= [ 1 1 } {a(l) -? ...fi  a(2) -? ...fi 2 k1 1 m 1 {a (1) -? ...fi ' a (2) -? - ...fi } The first list in the output is the square of the eigenfrequencies, and the remaining lists are the associated eigenvectors. . PROBLEM 1 Two Coupled Oscillators along a Line. Consider the vibrations of two particles of mass m connected to each other by a spring of stiffness kl. Each particle is also connected to the wall by two more springs with equal spring stiffness k2. Let x [ 1] and x [2] be the displacements from the equilibrium configuration for the two particles. Consider small vibrations along the line of the particles. xl x2 a. Derive the algebraic equations for the eigenfrequencies and eigenvectors. Solve for the eigenfrequencies and eigenvectors using the command Solve. b. Use the command Reduce to solve the algebraic equations for the eigenfrequencies and eigenvectors. c. Use the user-defined function smallOsc to solve for the eigenfrequencies and eigen- vectors. d. Write the general solution and plot the motion for the normal modes and for a mix- ture of normal modes. Remarks and Outline The algebraic equations follow from expanding the kinetic T and potential energies V for the system about the point of equilibrium. The Tij and Vij matrices for small oscillations follow from the coefficients in front of the quadratic terms in x[i]'[t] and x [i] [t]. The eigenfrequencies follow from solving Det [Vij -w 2 Tij] = O. The algebraic equations for the eigenfrequencies and eigenvalues can be solved using the commands Solve or Reduce. Alternately, the user-defined command smallOsc summarizes these steps and returns the eigenfrequencies and eigenvalues for the system. The solution also follows from the commands Eigenvalue and Eigenvector, or the command Eigensystem. The general solution is a linear combination of terms of the form cos[ wi t + t/>i], where wi are the eigenfrequencies and t/>i are the phases. 
160 Chapter 3 Oscillating Systems Solution In[104J:= Clear[RGlobal' * R] a. The kinetic and potential energies for the coupled oscillators are V= 1 1 -m x[1]'[t]2+- m x[2]'[t]2; 2 2 1 1 - k2x[1] [t]2 + - k2x[2] [t]2+ 2 2 1 - k1 (x[2] [t] -x[l] [t])2; 2 In[105J:= T = where the coordinates and momenta In[106J:= q= {x[l] [t],x[2] [t]}; p = D[q, t]; are the displacements from the equilibrium configuration. Note here the use of the x [ i] [t] notation. This allows you to use the i index to label the coordinates and momenta, while still taking advantage of the derivative shorthand notation x[i]'[t]: The Tij and Vij matrices for small oscillations follow from the coefficients in front of the quadratic terms in x[i]'[t] and x [i] [t]: In[107J:= Tij = OUter [D[T, #1, #2]&:,p,p] Vij = OUter [D [V, #1, #2] &:, q, q] ( m o m O ) Out[107J= ( kl + k2 Out[107J= -kl -kl kl + k2 The eigenvector matrix is In [108J:= (matrix = vij - ",2 Tij) / /MatrixForm ( kl + k2 - mw2 Out[108J= -kl -kl ) kl + k2 -mw2 where w2 is the square of the eigenfrequency. The eigenfrequencies follow from setting the determinate of matrix equal to zero and solving for w2 : In[109J:= ",2801 = 8 im;pli fy [801ve [Det [matrix] == 0, ",2]] { { k2 } { 2 kl + k2 } } Out[109J= w2  m ' w2  m The square root of w2 gives the two eigenfrequencies. The eigenvector { al, a2} for the first eigenfrequency, w2 = k/m, follows from solv- ing the algebraic equations (Mijv j = 0): 
3.3 Small Oscillations 161 In[110J:= vector = Array [a, 2]; eq = Thread [0 == matrix.vector] Out[110J= {O== (kl+k2-mw2) a(l) -kla(2), o = = (kl + k2 - m w2) a ( 2) - kl a ( 1) } To obtain the appropriate eigenvector, you must substitute the appropriate eigenvalue for w2. Here you solve for the first eigenvector in eq by substituting with w2S01 [ [1] ] : In [111J := eq1 = Sim,plify[ExpandAll [eq/ . ",2S01 [[1]]]] Out[111J= {kl (a(l) -a(2)) ==O,kl (a(2) -a(l)) ==O} The normalization equation is In[112J:= eqNorm= {vector.vector == 1}; Solving eq1 for the eigenvector (i.e., the components of vector), you have In[113J:= ev1ru1e = Solve [Join [eq1, eqNorm], vector] [[2]] Out[113J= {a(l)   ,a(2)   } The eigenvector for the second normal frequency follows from eq by replacing the eigenvalue with w2 Sol [ [2] ] : In [114J:= eq2 = Sim,plify[ExpandAll [eq/ .",2S01 [[2]]]] Out[114J= {kl (a(l) +a(2)) ==O,kl (a(l) +a(2)) ==O} The components for the eigenvector { a [ 1] , a [2] } are In[115J:= ev2ru1e = Solve [Join[eq2, eqNorm], vector] [[2]] Out[115J= {a(l)   ,a(2) -  } b. Instead of first solving for the eigenfrequencies and then eigenvectors, Reduce does both calculations simultaneously. Applying Reduce to the matrix equation, In [116J : = eq3 = Thread [0 == matrix. vector] Out[116J= {O == (kl +k2 -mw2) a(l) -kla(2), o == (kl + k2 - mw2) a (2) - kl a (1) } and reducing for { w2, a1, a2}, you get the relevant solutions In[117J:= {sol = Reduce [Flatten [{eq3, eqNorm}], {",2,a[1],a[2]}] [[{8, 10}]])// Co1umnForm 
162 Chapter 3 Oscillating Systems Out[117J= k2 1 1 w2==-lIa(l) ==-lIa(2) ==-lIkl*Ollm*O m '2 ...[2 2kl+k2 V. 1 1 w2 == m II a (1) == ...[2 II a (2) == - ...[2 II kl * 011 m * ° c. The eigenfrequencies and eigenvectors also follow immediately from the user-defined function small0sc. Applying small0sc to T and v, you get In [118J : = eq4 = smallOsc [T, V, {x[l] [t], x[2] [t] }, {O, O}, t] [ k2 Out[118J= 1 m 1 {a(l)  ...[2 ' a(2)  ...[2 } 2 kl + k2 { 1 m 1 } a(l)  ...[2 ' a(2)  - ...[2 The command small0sc returns two lists. The first list is the set of squared eigenval- ues; the second is the set of eigenvectors, in the same order. These solutions agree with the results derived in Parts a and b. d. The general solution is a linear combination of terms of the form cos[ wIt + f/J 1] and cos[ w2t + f/J2], where wI and w2 are the two eigenfrequencies. By defining the eigenmatrix: In[119J:= eigenmatrix = vector/ /. {ev1ru1e, ev2ru1e} 1 1 Out[119J= I 'll _1 ...[2 ...[2 the general solution is In[120J:= xRu1e = {xl [t], x2 [t]} -+ Transpose[eigenmatrix]. {c1 Cos[w1 t + 4>1], c2 Cos [w2 t + 4>2] }// Thread / / 8ill\Pli fy { c1 Cos (.pl + t wl) + c2 Cos (.p2 + t w2) Out[120J= xl(t) ...[2 , c1 Cos (.pl + t wl) - c2 Cos (.p2 + t w2) } x2 (t)  ...[2 where cl and c2 are the relative amplitudes of the two normal modes. The eigenfrequen- cies, wl and w2, are In[121J:= freqru1e = Thread [ {w1, w2} -+ (8qrt [w2] / .(2801)] Out[121J= {Wl  N , w2  ) 2 kl m + k2 } The two normal modes correspond to the special cases c2 = 0 and cl = O. 
3.3 Small Oscillations 163 Consider the value of the parameters given by In [122J := values = {kl-+ 1, k2 -+ l,m-+ 1, "'1-+ 0, "'2 -+ O}; For simplicity, you collect all the appropriate rules into allRules: In[123J:= allRules = Join [xRule, freqrule, values]; Next,examinethefirstnormalmode{cl = 1, c2 = o}. UsePlottoplotthemo- tion of the two coordinates {xl [t] , x2 [t] } on the same graph separated by a distance of x = 2. In [124J : = ptla = Plot [ {xl [t] + 1, x2 [t] - 1}/ / .allRules/ /. {c1-+ 1, c2 -+ O} //Evaluate, {t, 0, 20}, PlotStyle -+ {{Thickness [0.01], Hue [0.6]}, {Thiokness[0.005],Hue[0.9]}} ] ; The top graph corresponds to the motion of x [1] and the bottom left is x [2] . From both plots, you can see that the motion is simple harmonic and the objects are in phase. Another way to display the motion is to use the command ParametricPlot and map the ttajectory ofthis system in the {xl [t], x2 [t]} plane. This path is known as a Lissajous figure, developed by the French physicist Jules Lissajous. A Lissajous pattern is a graph of one displacement plotted on the y axis combined with the second displacement plotted on the x-axis. In general, if the displacements are both periodic functions of the form x = Sin [wl t+c] and y = Sin [w2 t], then different patterns are generated for different values of wl and w2 and phase shift c. The simplest patterns are formed when the ratio of wl and w2 are rational numbers. Applying parametricPlot to our example with {cl1,c2O}, you get 
164 Chapter 3 Oscillating Systems In [125] ;= pt1b = parametricP10t [ {x1[t],x2[t]}//.a11Ru1es//. {c1-+ 1, c2 -+ O} //Eva1uate, {t, 0, 20}, Axes Label -+ {xl, x2}]; x2 xl The sttaight line means the two displacements are in phase. Next, examine the second normal mode {cl = 0, c2 = l} using the same types of graphics. The plot for the amplitudes follows from In[126]:= pt2a = Plot [ {x1[t] +l,x2[t] -1}//.allRu1es//. {c1-+ 0, c2 -+ 1} //Eva1uate, {t, 0, 20}, P1otSty1e -+ {{Thickness [0.01], Hue [0.6] }, {Thickness [0.005], Hue[0.9]}}, Disp1a.yFunction- > Identity] ; and the Lissajous path is In[127]:= pt2b = parametricP10t [ {x1[t],x2[t]}//.a11Ru1es//. {c1-+ 0, c2 -+ 1} //Eva1uate, {t, 0, 20}, Disp1aYl'unction- > Identity] ; Displaying the two graphs side by side, you get In[128]:= Show[GraphicsArray[{pt2a,pt2b}]]; 
3.3 Small Oscillations 165 The second normal mode (graphs on the left) is out of phase-one displacement is maximum while the other is a minimum. The sttaight line in the Lissajous figure is again indicative of the out of phase motion. Finally, examine a mixed mode { c 1 = 1, c2 = 1}. The plots for the displacements are In[129]:= pt3a = Plot [ {xl[t] +1,x2[t] -l}//.allRules//. {cl-+ 1, c2 -+ 1} / /Evaluate, {t,0,20}, PlotStyle -+ {{Thickness [0.01], Hue[O .6]}, {Thickness [0.005], Hue [0. 9]}} ]; The motion is a combination of harmonics with different frequencies. The phases and multiple frequencies create a Lissajous pattern that is not a simple curve; the pattern fills a rectangle. In[130]:= pt3b = parametricPlot [ {xl[t],x2[t]}//.allRules//. {cl-+ 1, c2 -+ 1} / /Evaluate, {t, 0, 50} ]; . PROBLEM 2 Three Coupled Oscillators along a Line. Consider the vibrations of three particles that are coupled by springs. 1\vo particles of mass m are symmetrically 
166 Chapter 3 Oscillating Systems located on each side of a third particle of mass M. All three particles are on a sttaight line. The three particles are joined by two springs with equal force constants k. Consider only vibrations along the line of the particles. Let x [1] , x [2] , and x [3] be the displacements from the equilibrium configuration for the three particles. xl x2 x3 a. Find the kinetic and potential energies for the system. Solve for the eigenfrequencies and eigenvectors. b. Write the general solution and plot the motion for the normal modes and for a mix- ture of normal modes. c. Animate one of the solutions. Remarks and Outline The eigenfrequencies and eigenvectors follow from the user- defined command smallOsc. The general solution is a linear combination of the normal modes. Solution In[13i]:= Clear [nGlobal ' * n] a. The kinetic and potential energies are In [132] := T =  m (X[l]' [t]2 +x[3]' [t]2)+ 1 - M x[2]' [t]2 ; 2 v= 1 -k 2 ( (x[2] [t] - x[l] [t]) 2+ (x[3] [t] -x[2] [t])2) ; where the coordinates are the displacements from the equilibrium positions. Again use the notation x [i] [t] so that you can easily index the coordinates. The eigenfrequencies and eigenvectors follow from the user-defined function smallOsc: In[133]:= solution = smallOsc [T, V, {x[l] [t], x[2] [t], x[3] [t]}, {O, 0, O}, t] 
3.3 Small Oscillations 167 Out[133J= o { 1 1 l } all) -> y:3 ' a(3) -> y:3 ' a(2) -> y:3 k 1 m 1 {all) -> Y2 ,a(3) ->- Y2 ,a(2) ->o} k (+) { M M Y2m } all) -> ,a(3) -> ,a(2) ->- Y2 y 2 m 2 + M 2 ...{i Y 2 m 2 + M 2 Y 2 m 2 + M 2 The first list is the square of the eigenfrequencies, w 2 ; the second contains the eigen- vectors. The first eigenfrequency, w 2 = 0, with eigenvector {  ,  ,  }, is not really an oscillation but represents a translational motion of all three masses. b. The general oscillatory motion follows from a superposition of the normal modes. Form the eigenmatrix: In [134J : = eigeDJDatrix = Array [a, 3] I. sOlution [[2] ] 1 y:3 1 Out [134J = ...{i M ...{i Y 2 m 2 + M 2 1 y:3 o ...{im Y 2m 2 +M 2 1 Y3 1 Y2 M ...{i Y 2 m 2 + M 2 The general solution follows from In[135J:= xRule = {xl [t], x2 [t], x3 [t]} -+ Transpose [eigenmatrix] . {c1t+"'l,c2 Cos[1I)2t+"'2], c3 COS [11)3 t + "'3] } I I Thread Out[135J= {xl(t) -> cl t + rj)l y:3 c2 Cos(rj)2+tw2) c3m Cos(rj)3+tw3) + ...{i ...{i Y 2 m 2 + M 2 cl t + rj)l ...{i c3 m Cos (rj)3 + t w3) x2 (t) -> -{3 - , x3 (t) -> 3 Y 2m 2 +M 2 clt+rj)l _ c2 Cos(rj)2+tw2) + c3m COS(rj)3+tW3) } -{3 ...{i ...{i Y 2 m 2 + M 2 + where the frequencies are given by solution [ [1] ]: In [136J := freqrule = {lI)l,1I)2,1I)3} -+ .y solution[ [1]] II Thread Out[136J= {Wl->O'W2->jg.'W3-» k (+)} 
168 Chapter 3 Oscillating Systems Thenormalmodescorrespondto{cl = 1, c2 = 0, c3 = O},{cl = 0, c2 = 1, c3 = O} and {cl = 0, c2 = 0, c3 = 1}. Note that {cl = 1, c2 = 0, c3 = O} corresponds to a zero frequency and is a pure ttanslation. Plot the motion of the three coordinates with the parameters given by In [137 J : = values = {k -+ 1, m -+ 1, M -+ 3, "'1 -+ 0, "'2 -+ 0, "'3 -+ O} ; Collect all relevant rules into allRules: In[138J:= allRules = Join [xRule, freqrule, values]; A user-defined procedure to plot {xl [t], x2 [t], x3 [t]} versus t on the same graph is In [139 J : = xPlot [Cl_, C2_, C3_] .- Plot [ {xl[t] +2,x2[t],x3[t] -2}//. allRules//. {cl -+ Cl, c2 -+ C2, c3 -+ C3} / /Evaluate, {t, 0, 20}, PlotStyle -+ { {Thickness [0.01], Hue[0.3]}, {Thickness [0.009], Hue[0.6]}, {Thickness [0.007], Eue[0.9]}}, AxesLabel -+ {t , x}, DisplayFunction- > Identity] ; The procedure xPlot plots {xl [t], x2 [t], x3 [tJ} as a function oftirne. The ttajectories are displaced relative to each other along the vertical axis. The input for the plot function is {Cl, C2, C3} . Another way to display the motion is to use a three-dimensional Lissajous figure. The user-defined procedure is In[140J:= xLPlot [CL, C2_, C3_, opts__] .- ParametricPlot3D[ {xl[t],x2[t],x3[t]}//.allRules//. {cl-+ Cl, c2 -+ C2, c3 -+C3} //Evaluate, {t, 0, 20}, BoxRatios -+ {l, 1, l}, AxesLabel -+ {xl, x2, x3 } , opts, Displa.yFunction- > Identity] ; The user-defined xLPlot plots {x [1], x [2], x [3]} using a three-dimensional parametric plot. The input opts___ allows you to add options to the graphics. 
3.3 Small Oscillations 169 Let us apply the two plot functions to the trivial first normal mode {c 1 = 1, c2 = 0, c3 = O}. The plots for the motions are In[141]:= Show[GraphicsArray[ {xP1ot [1,0,0], xLP10t [1,0,0, Ticks -+ None]}]]; x  X3 xl The curves on the left are for {x [1] ,x [2] ,x [3]} versus t. The top curve is x [1] followed by x [ 2] and x [3] . Note that this corresponds to a pure ttanslation for all co- ordinates, which is why the eigenfrequency was zero. The parametric plot on the right is trivial for this case. Next, display the second normal mode {c1 = 0, c2 = 1,c3 = O}. The two plots are In[142]:= Show[GraphicsArray[ {xP1ot [0,1,0], xLP10t [0, 1, 0 , Ticks -+ None, ViewPoint -+ {1, 1, 1}] } ] ; x xl x3 Note, masses 1 and 3 are out of phase, while mass 2 (center curve) is stationary with respect to the others. Display the third normal mode { c1 = 0, c2 = 0, c3 = 1}: In[143]:= Show[GraphicsArray[ {xP1ot[0, 0, 1], xLP10t [0,0,1, Ticks -+ None]}]]; 
170 Chapter 3 Oscillating Systems at ft1 X3 Q xl x Masses 1 (top curve) and 3 (bottom curve) are in phase, while mass 2 is out of phase. Finally, display a mixed mode {cl = 0, c2 = 1, c3 = I} (keep cl = 0, since this mode is trivial). The plots for {x[I], x[2], x[3]} are In[144]:= Show[xPlot[O,l,1], DisplayFunction -+ $DisplayFunction] ; x t and the parametric plot follows from In[145]:= Show [xLPlot [0,1,1, ViewPoint -+ {1, 1, 1 }], DisplayFunction -+ $DisplayFunction] ; x3 
3.3 Small Oscillations 171 c. To animate the solution, use ListPlot inside a Do loop to generate the individual graphic frames. Here, take the mixed mode {c1 = 0, c2 = 1, c3 = 1}. Choose the number of frames to be In [146J : = number = 1 (* for more frames make number larger *) ; then In [147] : = Do [ListP1ot [ {{xl [t] - 2, O}, {x2 [t], O}, {x3 [t] + 2, O}}I I .allRu1es 11.{c1-+ 0, c2 -+ 1, c3 -+ 1} l/Eva1uate, P1otSty1e -+ {pointSize [0 .05] }, PlotRange -+ {{ -4, 4}, {-1, 1)}], {t, 0, 1 - 1/number, 1/number}]; 1 0.75 0.5 0.25 .4 -3 .2 -1 1 -0.25 -0.5 -0.75 -1 3 4 Only one frame has been kept. To animate the results double-click on any of the graphics and use the menu to adjust the speed. . PROBLEM 3 Three Coupled Oscillators along a Circle. Three mass points have equi- librium positions at the vertices of an equilateral triangle. They are connected by equal springs that lie along the arcs of the circle circumscribing the triangle. Mass points and springs are consttained to move only on the circle so that the potential energy of a spring is determined by the arc length considered. a. Let two of the masses be the same and the third mass be different from the first two. Determine the eigenfrequencies and normal modes for small oscillations in the plane of the circle. b. Take the limit as all the masses become equal. c. Plot the normal mode solutions. 
172 Chapter 3 Oscillating Systems Solution In[148]:= C1ear[nG1oba1' * n] a. Choose polar coordinates with the origin at the center of the circle and let r be the radius of the circle. Let () [ 1] , () [ 2] and () [3] be the angular displacement as measured from the equilibrium positions. The kinetic and potential energies are In[149]:= T= ! r A 2 2 (m 8[1]' [t]2 +m 8[2]' [t]2+ m1 8[3]' [t]2) ; v= ! kr A 2 2 (8[2] [t] -8[1] [t])2+ (8[3][t] -8[2][t])2+ (8[1] [t] -8[3] [t])2); where the coordinates are the displacements measured from the equilibrium positions. The eigenfrequencies and eigenvectors follow from the user-defined function smallOsc: In[150]:= eq1 = smallOsc[T,v, {8[1] [t],8[2] [t],8[3] [t]}, {O, 0, O}, t] / /Sim,plify / /powerExpand 
3.3 Small Oscillations 173 Out[150]= o { II I } a(l) -> -f3 ' a(2) -> -f3 ' a(3) -> -f3 3k 1 m 1 {a(l) -> ,f2 ,a(2) ->- ,f2 ,a(3) ->o} k ( 2.+ ) m1 m { 2m ym - m1 a(3) -> , y 4 m 3 - 4 m1 m 2 + 2 m1 2 m - 2 m1 3 ym-m1 m1 a (1) -> Y 4 m 3 - 4 m1 m 2 + 2 m1 2 m - 2 m1 3 ' ym-m1 m1 } a (2)-> y 4 m 3 - 4 m1 m 2 + 2 m1 2 m - 2 m1 3 The elements in the first list contain the squares of the eigenfrequencies; the remain- ing lists are the eigenvectors. The zero eigenfrequency is not an oscillation but is just a displacement of the particles in the same direction. To get the equal mass case you set ml = m, In[151]:= solution = Limit [eql, ml- > m] / / PowerExpand Out[151]= o { II I } a(l) -> -f3 ' a(2) -> -f3 ' a(3) -> -f3 3k { 1 m 1 } a(l) -> ,f2 ' a(2) -> - ,f2 ' a(3) -> 0 3k m {a(3) -> H, a(l) -> -  , a(2) -> -  } This solution is very degenerate and it is obvious that any permutation of the particles is also a solution. b. Consider the equal mass case and plot one of the normal mode solutions. The general oscillatory motion follows from a superposition of the normal modes. Form the eigen- matrix: In [152] := eigemaatrix = Array [a, 3] /. solution [ [2]] Out[152]= 1 I f ,f2 1 - yr, 1 V3 1 - ,f2 1 yr, X I 1 
174 Chapter 3 Oscillating Systems The general solution follows from In[153]:= solrule = {81 [t], 82 [t], 83 [t] } -+ Transpose[eigenmatrix]. {cl t + phasel, c2 COS [freq2 t + phase2], c3 COS [freq3 t + phase3]} / /'l'hread; where the frequencies are given by solution [ [1] ] : In[154]:= freqrule = {freql, freq2, freq3} -+ Sqrt [solution [ [1]]] / /'l'hread Out[154]= {freql-> 0, freq2 -> -fj j¥, freq3 -> -fj j¥} Note that c1 corresponds to a pure ttanslation with zero frequency. The normal mode oscillations correspond to {c1 = 0, c2 = 1, c3 = O}, and {c1 = 0, c2 = 0, c3 = 1}. To be specific, we choose the following values: In [155] : = valuerule = {k -+ 1, m -+ 1, phasel -+ 0, phase2 -+ 0, phase3 -+ O} ; A plot function for 01 [t], (}2 [t] and 03 [t] is In[156]:= xPlot[CL,C2_,C3.]:= Plot [ {81[t] +2,82[t],83[t] -2} /.solrule/. freqrule//.valuerule//. {cl -+ Cl, c2 -+ C2, c3 -+ C3} / /Evaluate, {t,O,20}, plot style -+ { {Thickness[0.012]}, {Thickness[0.008]}, {Thickness [0.004]}}, Displayl'unction- > :Identity] ; Display the nontrivial normal modes {c1 = 0, c2 = 1, c3 = O} and {c1 = 0, c2 = 0, c3 = 1}: In[157]:= Show[GraphicsArray[ {xPlot [0,1,0], xPlot [0,0,1] }]]; :o :c 
3.3 Small Oscillations 175 The top curves are for 01 [t] followed by 02 [t] and 03 [t]. The normal mode motion for {c1 = 0, c2 = 1, c3 = o} (left graph) has masses 1 and 2 out of phase while mass 3 is stationary with respect to the others. The second normal mode solution with {c1 = 0, c2 = 0, c3 = 1} (right graph) has masses 1 and 2 in phase while mass 3 is out of phase. . PROBLEM 4 Double Pendulum. Consider a double pendulum consisting of a massless rigid rod. The first segment of the rod has one end fixed and the other supporting a particle of mass m1. The length of this segment is L1. Attached to m1 is another segment of lenglh L2. At the other end of the second segment is a particle of mass m2. Assume the motion is confined to a plane. a. Find the normal modes for small oscillations. b. Plot the normal modes and mixed modes for the motion of the mass points for one cycle. c. Animate one of these solutions. Remarks and Outline The eigenfrequencies and eigenvectors follow from the user- defined command smallOsc. The general solution is a linear combination of the normal modes. Solution In [158] : = Clear [nGlobal' * n] 
176 Chapter 3 Oscillating Systems a. The coordinates of the masses are {xl, yl} and {x2, y2}. Let 01 [t] and 02 [t] be the angles between the vertical line formed by the first and second rods, respectively. Expressing the mass points in polar coordinates, you have In[159]:= xl = Ll Sin[81[#] ]&; yl = Ll Cos [81 [I] ] &; x2 = xl [I] + L2 sin [82 [I]] &; y2 = yl [I] + L2 Cos [82 [I] ] & ; Use pure functions so that these definitions also apply to derivatives. For simplicity, let Ll = L2 = leD: In[160]:= Ll = L2 = len; The kinetic and potential energies for the two masses are In[161]:= '1'1 = 1/2 ml(xl'[t]A2 +yl'[tr2); '1'2 = 1/2 m2(x2'[tr2 +Y2'[t]-2) Vl = - mlg yl [t]; V2 = -m2gy2[t]; '1' = '1'1 + '1'2 ; V=Vl+V2; The eigenfrequencies and eigenvectors follow from the user-defined command smal- lOse: In [162] : = solution = smallOse ['1', v, {81 [t], 82 [t]}, {O, O}, t] g (ml+m2 -Vm2) lenml { yml +m2 Vm2 } a(2)-> ,a(l)-> y ml + 2 m2 y ml + 2 m2 Out[162]= g (ml +m2 + Vm2 ) lenml { yml +m2 Vm2 } a(2) -> ,a(l)->- y ml + 2 m2 y ml + 2 m2 b. To consttuct the general solution, define the eigenmatrix: In [163] : = eigemaatrix = Array [a, 2] / / . solution [ [2] ] Vm2  Out [163]= [ y ml + 2 m2 y ml + 2 m2 ] Vm2  - y ml + 2 m2 y ml + 2 m2 
3.3 Small Oscillations 177 The general solution will be a linear combination of normal modes with relative ampli- tudes {cl,c2}: In[164]:= thetaRule = {8l[t],82[t]} -+ Transpose[eigenmatrix]. {cl Cos [lIJl t + 1], c2 Cos [1IJ2 t + 2]} I I 'l'hread I I sin\plify { Vi.ii2 (cl Cos (rjJl + t wl) - c2 Cos (rjJ2 + t w2) ) el (t) -> , y ml + 2 m2 e2 (t) ->  (cl Cos (rjJl + t wl) + c2 Cos (rjJ2 + t w2)) } y ml + 2 m2 Out[164]= where wl and w2 are the eigenfrequencies and cpl and cp2 are the phases of the normal modes. The frequencies are given by the first list of the results returned by smallOsc: In[165]:= freqrule = {1IJ1, 1IJ2} -+ sqrt [solution [ [1]]] II 'l'hread Out[165]= {Wl-> g (ml + m2 - Vi.ii2 yml + m2 ) lenml w2 -> g (ml + m2 + Vi.ii2 yml + m2 ) } lenml Plot the motion of the two mass points for the values In[166]:= values = {m1-+ 3, m2 -+ 1, len -+ 1, g -+ 1, 1-+ 0, 2 -+ O}; Collect all relevant rules into allRules: In[167]:= allRules = Join [thetaRule, values, freqrule] ; Next create a graphic object that represents the two rods of the pendulum. The line comes from connecting the origin {O, O} with the coordinates of the first rod {xl [t] ,yl [t]}, and the second rod {x2 [t] ,y2 [t]}. Make this graphic object a function of { c 1, c2} so that you can vary the relative weights of the normal modes. In[168]:= line [c1_, c2_] = Line[{{O, O}, {x1[t], -Y1[t]}, {x2[t],-y2[t]}}]II.allRules; The graph forthe normal mode described by {cl = 1, c2 = O} is 
178 Chapter 3 Oscillating Systems In[169]:= Show[ Graphics [Table[N[line[1, 0]], {t, 0,4, 0.1}]]]; Note that this is a symmetric mode in the sense that the two rods are moving in the same direction. The graph for the second normal mode described by {cl = 0, c2 = l} is In[170]:= Show[ Graphics [Table[N[line[O, 1]], {t, 0,2.5, 0.2}]]]; Note that this is an antisymmetric mode in the sense that the two rods are moving in opposite directions. The graph for a mixture of normal mode states {cl = 1/2, c2 = 1/2} is In[l71]:= Show[ Graphics[Table[N[line[0.5,O.5]], {t, 0, 6, 0.2}]]]; 
3.3 Small Oscillations 179 This motion appears complex; however, this solution can be understood more com- pletely by animating this mode. c. The animation of this last case follows from enclosing the Show command inside a Do loop: In [172] := frames = 1; Do [Show [Graphics [N[line[0.5, 0.5]], P1otRange- > -2, 2, 0, -2]], t, 1, 25, 25/frames]; Only one frame has been kept. Increase the number of frames. To animate the results double-click on any of the graphics and use the menu to adjust the speed. Note the charac- teristic behavior. The top rod leads, and then the bottom rod follows. It appears as though only one rod is moving significantly at any time. . PROBLEM 5 Understanding the User-Defined Procedure smaIlOsc[]. How does the user-defined function smallOsc work? Solution In[173]:= C1ear["G1oba1' *"] To see how this works examine the intermediate results. Do this by eliminating the local variables by executing a related function smallOsc2 with the modification: 
180 Chapter 3 Oscillating Systems In[174] : = smallOsc2 ['1'_, v., coord_List, equlib..List, t_ :t] := Module [ { } , q = coord; p = D[coord, t]; dim = Length[q]; equlibRule = 'l'hread[coord -+ equlib]; Vij = Outer [D [V, #1, #2] &, q, q ] ; '1'ij = Outer [D['1', #1, #2]&, p, p]; matrix = Vij - 1A/2 '1'ij / .equlibRule; 1A/2Sol = Simplify [Solve [Det [matrix] == 0, 1A/2]]; freq = 1A/2/ .1A/2Sol; vector = Array [a, dim]; eqs = Simplify [ ExpandAll [ 'l'hread[O == matrix.vector]]]; vSol = Table [ Solve[Join[eqs/.1A/2Sol[[i]], {vector. vector == 1}] , vector] [ [2]], {i, 1, dim}] ; {freq, vSol} ] Here the local variables have been removed from the statement Module [ {} . . . ] . Consider two equal masses that are described by the kinetic and potential energies: 1 1 In[175]:= '1'=-m ql'[t]2+- m q2'[t]2, 2 2 V= kl (q2[t] _ql[t])2; 2 The eigenvalues and eigenfunctions for small oscillations are In[176]:= smallOsc2 ['1', v, {ql[t], q2 [t]}, {O, O}, t] Out[176]= [ 1 1 {a(l) -> -j2 a(2) -> -j2 } 2 kl 1 m 1 {a(l) -> -j2 ,a(2) ->- -j2 } Examining the internal variables, it is obvious that q is the coordinate list, p is the velocity (momentum) list, and dim is the dimension of normal modes: In[177]:= {q,p,dim}//columnForm {ql (t) , q2 (t) } Out[177]= {ql' (t), q2' (t)} 2 The equilbList is the list of equilibrium positions; convert this into equlibRule so that you can make the appropriate replacements: 
3.3 Small Oscillations 181 In[178):= equlibRule Out[178)= {ql (t) -> 0, q2 (t) -> 0) Vij and Tij are the potential and kinetic energy tensors, respectively: In[179):= {Vij,Tij}//ColumnForm Out[179)= ( kl -kl -kl kl ( ) Note the use of OUter to compute the derivative of these matrices with respect to the appropriate coordinates. The matrix is formed from V;j - w 2 Tij and the solutions of the determinate of this matrix yield the square of the eigenfrequencies: In[180):= 1A/2So1 Out[180)= {{W2->OL {W2-> 2:1 }} This procedure may fail if the algebraic solution cannot be found or is returned with complex terms even though the solutions are real. To find the eigenvectors, solve the equa- tion matrix. vector = 0 with various w2 values given in w2Sol. For example, the eigenvector associated with the first eigenfrequency is In[181):= SOlve[Join[eqs/.1A/2So1[[1]], {vector .vector == l}], vector] Out[181)= {{a(l) ->-  ,a(2) ->-  }, {a(l) ->  ,a(2) ->  }} Note that you get two solutions. Select the second of these with [[2]]. Using the Table command, collect all eigenvectors associated with all eigenfrequencies. You finally get the list of eigenfrequencies and eigenvectors: In[182):= {freq,vSol} Out[182)= [ 1 1 {a(l) -> 12 a(2) -> 12 } 2 kl { 1 m 1 } a(l) -> 12 ' a(2) -> - 12 Certainly this procedure can be made more time efficient and additional defaults and options can be added to the procedure. The eigensystem could have been solved using the built-in functions Eigensystem, Eigenvectors, and Eigenvalues. The user- defined procedure will fail in special cases so you are encouraged to write conditional statements to handle these cases. Again, we emphasize that our goal is to solve the physics, not to write an all-purpose foolproof package. . 
182 Chapter 3 Oscillating Systems 3.4 . OSCILLATING CIRCUITS 3.4.1 . Overview One of the most familiar oscillating electrical systems is a circuit with a resistance, capac- itance and inductance. The analysis of such a system has a remarkable similarity to the mechanical systems we have been concerned with so far. One of the simpler circuits con- sists of a time-dependent emfV[t], a resistance R, and a capacitor C, connected in series. The equation for the charge is V[t] = q[t] + R q'[t] C The capacitor is a device for storing electric charge and the associated electtostatic potential energy. If you replace the capacitor with an inductor, then the circuit is described by V[t] = R q'[t] + L q"[t] The charge q[t] is related to the current ![t] by dt] = ![t]. In the case of a series circuit that contains all four-an electtomotive force V[t], in- ductance L, capacitance C, and resistance R-then the basic equation for the charge q[t] is L q"[t] + R q'[t] + q] = V[t] This is precisely like the basic differential equation for a harmonic oscillator that has a damping and a driving term. The charge q plays the role of the displacement x, L appears in the place of mass, C replaces the spring constant k, and the resistor R causes damping. . PROBLEM 1 Series RC Circuit. Consider a circuit consisting of a time-dependent emf V [t] , a resistor R, and a capacitor C, connected in series. a. Solve for the charge q [t] with an arbittary V [t] . b. Evaluate the general solution found in Part a when V[t] = VO Cos [w t] and q[O] = qO. c. Make a two-dimensional plot of the charge as a function of t. Make a three- dimensional plot of the charge as a function of t and C. Remarks and Outline Part a shows how DSol ve returns a symbolic solution for the first-order RC differential equation. Solution In[183]:= Clear ["Global ' * 0]; 
3.4 Oscillating Circuits 183 a. The charge q[t] in the RC circuit obeys the differential equation In[184]:= eq1=V[t] ==Rq'[t] +q[t]/c q(t) Out[184]= V(t) == c- + Rq' (t) Solving eql for q [t] with an arbittary voltage V [t] , you get In [185] : = dsol = DSolve [eq1, q[t], t] [ [1] ] Out[185]= {q(t) ->e. iR c 1 + _....t.... rt K$1756 e CR J K$1757 e CR : (K$1756) dIK$1756 } b. The dsol for the potential vo Cos [w t] becomes In[186]:= V[t_] =vo Cos[wt]; q [t.] = q[t] / .dsol/ / Simplify Out[186]= 1 ( t e- ER c 2 R 2 w 2 + 1 ( K$1757 R 2 W 2 c 1 c 2 -e CR RVOwSin(K$1757w)C 2 + eiR RVOw Sin(tw) c 2 _e K$57 VO Cos(K$1757w) c+eiRvO Cos(tw) C+c 1 )) Expressing C [1] in terms of the initial conditions q [0] = qO, you get In[18?]:= c1So1=Solve[q[O] ==qO,C[l]][[l]] Out[187]= [ ill122 { e CR RVOwSin(K$1757w)C 2 C 1 -> c 2 R 2 w 2 + 1 + K$1757 e CR vO Cos (K$1757 w) C c 2 R 2 w 2 + 1 VOC - + c 2 R 2 w 2 + 1 )jr C2 R 2 w 2 1 J qO c2 R2 w2 + 1 + c 2 R 2 w 2 + 1 } and the solution for the charge becomes In[188]:= q[t_] = q[t] / .c1Soll /PUll Sill\Plify Out[188]= 1 ( e.iR ( C2qOR2W2+qO_ c 2 R 2 w 2 + 1 cvO + c e iR vO (Cos (t w) + C Rw Sin (t w)) )) c. The plot of the charge as a function of time for the parameters 
184 Chapter 3 Oscillating Systems In[189]:= valuesl = {qO ...1, VO ...1, C ...1, R ...1, W'" 6}; is In[190]:= Plot [q[t]/.valuesl //Evaluate, {t, 0, 6}, AxesLabel... { "time", "charge"}, PlotLabel... "RC LOop"]; charge 1 RC Loop 0.4 0.2 1 A three-dimensional plot of the charge as a function of the variables t and C is In[191]:= values2 = {qO...l,VO...l,R...l,w...6}; In [192] := Plot3D[q[t] / .values2 / /Evaluate, {t,0,6}, {C, 0.01, 0.25}, AxesLabel... {nTime n , "Capacitance", "Charge"}, Ticks... {Automatic, {0.01, 0.1, 0.2 }, Automatic}, l!'aceGrids... HO, -1, O}}, ViewPoint... {0.3, -1, 0.3}, Plotpoints ... 35] ; Charge 6 . PROBLEM 2 Series RL Loop. Consider a circuit consisting of a time-dependent emf V[t] = va Cos [w t], a resistor R, and an inductor L connected in series. 
3.4 Oscillating Circuits 185 a. Solve for the charge q [t] and the current q' [t]. b. Make a two-dimensional plot of the charge and current as a function of t for the initial condition q [0] = o. c. Take the Fourier ttansform of the data formed by the solution of the charge found in part b. Include a random error to make the data table appear more like the results of an actual measurement. Remarks and Outline This problem follows from applying DSol ve to the circuit equa- tion. In part c, you see how the Fourier ttansform shows the periodic behavior of the oscil- lating system. We make use of the package Statistics 'NormalDistribution' to generate a normal error distribution. Solution In[193J:= Clear [RGlobal ' * 0]; a. The time dependence of the charge is described by the equation In[194J:= eql=V[t] ==Lq"[t] +Rq'[t] Out[194J= V(t) == Rq' (t) + Lq" (t) Assume the voltage V[t] and initial conditions are In[195J:= V[t_] =vo cos[wt]; initial = {q[O] == qO, q' [0] == iO}; Applying DSol ve to eql, you get In [196J := qsol = q[t]/. (DSolve[{eql,initial}//Flatten, q[t],t]l/Flatten// Sill\Plify} Out[196J= (e-¥ (e¥vo Sin(tw) R 2 + w ( ( - 1 + e ¥ ) iO L (R 2 + L 2 W 2 ) + R (L VO + e ¥ qO (R 2 + L 2 w 2 ) ) ) ) _ LRVOw Cos(tw) )/(RW (R 2 +L 2 w 2 )) The current follows from the derivative of the charge: In [197J : = isol = D[qsol, t] / /l'ullSimplify 
186 Chapter 3 Oscillating Systems Out[197]= 2 1 2 2 ( e.¥ ( iOR2_VOR+ R +L w iO L 2 W 2 + e¥ VO (R COS (tW) + Lw Sin(tW)))) b. For the values of the parameters, In[198]:= values = {R... 0.1, L... 2, VO ...1, tAl... 1, iO... 0.1, qO... O}; the graphics for the current and charge are In [199] := Plot [{qsol, isol}/.values //Evaluate, {t, 0, 20}, PlotStyle ... { {Hue[0.3], Thickness[O.Ol]}, {Hue[0.9],Dashing[{0.03}], Thickness[0.02]}}, Frame ... True, FrameLahel... { nTime n , n n }, GridLines... Automatic]; Here you see that the current (dashed line) oscillates in a regular fashion, but the charge through the circuit (solid line) is slowly accumulating. c. It follows from qsol that the charge has periodic terms of the form Cos [w t] and Sin[w t]. The Fourier ttansform is the basic tool for analyzing such oscillating systems. To Fourier-analyze the time dependence of the charge, generate a 300-item list of q [t] for the parameters given by values. We add a random error using the package Statistics'NormalDistribution'. In[200]:= «Statistics'NormalDistribution' 
3.4 Oscillating Circuits 187 In[201J:= fourierdata = Table [ qsol RandomArray[NormalDistributiOD[ 1,0.1],1] [[1]] l.valuesllN, {t, 0, 100 1f, 100 1f/300}] ; The Fourier ttansform of the data and the plot of its absolute value is In[202J:= ListPlot[ Abs[Fourier[fourierdata]], PlotJoined -+ True, PlotStyle -+ Hue [Random] , PlotRange -+ {O, 5}]; 5 4 3 2 1 50 100 150 200 250 300 This graph shows a sttong peak at 50 and another at 250 due to aliasing; this result is expected from the Fourier ttansform of the data generated. . PROBLEM 3 RLC Loop. Consider an RLC circuit consisting of an emf V = 0, aresis- tor R, an inductor L, and a capacitor C connected in series. a. Solve the RLC circuit by taking the Laplace ttansform of the circuit equation. b. Make a two-dimensional plot of the charge and current as a function of time. Make a three-dimensional plot of the charge as a function of t and L. Remarks and Outline Although DBol ve will solve the RLC differential equation, LaplaceTransform is used to illusttate how this method can be used to solve certain differential equations. Solution In [203J : = Clear ["Global ' * 0] ; a. The differential equation for the charge q [t] in an RLC circuit is 
188 Chapter 3 Oscillating Systems In[204]:= eql = Lq" [t] + Rq' [t] + q[t] Ie == 0; Taking the Laplace ttansform of eql, you get In[205]:= eq2 = Lap1aceTransform[eql, t, s]IISim;p1ify 1 Out[205]= c((Cs (R+Ls) +1) LaplaceTransfonn[q(t),t,s]- C (Rq(O) + L (s q(O) + q' (0)))) == 0 It follows from the algebraic solution of eq2 that the Laplace ttansform of q [t] is: In [206] := solO = Solve[eq2,Lap1aceTransform[q[t],t,s]][[ 1]] Out[206]= {LaplaceTranSfOnn[q(t), t, s] -> C (Rq(O) +L (sq(O) +q'(O))) } Cs(R+Ls)+l Assume the initial conditions In[207]:= initial = {q[O] ... qO, q [0] ... iO}; and take the inverse Laplace ttansform of solO: In [208] := eq3 = InverseLap1aceTransform[ Lap1aceTransform[q[t],t,s]/.so10/. initia1,s,t]llru11Simp1ify Out[208]= Ie. R+ VCR24L t yc II t )  l+e  CR 2 - 4LqO+ I t l 11/ jC - 1 + e  (2 iO L + qO R) (2  CR2 - 4L) The expression for the charge is rather cumbersome, but can be simplified if you define the frequency w0 2 = 4I;;;;if' . This notation is implemented with the rule In [209] : = freqru1e = e R 2 - 4 L... -4 e L 2 1110 2 ; 
3.4 Oscillating Circuits 189 With this change in notation the expression for the charge simplifies to In[210J:= charge = eq3/ / .freqrule/ /PowerExpand / / ExpToTrig// FullSimplify Out [210J = Rt e. u (2LqOwO Cos(twO) + (2iOL+qOR) sin (twO)) 2 LwO The current follows from the time derivative of the charge: In[211J:= current = D[charge, t] //FullSimplify 1 ( Rt . 2 Out[211J=  e. TI (4J.OL wOCos(twO)- 4 L wO (2 iO LR+ qO (R 2 + 4 L 2 w0 2 )) Sin(twO))) b. Consider the parameters In [212J := values = {R"'l, C ...1, L... 4, qO ...1, iO... O}; for the plots of the charge and current. The value of wO follows from In[213J:= lllrule = Solve [ "" CR 2 - 4 L == 2 i .ycLIIIO, 1110] [[1]] { i Y CR2_4L } Out[213J= wO->- 2 ...;c L The labels for the graphs follow from In[214J:= text = {Text [Stylel!'orm ["Charge" , I!'ontl!'amily- > "Times - Bold", l!'ontSize- > 15] , {5, 0.8}] , Text [stylel!'orm["CUrrent" , I!'ontl!'amily- > "Times - Bold", l!'ontSize- > 15], {8, 0.3}]}; Adding the labels to the curves with the option Epilog, the plot of the charge and current is 
190 Chapter 3 Oscillating Systems In[215J:= Plot[{charge,current}/.wrule/.valuesll Evaluate, {t, 0.001, 20}, PlotStyle -+ { {Hue[0.3],DaShing[{0.01}], Thickness[O.Ol]}, {Hue[0.9],Dashing[{0.02}], Thickness[0.008]}}, Frame -+ True, FrameLabel-+ {"Time", no}, GridLines -+ Automatic, Epilog -+ text] ; 1 0.8 0.6 0.4 0.2 o .0.2 -0.4 o 5 10 Time 15 20 To study the effects of inductance on the charge, consider a three-dimensional plot of the charge as a function of the variables time and inductance L. For the parameters In [216J : = values2 = {R -+ 1, C -+ 1, qO -+ 1, iO -+ 1}; the plot of the charge is In[217J:= pl = Plot3D[charge/.wrule/.values2 II Evaluate, {t, 0.01, 30}, {L,l,4}, ViewPoint -+ {1, +3,1}, FaceGrids -+ {{O, 0, 1}, {O, -1, On, AxesLabel -+ {"Time", ":rnductance", nCharge n }, Plotpoints -+ 30]; 
3.5 Exercises 191 Inductance 2 o Charge .0.5 30 Time 3.5 . EXERCISES The solutions to many of these exercises can be found on our web site. 3.1 Blocks Connect with a Spring on a Thble Two identical blocks A and B, both of mass M, are connected by a spring of length L and spring constant k. Initially, they are at rest on a frictionless straight track. At t = 0, block A is hit sharply, giving it an instantaneous velocity vO to the right. Find the motion for subsequent times. 3.2 Falling Blocks Connect with a Spring Two masses ml and m2 in a unifonn gravitational field are connected by a spring of unstretched length h and spring constant k. The system is held by ml so that m2 hangs down vertically, stretching the spring. At t = 0, both ml and m2 are at rest and ml is released, so that the system starts to fall. Find the subsequent motion. 3.3 Parabolic Coordinates and Harmonic Oscillator Parabolic cylindrical coordinates {g, 1], z} are defined by the equations x = g1], y = (1]2 _ g2), and z = z. Consider a three-dimensional isotropic harmonic oscillator. (a) Express the equations of motion in parabolic cylindrical coordinates. (b) Solve the equations and plot several solutions. 3.4 Forced Oscillator Consider the motion of a forced oscillator fO x"[t] + w0 2 x[t] = - cos[wt] m (a) Find the general solution. (b) Assume wO '" w and plot the motion. Illustrate the beats and the envelope. 3.5 Pendulums and Spring Consider a pair of identical simple pendulums of mass m and length b connected to each other through a massless spring, whose spring constant is k. (a) Write the solution in the fonn of its nonnal modes. (b) Graph the nonnal modes and a mixed mode solution. 
192 Chapter 3 Oscillating Systems 3.6 Five Particles Connected with Springs Consider the vibrations of five particles that are coupled by springs. The first particle has mass m, the second M, the third m, the fourth M, and the fifth m. All five particles are on a straight line and the particles are joined by four springs with the same force constants k. Consider only vibrations along the line of the particles. (a) Find the kinetic and potential energies for the system. Solve for the eigenfrequencies and eigenvectors. (b) Write the general solution and plot the motion for the normal modes and for a mixture of normal modes. (c) Animate one of the solutions. 3.7 Vibrating Atoms on an Equilateral Triangle The equilibrium configuration of a molecule is represented by three atoms of equal mass on the vertices of an equilateral triangle connected by springs of equal force constant. Consider only vibrations in the plane of the particles. (a) Find the kinetic and potential energies for the system. Solve for the eigenfrequencies and eigenvectors. (b) Write the general solution and plot the motion for the normal modes and for a mixture of normal modes. (c) Animate one of the solutions. 3.8 Vibrating Charged Spheres Two small metal spheres of equal mass m and equal charge Q are suspended by insulating threads of equal length b from two points separated by a distance a on the same horizontal line. (a) Find the kinetic and potential energies for the system. Solve for the eigenfrequencies and eigenvectors. (b) Write the general solution and plot the motion for the normal modes and for a mixture of modes. (c) Animate one of the solutions. 3.9 Quadratic Damping The form we used in the damped harmonic oscillator for the damping force, the term propor- tional to x' [t], was chosen mainly for analytic simplicity, although it is a fair approximation. Discuss the damped harmonic oscillator when the damping term is proportional to x [tf. 3.10 Motion of a Charged Particle in a Harmonic Potential A particle in an isotropic three-dimensional harmonic oscillator potential has a natural frequency of wO. Assume the particle is charged and that crossed static electric and magnetic fields are applied. Find the vibration frequencies with these electromagnetic fields present. Discuss the results for the limits of strong and weak fields. 
CHAPTER 4 Nonlinear Oscillating Systems 4.1 . INTRODUCTION The study of systems whose behavior is described by nonlinear differential equations in- volves a deeper investigation of vibrational processes than does the study of linear systems. Given the initial conditions, the solution of a time dependent differential equation describes the state of the system at a later instant. In a linear system the sum of two solutions is again a solution, but this principle of superposition fails to hold for nonlinear systems. Conse- quently, the outcomes of nonlinear systems cannot be understood by adding together two solutions. For nonlinear systems, each solution must be sought on an individual basis. In this chapter we consider oscillating systems that are described by nonlinear differential equations. For systems described by nonlinear differential equations, it is advantageous to study the solutions in terms of phase planes. Such a representation appeals to geometric intu- ition, simplifies the interpretation, and allows one to classify the different behaviors. For example, consider a system with one degree of freedom described by a second-order dif- ferential equation of the form x"[t] + f[x[t]x'[t], t] = 0 If you define v[t] = x'[t], then this equation can be expressed as two first-order equations v'[t] = -f[x, v] and x'[t] = v[t] Each point in the plane {x, v} represents an individual state, or an initial condition of the system. The curve in the {x, v} space is called the orbit or ttajectory. Once the initial position and velocity of each particle are given, the future motion is determined, at least in principle. The collection of all possible states is called the phase space of the system. If v'[t] = 0 and x'[t] = 0 then the point is an equilibrium point (critical point). As the parameters are changed in a system, the stability of the equilibrium points can change as well as their number. 193 
194 Chapter 4 Nonlinear Oscillating Systems A periodic ttajectory is a closed curve that returns to itself precisely in a time T, called the period. A periodic ttajectory can be stable or unstable, depending on whether nearby ttajectories tend toward or away from the periodic cycle. An atttactor is a set of points in phase space toward which a ttajectory evolves as time gets large. Thus in a dissipative system the long-term behavior of a ttajectory may settle into an atttactor. For example, imagine a ball rolling inside a bowl with no angular momentum. If you start the ball at a point in the bowl with a velocity too small to reach the edge of the bowl, the ball will eventually settle to the bottom of the bowl. This position at the bottom of the bowl is an attractor. The neighborhood of initial conditions that eventually approach the atttactor is the basin of atttaction. Some motions are explained, while others-such as the shifting patterns of a waterfall- are irregular and appear to defy any rule. A small difference in their initial conditions can lead to enormously different results. In practice this leads to a state of the system that is essentially unknown after a very short time, and it becomes impossible to make predictions. This sensitivity on the initial conditions is called chaos. The behavior of a chaotic system is not random, since the ttajectory of a chaotic system with identical initial conditions always lead to the same results. The idea that deterministic systems can behave in an apparently unpredictable and chaotic manner was first noticed by the French mathematician Henri Poincare. However, chaos was not fully appreciated until the widespread availability of computers that could perform numerical simulations and demonsttate chaos in various physical systems. Chaos has broad implications for many fields of science, and within the past decade or so the field has undergone explosive growth. One important application of chaos in physics is to quantum systems. According to the correspondence principle, there is a limit where classical behavior as described by Hamilton's equations becomes similar. The semiclassi- callimit can be higWy nontrivial when the classical problem is chaotic. The study of how quantum systems, whose classical counterparts are chaotic, behave in the semiclassical limit has been called quantum chaos. Several tools can be developed to examine nonlinear systems. If the solution of the dif- ferential equation contains terms periodic in time, then to simplify its phase diagram it is useful to make a sttoboscopic map. The map effectively looks at points in phase space with a sttoboscope tuned to a period T. This map is called a Poincare section. The Poincare section simplifies the phase diagram by sampling time intervals equal to the period of the driving frequency. If you are dealing with a periodic change, then this sequence consists of n dots being indefinitely repeated in the same order. If the evolution is chaotic, then the Poincare section is a collection of points that show patterns with no obvious repeti- tion. This chapter considers two well known nonlinear systems and is divided into two prob- lem sections: 4.2, Nonlinear Pendulum, and 4.3, Duffing Equation. Exercises are included in section 4.4. Before starting the problems you might find it convenient to turn off the spell checker: In[l]:= Off [General :: "spell"]; Off [General :: "spelll"]; 
4.2 Nonlinear Pendulum 195 4.2 . NONLINEAR PENDULUM 4.2.1 . Overview This section deals with the fairly simple nonlinear differential equation governing the mo- tion of a pendulum. Consider a planar pendulum of length L and mass m that moves in a vertical plane. It is described by the second-order equation B"[t] + Sin[B[t]] = 0 L where 9 is the acceleration of gravity and L is the length of the pendulum. The function B [t] is the angular displacement measured from its position of equilibrium at B= 0, which corresponds to a pendulum hanging sttaight down. The equations of motion for a planar pendulum are nonlinear. This is a result of the force of gravity pulling sttaight down and the pendulum bob swinging in an arc so the restoring force is proportional to the sine of the displacement angle. If the standard pendulum motion is enhanced by adding a damping term proportional to B' [t], then the equation for the damped pendulum becomes B"[t] + Y e'[t] + w6Sin[B[t]] = 0 The damping insures that phase ttajectory will eventually approach an atttactor. We finally consider the driven pendulum e"[t] + Y e'[t] + w6Sin[B[t]] = foCos[wd t] The interesting behavior in the forced pendulum is the occurrence of chaotic states where nearby initial conditions lead to widely varying behaviors. It is quite remarkable that such complexity arises from a fairly simple physical object. The basic problems to be studied are to: 1. find the conditions of equilibrium of the system and investigate their stability; 2. investigate the change in the system as the initial conditions are varied; and 3. investigate the dependence of the solution on the damping and forcing parameters. The problems are arranged in order of increasing complexity. We start with the behavior of an unforced and undamped pendulum, and then proceed to the damped pendulum, and finally to the driven pendulum. Each new problem provides more insight into nonlinear motion and gives more examples on how Mathematica is applied to physics. It is useful to create user-defined procedures for calculations that are used in more than one problem in this section. Several user-defined procedures are used repeatedly for the pendulum equations. Basically, all of these procedures numerically solve the pendulum equation and plot some form of the results. It is not necessary to understand the details of these procedures until you have done all the problems; then you can go back and ex- amine the steps. To understand them in detail, go through the steps one at a time. Try to make the procedures more time efficient, add default conditions, and add options to the 
196 Chapter 4 Nonlinear Oscillating Systems procedures. These user-defined procedures must be entered before many of the problems in this section will work. They have been placed on the author's web sites and can be down- loaded. They also can be downloaded from the publisher's web site. The user-defined pro- cedures we have consttucted for the nonlinear pendulum are anglePend, phasePend, poincarePend,reduce,anglePendR,phasePendR,poincarePendR: 4.2.2 . Initialization of User-Defined Functions 4.2.2.1 . User-Defined Procedure for the Pendulum1s Angle-Time Graph The procedure anglePend numerically solves the force pendulum and returns a plot of its angle: In [2] : = anglePend [{BO_, dBO.}, h'., fO., lAIO., lAJd_}, tmax_, step_, opts__.] .- Module [ {teDIP } , teDIP = NDSol ve [ {dB'[t] +¥ dB[t] +lAIO A 2 Sin[B[t]] == fO Cos [t lAId] , B'[t] ==dB[t],B[O] ==BO, dB[O] == dBO}, {dB[t],B[t]}, {t, 0, tmax}, MaxSteps -+ step ] / /Flatten; Plot [{ B [t] } / . temp / /Evaluate, {t, 0, tmax}, opts, DisplayFunction -+ Identity] The list {(}O , d(}O} gives the starting angle and its starting derivative. The list {y , f 0, wO, wd} gives the damping coefficient, the applied force, the natural frequency, and the forcing frequency for the pendulum equation. The input tmax gives the maximum time, and step gives the maximum number of steps used to numerically solve the differential equation. The default setting for MaxSteps is 1000 for ordinary differential equations. You apply Show with the rule DisplayFunction -> $DisplayFunction to display the graph. The input opts allows you to add options to the graphics. 4.2.2.2 . User-Defined Procedure for the Pendulum'!; Phase Diagram The user-defined procedure phasePend returns a plot of its phase diagram. 
4.2 Nonlinear Pendulum 197 In[31:= phasePend[{BO., dBO_}, h.-, fO., ""0_, ""d_}, tmax_, step., opts__] ._ Module [{temp}, temp = NDSol ve [ {dB' [t] + ¥ dB [t] + ""0-2 Sin [B [t]] == fO Cos [t ""d] , B'[t] ==dB[t],B[O] ==BO, dB[O] == dBO}, {dB [t], B [t]}, {t, 0, tmax}, MaxSteps -+ step ] / /Flatten ; numgraph = parametricplot[ {B[t] , dB[t]}/ .teDIP / /Evaluate, {t, 0, tmax}, opts, DisplayFunction -+ rdentity] The input is the same as for anglePend. 4.2.2.3 . User-Defined Procedure for the Pendulum's Poincare Diagram The user-defined procedure poincare Pend returns a Poincare diagram: In [41 := poincare Pend [{BO., dBO_}, {¥ _, fO_, ",,0., ""d.}, start_, tmax., step_, opts_..] : = MOdule[{templ,temp2}, templ = NDSol ve [ {dB' [t] + ¥ dB[t] + ""0-2 Sin[B[t]] == fO Cos [t ""d] , B'[t] ==dB[t],B[O] ==BO, dB[O] == dBO}, {dB[t], B[t]}, {t, 0, tmax}, MaxSteps -+ step ]//Flatten; temp2 = Table [ { B [t] , dB [t] } / .templ, {t, start, tmax, 2 7f/""d}]; ListPlot[temp2, Plot Style- >PointSize[0.02], opts] The input is the same as for anglePend with an additional variable start. Instead of starting the time points at t=O the graph starts at t=start. This allows a starting time to be picked so the ttansient motion has died out. 
198 Chapter 4 Nonlinear Oscillating Systems 4.2.2.4 . User-Defined Procedure to Map the Pendulum to the Interval-H and H This procedure restricts the position of the pendulum x to the interval of -H and H: In [5] := reduce[x.] = Mod[x, 271", -71"] Out[5]= Mod(x, 21[, -1[) Let's check this graphically. In [6] : = Plot [reduce [x], {x, -471" , 4 71"}, Ticks.... {Table [i 71", {i, -4, 4}], None}]; 7T 4.2.2.5 . User-Defined Procedure for the Pendulum's Reduced Angle-Time Graph The user-defined procedure anglePendR returns a plot of the pendulum angle where the angle has been restricted to the interval of -1T and 1T: In[7]:= anglependR[{BO_, dBO_}, h'., fO., ",,0., wd.}, tlIIax-, step_, opts___] .- Module [ {teDIP } , teDIP = NDSolve[ {dB' [t] + ¥ dB [t] + ""OA2 Sin [B [t]] == fO Cos [t ""d] , B'[t] ==dB[t],B[O] ==BO, 119[0] == dBO}, {dB[t], B[t]}, {t, 0, tmax}, MaxSteps .... step ] / /Flatten ; Plot [reduce[B[t]/.temp] //Evaluate, {t, 0, tmax}, opts, DisplayFunction .... Identity] The input is the same as for anglePend. 
4.2 Nonlinear Pendulum 199 4.2.2.6 . User-Defined Procedure for the Pendulumls Reduced Phase Diagram The user-defined procedure phasePendR returns a plot of the phase diagram where the points are restricted to the interval of -n and n: In[8]:= phasePendR[{BO_, dSO_}, b'-, fO_, (Al0_, (Ald.}, tmax., step., opts___] .- Module [{temp}, temp = NDSolve[ {dB'[t] +¥ dS[t] +(Al02 Sin[B[t]] == fO Cos [t (AId] , B'[t] ==dB[t],B[O] ==BO, dS[O] == dSO}, {dB[t], B[t]}, {t, 0, tmax}, MaxSteps .... step ] / /Flatten ; parametricPlot[ { reduce [B[t] / . temp ], dB[t] / . temp} / / Evaluate, {t, 0, tmax}, opts, Displayl!'unction.... Identity] The input is the same as for phasePend, 4.2.2.7. User-Defined Procedure for the Pendulum IS Reduced Poincare Diagram The user-defined procedure poincarePendR returns a plot of its Poincare diagram re- stricted to the interval of -n and n: 
200 Chapter 4 Nonlinear Oscillating Systems In[9]:= poincarePendR[{eo., deO_}, {y _, fO., ""0., ""d_}, start_, tmax_, step_, opts_..] : = Module[{templ,temp2}, templ = NDSolve[ {de' [t] + y de [t] + ""02 Sin [e [t]] == fO Cos [t ""d] , e'[t] ==de[t],e[O] ==eo, de[O] == deO}, {de[t],e[t]}, {t,O,tmax}, MaxSteps -+ step ] / /Flatten ; temp2 = Table [ {reduce[e[t]/.templ], de[t]/.teD\Pl} , {t, start, tmax, 2 7f/wd}] ; ListPlot[temp2, PlotStyle- > PointSize [0 .02], opts] The input is the same as for poincarePend. 4.2.2.8 . Protect User-Defined Procedures Finally we apply Protect to the user-defined procedures to keep them from being deleted with Clear ["Global' *"] : In[10]:= protect[anglepend,phasepend,poincarepend,reduce,anglependR, phasependR,poincarependR]; We also suppress some warning messages with the following commands. In[ll]:= Off [Clear :: wrsym]; Off [SetDelayed :: write]; . PROBLEM 1 Analytic Solution for the Planar Pendulum. Consider a planar pendu- lum of length L and mass m that moves in a vertical plane. If gravity is the only force, then the motion is described by the second-order equation e"[t] + Sin[e[t]] = 0 L where 9 is the acceleration of gravity, and e [t] is the angular displacement measured from its position of equilibrium at e=o; this corresponds to a pendulum hanging sttaight down. 
4.2 Nonlinear Pendulum 201 a. Show that the conserved energy of the pendulum can be written as En = B'[t]2 - tCOS[O[t]] Make a phase diagram using the energy expression. Graph the phase diagram on a cylinder. b. Integrate the energy expression to get an analytic expression for O[t]. c. Find the period for the nonlinear pendulum, and plot the results as a function of the amplitude. d. If 0 is small, then Sin [0] can be approximated by 0 and the linear pendulum equa- tion becomes B"[t] + to[t] = 0 Compare the linear and nonlinear solutions for the pendulum. e. Compare the Fourier series of the nonlinear and linear solutions. Remarks and Outline An expression for the conserved energy follows from multiplying the equation of motion by 0' [t] and integrating. The pendulum system has two equilib- rium points, one is stable and the other is unstable. The stable one is at 0=0 and corresponds to a pendulum hanging sttaight down at rest. The other fixed point at 0 = 7r is unstable and corresponds to a pendulum resting sttaight up. The exact solution follows from integrating the energy expression which gives an elliptic integral. Solution In [12] := Clear[DGlobal' * 0] a. Consider the nonlinear pendulum equation In [13] := NLeq = B" [t] + glL Sin[B[t]] == 0 Out[13]= g Sine(t» + en (t) == 0 
202 Chapter 4 Nonlinear Oscillating Systems where e [t] is measured relative to the downward vertical. To reduce the pendulum equa- tion to a first integral, multiply bye' [t] and integrate the left-hand side ofNLeq, In[14J:= eql = En == (e' [t] NLeq [ [1]] IIExpandAll II rntegrate [I, t] &:) Out [14J = En ==  8' (t) 2 _ g Cos (8 (t) ) 2 L where En, the constant of integration, is equal to the total energy of the pendulum. The first term on the right side of eq1 is the potential energy and the second is the kinetic energy. Since the energy is a constant, you can replace En with the angle at the highest point of its swing where e' [t] =0. If eo is the highest point of the oscillation, then En= - fCos [(}O] . You can describe this energy expression with the rule In[15J:= Erule = {En.... -gl L Cos [eo]}; Notice the energies for a motionless bob (e' [t] =0) at the bottom (e[t]=O) and at the top (e[t] = n) of the pendulum are In[16J:= En/.Erule/.{eO....{0,7I"}} Out[16J= { -, } A phase porttait for the pendulum follows from applying the command ContourPlot to the energy expression. The command ContourPlot graphs the curves {e[t]. e' [t]} for different values of the energy (different initial conditions). Each value of the energy gives a different ttajectory. Assume g=l and L=l and apply ContourPlot to the right side of the energy equation given by eq1. You get the following phase porttait. In [17 J : = pt = ContourPlot [ eql[ [2] ]/.{g ....1, L ....l}IIEvaluate, {e [t], -471", 4 7I"}, {e' [t], -3, 3}, Contours.... Range [-1, 3, 0.5], FrameTicks .... {71" Range [-4, 4 ],Automatic}, ColorFunction.... Hue, Plot Points .... 100, FrameLabel.... {ne n , ne'n}, DisplayFunction.... rdentity]; Several options have been added to embellish the graph. The option Contours-4{ . . . } is used to exhibit n contours with specified values of the energy. Displaying the graph, we obtain 
4.2 Nonlinear Pendulum 203 In[18]:= Show[pt, Graphics[{Hue[O.2],PointSize[O.02], Map [Point, { 7f(2 # + 1),0 } &:/@ Range [-2, 1] ]}], Graphics[{Hue[O.8],PointSize[O.03], Map [Point, {2 7f#, 0 } &:/@ Range [-2, 2]]}], DisplayP'unction... $DisplayFunction] ; CD -If If 2 If 3 If 4 If For each value of the energy (initial conditions) there is a curve in the {8[t], 8' [t] } plane. The curves with E > 1 correspond to orbits with initial velocities so large that the pendulum revolves without end. If 0 < E < 1 then the orbits are closed and the pendulum periodically oscillates back and forth. The points with 8' =0 and 8=0, :tn, :t2n, :t3n are critical points. We have denoted these points by adding dots to the graph. The position at the bottom of the pendulum's motion correspond to 8=0, :t2n, :t4n,... and mark the stable points. The points at the top of the pendulum correspond to 8= :tn, :t3n, ... and are unstable points. The physical pendulum repeats every 2n interval, so the information about the oscil- lation is contained in the interval {-n, n}. You can display these restricted ttajectories by drawing the curves on a cylinder that repeats every 2n interval. Do this by first drawing a cylinder, and then adding the ttajectories. Consider the graphics for a cylinder In [19] : = cylind = ParametricPlot3D [ {v, Sin[9], Cos [9]}, {9, -7f, 7f}, {v,-3,3}, DisplayFunction... :Identity] ; Show [cylind, DisplayFunction... $DisplayP'unction]; 
204 Chapter 4 Nonlinear Oscillating Systems 1 0.5 o -0.5 1: 1 0.5 o -0.5 -1 Combining the cylinder with the phase ttajectories, we obtain In[20]:= Show[ cylind, Graphics3D [ {AbsoluteThickness[3], Cases [Graphics [pt], -Line, 00] /. {9_,v.} :>{v,1.02 Cos[9], 1.02Sin[9] }}], ViewPoint... {I, I, I}, DisplayFunction ... $DisplayFunction ] ; 1 b. Even though the pendulum is nonlinear, it has an analytic solution expressed in terms of an elliptical function. To get an analytic expression for e[t], start with the energy equa- tion En= g cos[e[t]] + !tJ'[t]2 L 2 given by eql. Solving the energy equation for 8' [t) and replacing En with its expres- sion for eo, you get 
4.2 Nonlinear Pendulum 205 In[21]:= eq2 = Solve [eql, e' [t]] [ [2]] / .Erule/ / simplify/ /PowerExpand { Y2-..ftiycos(e(t)) - cos(eo) } Out[21]= e' (t) .... YL The expression for t follows from inverting the right-hand side of eq2 and integrating, In [22] := eq3 = t == :Integrate [ //.eq2, e'[t] {e[t], 0, e}] / /SiJDplify / /powerExpand Out[22]= YL Csc (  J F (  I Csc 2 (  JJ t -- -- -..fti Solving for 8, you get In [23] := eq4 = Solve [eq3, e, :InverseP'unctions ... True] / / Platten Out[23]= [ -..ftitSin(J ] { e .... 2 am YL 2 I Csc2 ( o ) } A user-defined function for 8 is In [24] := NLesol [tL, el_, CIJ_] e/. Solve [eq3, e, :InverseP'unctions... True] [[ 1]] /. {t ... tl, eo ... el, g... L ClJ2 } / / PowerExpand Out[24]= 2 am (tlW Sin ( 1 ) JCsc 2 ( e 2 1 )) where w 2 = f. You can substitute NLBsol back into the original equation to verify the validity of the solution. In[25]:= NLeq[[l]]/.e... «NLesol[#,eO,CIJ ])&:)/. g ... ClJ2 L/ / Simplify Out[25]= 0 The solution you have consttucted for 8[t] corresponds to the following initial condi- tions {8[O] ,8' [On: 
206 Chapter 4 Nonlinear Oscillating Systems In [26] : = initial = {e[o], e' CO]} == {NLesol [0, eo, III] , D[NLesol [t, eo, w], t]}/.t... 011 Thread Out[26]= {e(o) ==o,e'(O) ==2WSin( e 2 0 )} where w 2 = f. These initial conditions correspond to a pendulum that starts at the bot- tom (e[O] =0) and is given an initial push, either in the clockwise or counterclockwise direction. The size of the push is parameterized with eo. Let us plot the solution for different values of eO/1T={O.l, 0.3, 0.5, 0.7, 0.9} (i.e., different initial pushes). We form the list of solutions In[27]:= list = Table [ NLesol [t, i 1f, 1], {i, 0.1,0.9, 0.2}] ; and display the results with Plot. In [28] : = Plot [list II Evaluate, {t,0,16}, AxesLabel... {nt n , ne n }, PlotStyle ... ({Thickness [#/100], Hue[#]}& I@ Range [0.1, 0.9, 0.2] II Evaluate) ] ; e t As the size of the push gets larger the value of the amplitude increases. c. The time for the pendulum to go from e=o to eo follows from setting e = eo in eq3, In[29]:= eq3[[2]] I. {e- >eo} Out[29]= VL Csc l  ) F l  I csc2l  ) ) --J9 
4.2 Nonlinear Pendulum 207 Since this is 1/4 of a full swing, the period for one complete cycle is four times this value. In [30] := period = 4 eq3 [[2]] I. {e- > eO} 4 VL Csc [  J F [  I Csc 2 [  JJ Out[30]= -..fti Plotting the period as a function of eo, you get In[31]:= Plot [period. I. {g... 1, L... 1} I IRe II Evaluate, {eO, o. ,7f}, GridLines... Automatic, AxesLabel... {neon, "period"}, PlotSty1e... {Hue [0 .6], Thickness [0.01] }, Ticks... {7f/4 Range [0,4,1], 7f Range [0,10,2]}, PlotRange... {{O, 7f}, {O, 107f}}, Epilog... {Bue[O .8], Thickness [0 .01], Line [{ {O, 2 7f}, {7f, 27f}} ]} ] ; Period 10 iT BiT .../' - - 6iT 4iT 2iT iT "4 iT "2 3iT 4 eo iT The horizontal line is the period for the equivalent linear pendulum (T=2n). Notice it takes an infinite amount of time to come to rest at the highest apex e = n. d. To compare the linear and nonlinear solutions, define the linear equation In [32] := Leq = en [t] + g/Le[t] == 0; The user-defined function for the linear solution is In [33] : = Lesol [tL, eo_, fIJ_] = e[t] I. DSolve[{Leq, e[O] == 0, e' [0] == 2 fIJ Sin[eO/2]}, e[t], t][ [ 1]]/.{t...t1,eO...eo,g... LfIJ-2 }II PowerExpand 
208 Chapter 4 Nonlinear Oscillating Systems ( eo ) . Out[33]= 2 Sin 2 Sm(tlw) where w 2 = f. The command for the nonlinear solution follows from NLBsol. The graph- ics for the linear and nonlinear equations are In[34]:= ptl = Plot [ { Lesol [t, 1f/2, 1], NLElsol [t, 1f/2, 1] } / / Evaluate, {t,O,41f}, PlotStyle .... { {Dashing[{l.,O.}], Thickness[O.Ol]}, {Dashing[{0.06,O.03}], Thickness[O.OOl]}}, l"rame .... True, DisplayFunction.... :Identity ] ; where w=l and eo=. To embellish these graphics, add the graphics for discrete time points for both the linear and nonlinear motions: In[35]:= Lpts = {#, Lesol [#, 1f/2, I]}&: /@ Range [0, 41f, 0.5] / /l"latten / / Partition[#,2]&://Chop; NLpts = {#, NLElsol [#, 1f/2, 1] }&:/@ Range [0, 41f, 0.5] / /l"latten / / Partition[#,2]&://Chop; Combining the graphics and displaying the results, you get In[36]:= Show[ ptl, Epilog.... {Hue [0.6] , Point size [0.02] , 1Iap[ Point, Join [NLpts , Lpts]]}, Displayl"unction .... $DisplayFunction ] ; 
4.2 Nonlinear Pendulum 209 1.5 -1 -0.5 -1.5 o 2 The solid curve is for the linear pendulum and the dashed curve is for the nonlinear pendulum. The points are equally spaced in time. e. To study the generation of higher harmonics with increasing nonlinearity, you can expand e [t] into its Fourier specttum. This is most easily accomplished by using the Mathematica command Fourier: In[3?]:= ?Fourier Fourier[list] finds the discrete Fourier transform of a list of complex num- bers. More... The data for the specttum of the nonlinear pendulum is In [38] := fourierdataNL = Table [NLElsol [t, O. 997f ,1] I IN, {t, 0, 100, 100/511}] ; The Fourier ttansform of the absolute value of the data is In [39] := ptNL = ListPlot[Fourier[fourierdataNL] IIAbs, PlotJoined... True, Plot Style ... Hue [Random [] ] , PlotRange ... All ] ; 25 20 15 10 5 100 200 300 400 500 
210 Chapter 4 Nonlinear Oscillating Systems Enlarging the sttucture on the left side of the graph, you get In[40]:= Show [ptNL, PlotRange... {{O, 45}, {O, 8 }}]; 8 ! 7 ! 6 ) I I \ \ 1\ \ II 1 \ \ ! I \ II \ I I \ I \ I' \ J ' \ 1\ ) '--- "----. 10 20 30 40 5 4 3 2 1 Compare this with the pure harmonic that follows from the linear pendulum In [ 41] : = fourierdataL = Table [Lesol [t, O. 997f ,1] I IN, {t, 0, 100, 100/511}] ; Displaying the linear and nonlinear pendulums, it follows In [42] := ptL = ListPlot[Fourier[fourierdataL] IIAbs, PlotJoined ... True, PlotStyle ... Thickness [0.01] , PlotRange... {{O, 45}, {O, 10}}, Epilog... ptNL [ [1]] ] ; 6 40 4 2 where the nonlinear plot has been included with Epilog. The single dark peak is the linear pendulum. . PROBLEM 2 Damped Pendulum. If the standard pendulum motion is enhanced by adding a damping term proportional to 8'[t], then the equation for the damped pendulum 
4.2 Nonlinear Pendulum 211 becomes O"[t] + y O'[t] + w0 2 Sin[8[t]] = 0 The damping in the pendulum ensures that its phase space ttajectory will eventually ap- proach an atttactor. a. For this part of the problem, pick y = 0.2 and wO = 1 and choose the initial condi- tions to be 8[0] = 0.91T and 0'[0] = O. Numerically solve and plot the results. Make a user-defined function to plot 8[t]. Apply the command to the list of initial conditions 8[0] = 0 and 0'[0] = {-6, -3, -1,1,3, 6}. b. Plot the phase ttajectory for the initial conditions 8[0] = 0.91T and 0'[0] = 0.0. Make a user-defined function that plots the phase ttajectory. Set y = 0.3 and wO = 1, and apply this command to the list of initial conditions I{>[O] = 0 and 0'[0] = {-6, -3, -1, 1, 3, 6}. Illusttate the basin about one of the atttactors by plotting the ttajectories for a range of initial values of 0'[0] that lead to the same phase space atttactor. c. Make a phase porttait for the damped oscillator using the command PlotVector- Field. Combine the vector field graph with the ttajectories discussed in Part b. Solution In[43]:= Clear[nGlobal' * n] a. You want to solve the equations for a damped pendulum and display the motion for a given set of initial conditions {8 [0), (I' [OJ). In particular set 8[0] = 0.91T, (I' [0] = 0, y=O. 2, and wO=l, and consider the differential equation In [44] := eq1 = {e"[t] +¥ e'[t] +wO2 Sin[e[t]] == 0, e [ 0] = = O. 97f, e' [0] = = O} / . {¥... 0.2, wO ... 1} / /Flatten; If you apply NDSol ve to eql, In [45] := solDP = NDSolve [ eq1, e[t] , {t, 0, 40}] / / Flatten; and then plot the result, you get In[46]:= Plot [ e[t]/.solDP //Eva1uate, {t, 0, 40}, AxesLabel... {nt n , ne n }, PlotRange ... All, Plot Style ... {Thickness [0 .01], Hue [Random [] ] } ] ; 
212 Chapter 4 Nonlinear Oscillating Systems e 2 1 t 40 -1 The pendulum starts from rest at 8 [0] = 0.9 7r and swings through the bottom to the other side. This pattern repeats over and over with the amplitude becoming progressively smaller. The swing eventually comes to rest at the bottom of the pendulum's swing. Assume a nonzero initial velocity as if the pendulum had received a sharp kick. In particular consider the graphics of 8[t] for the initial conditions 8[0] =0 and lJ'[0]= {-6, -3, -1, 1, 3, 6}. This list contains initial conditions for motions moving in both the counterclockwise and clockwise directions. To consttuct these solutions, gather the steps used in the previous calculation and make a general user-defined function. The user-defined function that summarizes these steps is In[47]:= angle [{eO_, vO_}, h'., wO.}, tmax.-, opts._.] : = Module [{numsol}, numsol = NDSolve[ {en [t] + ¥ e' [t] + wO-2 Sin [e[t]] == 0, e[O] ==eo,e'[O] ==vO},e[t], {t, 0, tmax}]; numgraph = Plot [ e[t]/.numsol, {t, 0, tmax}, opts, DisplayFunction... :Identity] The initial conditions are entered as a list in { 80, vO} and the pendulum parameters are entered in the second list {y , wO }. The time span is from t = 0 to t =tmax. Assume the initial conditions 8[0] = 0, lJ' [0] = {-6, -3, -1, 1, 3, 6} and apply angle. If you set y = 0.3, and wO=l then the list of graphics is 
4.2 Nonlinear Pendulum 213 In[48]:= grlist = angle [ {O, #}, {0.3, I}, 23, AxesLabel -+ {"t", "8"}, GridLines -+ Automatic, PlotStyle -+ {Thickness [0 .01], Hue [Random []] }, Ticks -+ {11" Range [0,8,2], 211" Range[-2,2]}, PlotRange -+ All, DisplayFunction -+ :Identity ]5: /@ {-6, -3, -I, I, 3, 6} ; Displaying the results for 8[t], you find In[49]:= Show[grlist, Displa.yl!'unction -+ $DisplayFunction] ; e 4lT 6lT t 2lT -2 IT -4 IT All but two of the initial kicks were of sufficient value that the pendulum made one or more full revolutions before coming to rest at the bottom of the pendulum's swing. Depend- ing on the number of rotations and whether the motion was clockwise or counterclockwise, the paths converge to the values 8=0, :t211", :t411". b. You can plot the phase ttajectory using parametricPlot and the solution for the previously solved differential equation. Consider the phase ttajectory with the initial conditions 8[0] = 0.911" and 8' [0] = O. The plot of {8[t],8' [t]} follows from In[50]:= ParametricPlot[ {8[t]/.solDP,D[8[t]/.solDP,t] }// Evaluate, {t, 0, 40}, AxesLabel-+ {"8", "8'"}, Ticks -+ {11" Range [-2,2,1/4], Automatic}, PlotRange -+ All, PlotStyle -+ {Hue [0.8], Thickness [0.009] } ] ; 
214 Chapter 4 Nonlinear Oscillating Systems e' e The phase ttajectory spirals toward the atttactor located at 8 and 8' equal to zero. Consider the phase ttajectory for another set of the initial conditions: 8[0] = 0,8'[0]=4. Before you do this example, gather the steps in the previous calculation and make a gen- eral user-defined procedure. A user-defined function consttucted to plot the general phase ttajectory {8[t],8' [t]} is In [51] : = phase [{ eo_, vO_}, {y _, wO_}, tmax., opts___] : = Module [{numsol}, numsol = NDSolve[ {v' [t] + y v[t] + wO A 2 Sin[e[t]] == 0, e' [t] == v[t], e[o] == eo, v[O] == yO}, {v[t], e[t]}, {t, 0, tmax}] / /Flatten; numgraph = parametricPlot [ {e[t] , v[t]}/ .numsol / /Evaluate, {t, 0, tmax}, opts, DisplayFunction -+ :Identity] Applying phase to the ttajectory with the initial conditions 8[0] = 0, 8' [0] =4 and with parameters {y= 0 . 2 , wO = I}, it follows In [52] := ptl = phase[{O, 4}, {0.2, 1}, 40, PlotRange -+ All, AxesLabel -+ {ne n , ne' n}, PlotStyle -+ {Thickness [0.009], Hue [0.7]}, Ticks -+ {11: Range [0,4 ], Range [-2,4 ]}, GridLines -+ Automatic, Plotpoints -+ 200, DisplayFunction -+ $DisplayFunction ] ; 
4.2 Nonlinear Pendulum 215 e' e The initial kick ensured that the pendulum went over the top twice before converging to the point at (JI =0 and (J=4 n. The damping term ensures that the ttajectory eventually converges to the atttactor. Let us consider the phase space ttajectories for several different initial values. Assume (J[O] = 0 and ()' [0] = {-6, -3, -1, 1, 3, 6} and apply phase In[53]:= phlist = phase [{O, #}, {0.3, I}, 23, AxesLabel -+ {Oe n , °e' O}, PlotStyle -+ {Thickness [0.008], Hue [Random []] }, Ticks -+ {1r Range [-8,8,2], Range [-6, 6]}, PlotRange -+ All ]5: /@ {-6, -3, -1, 1, 3, 6} ; Displaying the results, you find In[54]:= pt2 = Show[ phlist , GridLines -+ Automatic, DisplayFunction -+ $DisplayFunction ] ; e' e 
216 Chapter 4 Nonlinear Oscillating Systems Four of the initial kicks were sufficiently large that the pendulum completed one and two full revolutions before being atttacted to the atttactors at 8= :!:: 27r and:!::4 n. Some of the rotations were clockwise and the others were counterclockwise. A range of initial conditions converge to the same atttactor. The collection of points is called the basin of the atttactor. To illusttate this property consider the atttactor in phase space located at {8 = 2n, 8'=3}. Assume an initial displacement 8[0] = 0 with a range of values near 8'[0]=3. The list of initial conditions is In [55] := list = {O, 3 + #}&:/@ Range [-0 .51,0.51,0.2]; The graphics for the collection of ttajectories follows from applying phase In[56]:= grlist = phase [I, {O .2, 1}, 155, Plotpoints -+ 100, AxesLabel -+ {ne n , ne' n}, PlotStyle -+ {Thickness [0.005], Hue[0.9]} ] &: /@ li st ; Displaying the results, you get In[57]:= pt3 = Show[ grlist, Graphics [Point [{2 11"#, O} ] &:/@ Range [0,2] ], PlotRange -+ All, Ticks -+ {11" Range [0,4], 11" /4 Range [0, 4]}, DisplayFunction -+ $DisplayFunction ] ; e' IT 3lT  2" IT "4 e IT 4lT The damping term causes these ttajectories to spiral inward to the atttactor at 8= 2n and 8' =0. 
4.2 Nonlinear Pendulum 217 c. The phase porttait reveals all the atttactors and their basins. You can draw the phase porttait using the built-in command PlotVectorField (found in the package Graph- ics 'PlotField '), In[58]:= Needs[nGraphics'plotField'"] It follows that In [59] := pt4 = PlotVectorField[ {y,-0.2y-1Sin[x] }, {x, 0, 5 1r}, {y, -I, 5}, PlotPoints -+ 20, ScaleFunction -+ (0.4#5:), ScaleFactor -+ None, DisplayFunction -+ :Identity ] ; Displaying the phase portrait along with several ttajectories computed in Part b, you find In[60]:= Show[pt4,ptl,pt3, Displa.yFu.nction -+ $DisplayFunction] ; The arrows are tangent to the phase ttajectories. The points {8= 0 , ::I:27r, ::1:4 1C, . . .} and 8' =0 are the atttactors to which the ttajectories spiral toward. In each region of an atttactor there is a basin of initial condition and ttajectories with these initial conditions eventually converge to the specific atttactor. The curve dividing one basin from another is called a separatrix. . PROBLEM 3 Periodic Solutions for the Driven Pendulum. Let us investigate the be- havior of a driven pendulum described by the equation 8"[t] + Y e'[t] + w6 Sin [8[t]] = fa cos[wdt] a. Choose the parameters y = !, fa = 1, w a = 1, w d =  with the initial conditions 8[0] = 0 and 8'[0] = {1C/2, 3/21C, 27r, 31C}. Use the user-defined function anglePend defined at the beginning of this problem section to plot 8. 
218 Chapter 4 Nonlinear Oscillating Systems b. Use the user-defined function phasePend defined at the beginning of this problem section to plot the phase ttajectories for the parameters defined in Part a. c. Use the user-defined function poincarePend defined at the beginning of this problem section to make Poincare maps for the system in Part a. Solution In[61]:= Clear [nGlobal ' * n] a. The user-defined function that plots O[t] follows from anglePend. Consider the parameters y = 1/2, fO=l, wO=l, wd=213 and insert the initial conditions 0[0] = 0, e'[O]={ 11" /2, 3/211", 211", 311"} into the user-defined function. You get the following list of graphics: In [62] := ptl = anglePend[{O,# 1I"},{0.5 ,1,1,2/3}, 100 , 5000 , AxesLabel -+ {ne n , ne' n}, PlotRange -+ All, Ticks -+ {11" Range [0,20,5], 11" Range [0, 10 , 2]}, PlotStyle -+ Hue [Random [] ] ]5: /@ {1/2, 3/2, 2, 3}; Displaying the results, it follows In [63] := Show [ptl, DisplayFunction-+ $DisplayFunction] ; e' 6lT e 4lT 2lT The solution corresponds to a pendulum that swings over the top a number of times before settling into periodic motion. b. To plot the phase ttajectories use the user-defined function phasePend. Consider the parameters y = 1/2, fO=l, wO=l, wd=2/3 and insert the initial conditions 0[0] = 0, e'[0]={1I"/2, 3/211", 211", 311"} intophasePend: 
4.2 Nonlinear Pendulum 219 In[64]:= pt2 = phasePend[{ 0, #7f}, {0.5 ,1,1, 2/3}, 400,5000, AxesLabel-+ {nan, na'n}, PlotRange -+ All, Ticks -+ {7f Range [0, 6 ], Automatic}, Plotpoints -+ 150, PlotStyle -+ Hue [Random [] ] ]&: /@ {1/2, 3/2, 2, 3}; Displaying the results, it follows In [65] := Show [pt2, DisplayFunction-+ $DisplayFunction]; e' e After the pendulum loops over the top a number of times, it settles into periodic motion about one of the atttactors located at e = 0 I 211" I 411" and 611". C. The Poincare section simplifies the phase diagram by sampling the phase space at time intervals equal to the period of the driving frequency. The Poincare section is a sttoboscopic map and only exttacts those points in the phase diagram that are commensurate with the driving frequency. The user-defined function for the Poincare map is poincarePend. Inserting the previous parameters into this function, it follows In [66] := pt3 = poincarepend[ {O, #7f}, {0.5 ,1,1, 2/3}, 100, 400 , 5000 , PlotRange -+ {{ -25,25}, {-3, 3}} , Displayl'unction -+ :Identity ]&: /@ {1/2, 3/2, 2, 3}; Displaying the results, you get In [67] := Show[ GraphiCSArray[Partition[pt3,2]] , Displayl'unction -+ $DisplayFunction ] ; 
220 Chapter 4 Nonlinear Oscillating Systems 3 2 1 20 10_ 1 10 20 -2 -3 3 2 1 -20.10_ 1 10 20 -2 -3 3 2 1 -20-10_ 1 10 20 -2 -3 3 2 1 -20-10_ 1 10 20 -2 -3 All the Poincare graphs show only one point, which is indicative of periodic motion with period one. We can overlay the points on a single plot as follows: In[68]:= Show [ pt3, DisplayFunction -+ $DisplayFunction]; 3 2 1 -20 -10 10 20 -1 -! . . . -3 . PROBLEM 4 Looping Solutions for the Driven Pendulum. Consider the solutions of the driven pendulum 8"[t] + y B'[t] + w6Sin[8[t]] = fo COS[Wdt] that loop over the top in a repetitious manner. In particular, choose the initial conditions 8[0] = 0, B' [0] = 0 and let the parameters be y = , fo = 1.44, W o = 1, and W d = . These values correspond to a pendulum that rotates over the top each cycle so the coordinate 8 increases without limit. a. Plot 8 using the user-defined function anglePend. Notice, values of 8 differing by 27r represent the same physical point. Use the user-defined function anglePendR to restrict 8[t] to the interval {-7r, 7r}. Compare this graph with the results that followed from the unrestricted motion. b. Use the user-defined functions phasePend and phasePendR to plot the phase ttajectory and the restricted phase ttajectory, respectively. c. Use the user-defined functions poincarePend and poincarePendR to plot the Poincare map and the restricted Poincare map, respectively. 
4.2 Nonlinear Pendulum 221 Solution In [69] := Clear [nGlobal \ * n] a. Consider the initial conditions {8[0] = 0, e' [0] = O} and set the parameters y = 1/2, fO=l. 44, wO=l, wd=2/3. To plot 8 apply the user-defined function anglePend: In [70] := eql = anglePend[ {O, O} , {1/2, 1.44 ,1, 2/3}, 50,10000 ,AxesLabel-+ {nt n , na n }, Ticks -+ {Automatic, -11: Range [0, 10, 2 ] }, PlotStyle-+ { Thickness[O.Ol]}, DisplayFunction -+ $DisplayFunction ] ; e -2 IT -4 IT -6 IT -8 IT -lOlT The magnitude of 8 [t] continues to get larger as the pendulum loops over the top on each cycle. The pendulum looks periodic but strictly speaking the solution is not periodic because the 8 values do not repeat. However, the 8 values differing by 27r represent the same physical point, so the points differing by 211" can be considered to be the same. Let us plot 8 [t] using the user-defined procedure that maps 8 onto the interval -11" to 11". The user-defined function is anglePendR. Applying anglePendR to the previous parameters, you get In[71]:= eq2 = anglePendR[ {O, O} , {1/2, 1.44, 1, 2/3}, 50, 6000 , Ticks -+ {11: Range [0,20, 5], Range [-30, O,5]}, Plot Style -+ Thickness [0.01] ] ; Displaying these results along with the results of eq1, you find In[72]:= Show[ eql,eq2, DisplayFunction -+ $Displa.yFu.nction] ; 
222 Chapter 4 Nonlinear Oscillating Systems e -4 IT t -2 IT - 6 IT - 8 IT -10 IT The mapping of e [t] to the physical interval {-1C, 1C} reveals the periodic nature of the looping motion. b. What does the phase ttajectory look like? You can plot the trajectory using the func- tion phasePend or you can restrict the map to the interval -1C to 1C using phasePendR. Applying these two user-defined procedures to the motion, you get In [73] := eq3 = #[{O,O} , {1/2, 1.44 ,1, 2/3}, 100,6000, PlotRange -+ All, Ticks -+ None, Plotpoints -+ 150, PlotStyle -+ Hue [Random [] ] ] 5: /@ {phasePend, phasePendR} ; Displaying the results, it follows In[74]:= Show[GraphicsArray[eq3]]; \ '\  The curve on the left is the unrestricted phase ttajectory and the one on the right is the restricted phase. A careful observation of the restricted ttajectory suggests that the solution repeats every second period of the driver. This is clear when you magnify the restricted ttajectory edge. In [75] : = Show[ eq3 [[2]], PlotRange -+ {{ -1,0 }, {-1, 1}}, Displa.yl!'unction -+ $Displayl!'unction ] ; 
4.2 Nonlinear Pendulum 223 Notice the two bands. c. Further support for the period two motion follows from a Poincare map. The user- defined functions for the Poincare map is poincarePend and the restricted map follows from poincarePendR. The Poincare map is In [76] : = poil1carePend [{O, O} , { 1/2, 1.44,1, 2/3}, 400,500,6000 ] ; . . . . . . -1. 775 -1. 8 -1. 825 -1. 85 -1. 875 -310 -300 .290 .280 -270 .1. 925 . . . . This shows a pattern of two rows of dots. The restricted map reveals the basic period two motion. In[77]:= poil1carePendR[{O,O}, { 1/2, 1.44,1, 2/3}, 400, 500,6000 ] ; . -1. 775 -1. 8 -1. 825 .1. 85 .1. 875 0.2 0.4 0.6 0.8 -1.925 1.2 1.4 . 
224 Chapter 4 Nonlinear Oscillating Systems . PROBLEM 5 Chaotic Motion for the Driven Pendulum. One of the characteristics of the driven pendulum O"[t] + y O'[t] + w6Sin[0[t]] = fa cos[wdt] is the occurrence of chaotic states where nearby initial conditions lead to widely varying behaviors. You can approach chaotic behavior by changing the amplitude of the driving term fa. The Poincare maps for different values of fa illusttate the path to chaos. Consider the initial conditions 0[0] = nl2, 0'[0] = 0 with parameters y = 0.2, w a = 1, w d = 0.694. a. Show that for 0 < fa < 0.6 the pendulum's motion eventually either damps to an atttactor or is captured into periodic motion about an atttactor. In particular consider fa = 0,0.1,0.2, and 0.3. b. Consider the motion for fa = 0.69 and show it corresponds to a period three cycle. c. Show that the motion for fa = 0.74 is chaotic. d. Show that the motion for fa = 0.982 is a looping solution whose restricted Poincare map is period 2. Solution In[78]:= Clear[RGlobal' * R] a. Consider the initial conditions 0[0]=n/2, 0'[0] = 0 with the parameters y=0.2, wO=l, wd=O. 694. If £0=0, 0.1, 0.2, and 0.3 then the graphics for 0 [t] follow from In [79] : = eql = anglePend [ {7r/2,O}, {0.2, #,1, 0.694}, 50 ,10000, PlotRange -+ All ]& /@ Range [0, 0.3, 0.1] ; Displaying the results, you get In[80]:= Show [GraphicSArray [Partition [eql, 2]] , DisplayFunction -+ $DisplayFunction] ; 1.5  1 0.5 -0.5 04050 .1 1.5  1 0.5 -0.5! 3 4 0 -1 1.5  . 1 0.5 -0.5 1 3 0 -1 1.5  1 0.5 -0.5 2 3 0 -1 
4.2 Nonlinear Pendulum 225 After the ttansients die away the solutions either damp to the origin (top left) or become periodic about the origin. The corresponding phase ttajectories follow from In[81]:= eq2 = phasePend[ {1£/2, O}, {0.2, I, 1, 0.694}, 600,10000, PlotRange -+ All, Ticks -+ {1£ Range [-1/2, 1/2, 1/4], None} , Plotpoints -+ 100 ]& /@ Range [0, 0.3, 0.1]; Displaying the results, it follows In[82]:= Show[GraphicsArray[Partition[eq2,2]], DisplayFunction -+ $DisplayFunction] ;      Likewise, the Poincare maps are simple points In [83] : = eq3 = poincarePend [ {1£/2,0}, {0.2, I, 1, 0.694} , 500, 600, 10000 , Ticks -+ False , PlotRange -+ {{ -1, 1}, {-1, 1}} , DisplayFunction -+ :Identity ]& /@ Range [0, 0.3, 0.1]; In[84]:= Show[GraphicsArray[Partition[eq3,2]], DisplayFunctiOl1 -+ $DisplayFunction] ; 
226 Chapter 4 Nonlinear Oscillating Systems b. As £0 increases to a value of 0.69 the periodic cycles become more complex. The graph for () is In[85J:= anglePend[ {1£/2,O}, {0.2, 0.69,1, 0.694},200 ,10000, Ticks -+ {Automatic, 1£ Range [0, 2,1/2]}, Plotpoints -+ 150, DisplayFunction -+ $DisplayFunction ] ; 27f 37f 2 7f 7f "2 o The phase ttajectory reveals more information about the periodicity, In[86J:= phasePend[ {1£I2,O}, {0.2, 0.69,1, 0.694}, 700,8000, PlotRange -+ All, Plotpoints -+ 200, DisplayFunction -+ $DisplayFunction ] ; 
4.2 Nonlinear Pendulum 227 A period three cycle is suggested and is confirmed by the Poincare map In[87J:= poincarePend[ { 1£/2, O}, {0.2, 0.69,1,0.694}, 200,700, 10000 , PlotRange -+ {{ -5, 10}, {-3, 3}} , DisplayFunction -+ $DisplayFunction ] ; 3 2 . 1 . . -4 -2 2 4 6 8 10 -1 -2 -3 After the ttansient disappears the periodicity settles into a state of three cycles. c. You get a chaotic atttactor for £0=0.74. The graph of () is In[88J:= anglePend[ {1£/2,0}, {0.2, 0.74,1, 0.694}, 300,12000, AxesLabel-+ {nt n , ne n }, Ticks -+ {Automatic, 1£ Range [-5, 5, 1 ]} , DisplaYFw:1ction -+ $DisplayFunction ] ; 
228 Chapter 4 Nonlinear Oscillating Systems e 5lf 4lf 3lf 2lf If -If -2 If -3 If -4 If -5 If The pendulum does not appear to have any repeatable sttucture. The lack of sttucture is also supported by its phase ttajectory (restricted to the interval { -1[, 1[} ), In[89J:= phasePendR[ {7r/2,O}, {0.2, 0.83,l,O.694}, 300,10000, PlotRal1ge -+ All, DisplayFunctiol1 -+ $Displayl!'unctiol1 ] ; The Poincare map is a collection of points with no obvious repetition, In[90J:= poil1carePel1dR[ {7r/2,O}, {0.2, 0.8, 1, 0.694}, 100, 300, 10000 , PlotRal1ge -+ All, Displa.yFunctiol1 -+ $DisplayP'ul1ctiol1 ] ; 
4.2 Nonlinear Pendulum 229 2.5 . .. 2 . . . . . . 1.5 , . 1 . . 0.5 .... . -2 -1 1 2 -0..5 . . d. At £0 =0.982 the motion starts to loop. In[91]:= anglePend[ {1£/2,0}, {0.2, 0.982,1, 0.694}, 50,12000, AxesLahel-+ {Rt n , ne n }, Ticks -+ {Automatic, 1£ Range [-1, 1, 1/2 ]} , DisplayFunctiol1 -+ $DisplayFunctiOI1 ] ; e 7f zr - t Restricting () [t] to the interval {-1f, 1f}, the graph of () becomes In[92]:= anglePendR[ { 1£/2, O}, {0.2, 0.982,1, 0.694}, 50,12000, AxesLabel-+ {nt R , Re n }, Ticks -+ {Automatic, 1£ Range [-1, 1, 1/2 ]} , DisplayFunctiOI1 -+ $DisplayFunctiol1 
230 Chapter 4 Nonlinear Oscillating Systems e If If "2 If 2 -If The motion appears to be periodic. The ttajectory for phase space is In[93]:= phasePend[ {7r12,0}, {0.2, 1,0.982,0.694}, 300,12000, Plot Points -+ 150, DisplayFunction -+ $DisplayFunction ] ; Again, restricting the motion to the interval {-1f, 1f}, the ttajectory is In[94]:= ptl = phasePendR[ {7r/2,0}, {0.2, 1,0.982,0.694}, 300,12000, Plotpoints -+ 150, DisplayFunctiOl1 -+ $DisplayFunction ] ; 
4.2 Nonlinear Pendulum 231 The motion appears to be periodic. In fact, you discover more details in the motion by magnifying the edge of the ttajectory. In[95]:= Show[ pt1, PlotRange-+ {{ 1, 3}, {-1,1}}, DisplayP'ul1ctiol1 -+ $DisplayFunctiol1 ] ; 1 0.75 0.5 0.25  .52.753 .--/ There are two bands that suggest the motion is of period 2. This periodicity is confirmed with the restricted Poincare map, In[96]:= poil1carepel1dR[ { 1£/2, O}, {0.2, 1,0.985, 0.694}, 200, 300, 12000 , PlotRange -+ {{-3, 3}, {-3, 3}} , DisplayFunctiol1 -+ $DisplayFunctiol1 ] ; 
232 Chapter 4 Nonlinear Oscillating Systems 3 . 2 . 1 -3 -2 -1 1 2 3 -1 -2 . -3 4.3 . DUFFING EQUATION 4.3.1 . Overview In the previous section we studied the properties of the nonlinear pendulum. Another clas- sical system used to illusttate nonlinear effects is the Duffing oscillator. In 1918 Duffing studied a mechanical oscillator consisting of a thin metallic strip attached at each end to a solid support. Near the middle of the metal strip was an electtomagnet powered by an alternating current. As the current in the magnet went through a cycle, the magnetic field coupled to the strip and caused the strip to flex. The displacement of the strip sttetched the metal, which produced a restoring force that was proportional to the displacement cubed. The unforced Duffing oscillator with a cubic restoring term is described by the nonlinear equation q"[t] - a q[t] + b q[t]3 = 0 In the following problems we let b > 0 and consider both positive and negative values of a. This system is conserved and does not lose energy. If energy is lost due to internal heating then the damped Duffing equation becomes q"[t] - a q[t] + b q[t]3 + c q'[t] = 0 Finally, if we include a forcing term, then the driven Duffing equation becomes q" [t] - a q[t] + b q[t]3 + c q' [t] = fa cos[w dt] Each new solution of the Duffing equation provides further insight into nonlinear motion and gives more examples on how Mathematica is applied to physics. It is useful to create three user-defined procedures for this section, since these procedures are used in more than one problem. Basically, all of these procedures numerically solve the Duffing equation and plot the results in different forms. These user-defined procedures must be entered before many of the problems in this section will work. They have been placed on the author's web sites and can be downloaded. The user-defined procedures that we have developed are dispDuff, phaseDuff, and poincareDuf. 
4.3 Duffing Equation 233 4.3.2 . Initializations for the Duffing Equation 4.3.2.1 . User-Defined Procedure to Plot the Duffing Displacement Motion The procedure dispDuff: In [97] : = dispDuff [{qO_, pO.}, {a., b_, c., fO_, wd_}, bIIax.-, step_, opts__.] ._ Module [ {teD\P } , teD\P = NDSol ve [ {p'[t]-aq[t]+bq[tr3+cp[t] ==fO Cos[twd], q'[t] ==p[t],q[O] ==qO,p[O] ==pO}, {p [t], q[t] }, {t, 0, tmax}, MaxSteps .... step ] IIPlatten; numgraph = Plot [q[t] I .teD\P II Evaluate, {t, 0, tmax}, opts, DisplayPunction.... rdentity numerically solves the forced Duffing equation and returns a plot of its displacement. The list {qO, pO} gives the starting displacement and its starting derivative. The list {a,b, c, fO ,wei} gives the parameters for the Duffing equation. The input tmax gives the maximum time, and step gives the maximum number of steps used to numerically solve the differential equation. Apply Show with the rule DisplayFuDctioD - > $DisplayFuDctioD to display the graph. The input opts allows you to add options to the graphics. 4.3.2.2 . User-Defined Procedure to Plot the Duffing Phase The user-defined procedure phaseDuff: In [98] : = phaseDuff [{qO_, pO_}, {a_, b_, c_, fO., wd_}, bIIax.-, step_, opts__.] ._ Module [{teD\P}, teD\P = NDSolve [ {p'[t] -a q[t] +bq[tr3 +cp[t] == fO Cos[twd], q'[t] ==p[t],q[O] ==qO,p[O] ==pO}, {p[t], q[t]}, {t, 0, tmax}, MaxSteps .... step ] IIPlatten; parametricPlot [{ q [t] , P [t]} I .teD\P IIEvaluate, {t, 0, tmax}, opts, DisplayPunction.... rdentity] returns a plot of its phase diagram. The input is the same as for dispDuff. 
234 Chapter 4 Nonlinear Oscillating Systems 4.3.2.3 . User-Defined Procedure to Plot the Duffing Poincare Map The user-defined procedure poincareDuff: In [99} : = poincareDuff [{qO_, pO_}, {a_, b., c., fO., rdd_}, start_, tmax_, step_, opts___] : = Module [{temp1, temp2}, temp1 = NDSol ve [ {p'[t] -a q[t] +bq[tr3 +c p[t] == fO Cos[twd], q"[t] ==p[t],q[O] ==qO,p[O] ==pO}, {p[t], q[t]}, {t, 0, tmax}, MaxStepS .... step ] / /P'latten; temp2 = Table [ {q[t] ,p[t]}/.temp1 , {t, start, tmax, 27f/wd} ] ; ListPlot [temp2, PlotStyle- > pointSize [0 .02], opts] returns a Poincare diagram. The input is the same as for phaseDuff with an additional variable start. Instead of starting the time points at t=O, the graph starts at t=start. This allows a starting time to be picked so the ttansient motion has died out. 4.3.2.4 . Protect User-Defined Procedures Finally we apply Protect to the user-defined procedures to keep them from being deleted with Clear [ n Global' *" ] : In[lOO}:= protect [dispDuff, phaseDuff, poincareDuff]; Off [Clear: : wrsym] . PROBLEM 1 Potential and Phase Diagrams for the Duffing Oscillator. Consider a system described by the Duffing nonlinear equation of motion, q"[t] - a q[t] + b q[t]3 = 0 Assume b > 0 and let a be either positive or negative. a. Find the Duffing potential and plot it as a function of a and q. Illusttate the double- well and single-well behaviors. b. Plot the phase porttaits for the single- and double-well potentials. Do this by making a ContourPlot for the phase ttajectories with the same energy. Embellish the porttait by superimposing the contours on an energy surface. c. Numerically solve the phase ttajectories for a single-well potential. Plot a particular solution and its phase diagram. 
4.3 Duffing Equation 235 d. Numerically solve the phase ttajectories for a double-well potential. Plot a particular solution and its phase diagram. e. Animate one of the solutions. Remarks and Outline An expression for the energy follows from multiplying the equa- tion of motion by q' [t] and then integrating. Potential and phase diagrams are graphed using the commands Plot, Plot 3D, and ContourPlot. The graphics need the add-on package Graphics' Legend'. The shape of the potential depends on whether a is pos- itive or negative. The two-well potential with a > 0 has three equilibrium positions: two are stable and the third equilibrium position at the origin is unstable. The one-well poten- tial with a < 0 has only one stable equilibrium position. The numerical solution follows from applying NDSol ve to the nonlinear equation. The solution is returned in terms of an interpolating function. Solution In[lOl]:= Clear[nGlobal' * n] a. The Duffing equation is described by the acceleration In[102]:= Aee = q" [t]; and the two forces, In[103]:= Plinear = aq[t]; Pnonlinear = _bq[t]3; The force term has been separated into a linear and nonlinear term. The equations of motion follow from Newton's second law, In[104]:= eqMotion = Ace - Plinear - Pnonlinear == 0 Out[104]= bq(t)3 - aq(t) + q" (t) == 0 To reduce the problem to a first integral, i.e., to find the conserved energy, multiply the equations of motion by q' [t], integrate, and set the results equal to a constant (the energy): In[105]:= energy = rntegrate [ q' [t] (Aee - plinear - Pnonlinear) It] 14 1 2 1 , 2 Out[105]= "4 bq(t) - 2" aq(t) + 2" q (t) The kinetic energy T follows from integrating Acc and the potential energy follows from integrating Flinear and FDonlinear: 
236 Chapter 4 Nonlinear Oscillating Systems In[106]:= {T= rntegrate[q'[t]Acc,t], VO = - rntegrate[ q' [t]plinear, t], Vl = - rntegrate[ q' [t]Pnonlinear, t]} { l 1 1 } Out[106]= - q' (t)2, -- aq(t)2, - bq(t)4 224 To graph the potential, fix b=O. OS. Next apply Plot3D to the total potential VO + vI and vary q and a: In[107]:= Plot3D[VO + Vl1 I. {q[t] .... q, b.... O.OS} I I Evaluate, {q, -15, lS}, {a,-l,4}, AxesLabel.... {Rqn, Ra R , npotential n }, BoxRatios.... {1, 1, 1}, PlotRange.... {-100, 50}, ViewPoint.... {O, 3, 1} ] ; Potential a 50 The three-dimensional plot illusttates how the shape of the potential changes from a one-well potential with a < 0 and then for a > 0 to a two-well potential. A qualitative change in the dynamics is produced when the potential makes this change. The value a=O is called a bifurcation value and this particular bifurcation point is known as a pitchfork. To illusttate the two types of potentials you graph one potential curve with parameters {b=O.Os, a=-l} and the other with {b=O.Os, a=4}. Add to the Plot command the option PlotLegend found in the add-on package Graphics' Legend' : In[10B]:= Needs[RGraphics'Legend'R] 
4.3 Duffing Equation 237 The potential curves follow from In[109]:= Plot[ VO+V1//.{q[t] ....q,b....0.05}/. a.... {-1, 4} / /Evaluate, {q, -15, 15}, Ticks- > None, plot Style- > { {Dashing [ {O. 01} ], Hue [0.6]}, {Dashing[ {0.03} ],Hue[0.9)}}, plotLegend- > {A a = _lA, n a = 4 A }, LegendPosition- > {0.1, 0.3}] ; a=-l \ \ \ \ \ \ \ a=4 , , I I I /' "- '- '- \ \ / / / '- I I / '--"" The two-well potential (a > 0) has three equilibrium positions: two are stable, while the third position at the origin is unstable. For the potential with a < 0 there is only one stable equilibrium position. It is useful to have a physical picture to think about. Imagine a bead sliding on a wire in the shape of the double-well. The bead can exist at rest at the bottom of the wells and at the top of the well. If the bead at the top is slightly displaced to the left it will be atttacted to the left well and then continue to oscillate between the two wells. In general the beads in the wells will oscillate in the wells if they do not have sufficient energy to go over the top of the well. For the one-well potential, the bead slides in one dimension along the sides of a bowl. The only place the bead can remain at rest is at the bottom of the bowl. In general the bead will oscillate back and forth in the bowl. b. One way to make phase porttaits for these two characteristic potentials is to apply ContourPlot to the energy. Define the notation and fix the value ofb. In[llO]:= values = {q[t] ....q,q'[t] ....v,b....0.05}; Consider the contour graphics for a=-l (single-well potential) and a=4 (double-well po- tential): 
238 Chapter 4 Nonlinear Oscillating Systems In[lll]:= contour = ContourPlot [ energy/ / .values/ /. { a.... #} / / Evaluate, {q, -15, 15}, {v, -15, 15}, Contours.... 10 , plotpoints .... 20, ColorFunction .... Hue, DisplayFunction- > Identity ]& I@. {-1, 4}; Displaying the two graphs, it follows In[112]:= Show[GraphicsArray[contour]]; .1 .1 The contour plot on the left is for the single-well potential and the one on the right is for the double-well. The contour graphs can be embellished if we superimpose the phase contours on a surface-energy plot. Consider the two-well potential with a=4 and b=O. OS. The Con- tourPlot is In[113]:= pt1 = ContourPlot [ energy/ / . values/ /. {a.... 4} / / Evaluate, {q, -15, 15}, {v, -15, 15}, Contours.... 10 , DisplayFunction.... Identity ] ; and the energy surface is 
4.3 Duffing Equation 239 In[114]:= pt2 = Plot3D[energyll.valuesll.{ a-+ 4 } II Evaluate, {q, -15, 15}, {v, -15, 15}, Plotpoints -+ 20, ColorFunction -+ (If [# < 0.226, Hue[O .9], Hue [0 .1] ]&:), DisplayFunction -+ Identity ] ; Combining the contour lines in eql with the energy surface in eq2, it follows In[115]:= Show[ pt2, Graphics3D [ {AbSOluteThiCkneSS[3], Cases [Graphics [pt1] , ..Line, 00]/. { q...Real , v_} : > {q,V,15 _2q2+1/2 v'I +0.0125 q '}} ] , ViewPoint -+ {O, 1, 0.8}, DisplayFunction -+ $DisplayFunction ] ; This energy surface clearly illusttates the motion of a bead sliding on a wire with the shape of the double-well. If the bead's energy is not sufficiently large it will form a periodic oscillation in one or the other well-the bead will be ttapped in the well. On the other hand, if the motion is sufficiently large the bead will oscillate between both wells. c. Let us consider a numerical example of the Duffing motion. Instead of solving the second-order Duffing equation, you can consider two equivalent first-order equations. The equations of motion written as two first-ordered equations are: 
240 Chapter 4 Nonlinear Oscillating Systems In[116] : = eq1 = {eqMotion/. {q" [t] .... p' [t] }, q' [t] == P [t] } Out[116]= {bq(t)3_ aq (t) +p'(t) ==O,q'(t) ==P(t)} Assume the initial conditions In[117]:= initial = {p[O] == 0.001, q[O] == OJ; and combine them with the Duffing equations, In[118]:= eq2 = Join [eq1, initial] ; Consider the case of a single-well with a=-i and b=O. OS. Applying NDSolve to eq2, you get In[119]:= ndsol1 = NDSolve [eq2//. {b.... 0.05, a.... -1}, {q[t],p[t]}, {t,O,30}]//P'latten Out[119]= {q(t)  InterpolatingFunction [(0. p (t)  InterpolatingFunction [ (0. 30. ),<>][t], 30. ), <>] [t] The solution is returned in terms of an J:nterpolatingFunction. You will find it convenient to define the displacement function qi and velocity function pi for this single- well case: In[120]:= q1[t_] =q[t]//.ndsol1; p1[t_] =p[t]//.ndsol1; To plot q and p versus t you define the general user-defined plot function In[121]:= pt[var_,opts___] := Plot [var[t], {t, 0, 30}, opts, Displayl!'unction- > Identity] The graphs of qi and pi versus t for the single-well potential are In[122]:= Show[ GraphicsArray[ {pt [q1, PlotStyle- > Hue [0.7] ] , pt[p1,PlotStyle- >Hue[0.9]]} ] ; o.oo  0.00 0.0005 0.000 -0.000 0 -0.000 -0.001 -0.001 
4.3 Duffing Equation 241 d. Let us now consider the double-well potential with a=4 and b=O. OS. Applying NDSol ve to eq2, you get the following numerical solution for this double-well potential, In[123]:= ndsol2 = NDSolve [eq2/ /. {b.... 0.05, a.... +4}, {q[t],p[t]}, {t, O,30}]//P'latten; Define the interpolating functions In[124]:= q2[t_] =q[t]//.ndsol2; p2[t_] =p[t]//.ndsol2; where q2 and p2 are the displacements and velocity for the double-well case. The plots of q2 and p2 versus t for the double-well potential are In[125]:= Show[GraphicsArray[ {pt [q2, PlotStyle- > Hue [0.7] ] , pt [p2, PlotStyle- >Hue[0.9] ] } ] ; 10  .: 5 1 202 0 -10 10 5 .5 -10 The left-hand graph is for the displacement q2 versus t and the right-hand graph is for the velocity p2 versus t. Notice how the graphs are sharply peaked. The two-well motion is certainly more complex than the one-well case but the motion is still periodic and repeats with a definite period. Using our analog of a sliding bead you see that the bead slides through one well and up to the top of the double-well. At the top of the double-well the bead slows and then falls toward the other well, picking up speed as it falls. The bead continues to oscillate between the two wells because there is no dissipative term to decrease the energy. The behavior of the solution depends on the initial conditions (energy). To analyze the details of the periodic motion consider its phase ttajectory: In[126]:= parametricPlot[ {q2[t] ,p2[t]} //Evaluate, {t, 0, 30}, AxesLabel .... {nqn, npn} , AspectRatio .... Automatic ] ; 
242 Chapter 4 Nonlinear Oscillating Systems p q e. To animate the motion define the user-defined function oscMovie: In[127j:= oscMovie[f_, tMax.., frames_, range_ :Automatic] .- Module [{t, i}, DO[ t = i tMax/frames; plot [i] = Show [ Graphics [ {pointSize[0.05], Point [{N[f [t]], O}]}, plotRange.... {range, {-1, 1}}], Axes.... True ] , {i,l, frames}] ] ; Given a periodic function f of variable t, this procedure animates the motion in one dimension. The input tMax is the final value of t, the range determines the size of the graphic window, and frames is the number of frames. This function is a straightforward application of a Do loop for graphics. Consider the animation for q2. To generate the graphic frames, apply oscMovie: In[128j:= frames = 1; oscMovie[q2, 30, frames, {-15, 15}]; 
4.3 Duffing Equation 243 1 0.75 0.5 0.25 -15 -10 -5 -0.25 -0.5 -0.75 -1 5 10 15 Only one frame is displayed. To view the animation increase the number of frames and double click on one of the cells. You get a movie of a bead sliding back and forth from one well to the other. . PROBLEM 2 Phase Diagram and Orbits for the Damped Duffing Equation. The equation for the damped Duffing equation is q"[t] - a q[t] + b q[t]3 + c q'[t] = 0 Assume c>O (damping) and let a be either positive (double-well) or negative (single-well). a. Set {b=0.05, c=0.15} and a=4 for the double-well potential and a=-l for the single-well potential. Make two phase portraits for these parameters using the command PlotVectorField. b. Use the user-defined function dispDuff with fo = wd=O, a=4, and b=O. 05 to graph examples of displacements that oscillate in the right well, left well, and both wells. Use the user-defined function phaseDuff defined at the beginning of this section with fo=O and wd=O to display the phase trajectories for your various solutions. Solution In[129]:= Clear["Global' *"] a. You cannot directly get a phase portrait from an analytic expression, because there is no conserved energy. However, the phase portrait does follow from PlotVectorField found in the add-on package Graphics' PlotField ': In[130]:= Needs["Graphics'PlotField'"] PlotVectorField plots a set of arrows that are tangent to the phase ttajectories. Consider b=O. 05 and c=o .15 and a=4 for the double-well potential and a=-l for the single-well potential. The phase portraits follow from 
244 Chapter 4 Nonlinear Oscillating Systems In[131]:= lista = PlotVectorField [ {p, #q- 0.05 q-3 - 0.15 p }, {q, -13, 13}, {p, -20 , 20 } , Plotpoints -+ 10, ScaleFunction -+ (0 .2#&:), ScaleFactor -+ None, DisplayFunction -+ rdentity ]&: Iii/. {4., -1}; Displaying the results, it follows In[132]:= pt1 = Show [GraphicSArray [lista] ]; j /f........................,,\ f /", // .\ /., / "\1 " \ " /'- 1\ \ I I / ! / ,'I \ i t \ \ ' , ! I \ III \  \\ \ i ,I : \ \ \ / 1'\  ' \ '/' \ \ ) 11  II ,\,,1. // / /r'-" -/>':"-1   I C\) :\ ',  \ \\1 \ r:7 ;  ! '11 . !,\  \\\ \ - - / 1,\ II \--/ I ' I I \  t /y 1 I The graph on the left is for the double-well and the one on the right is for the single- well. Notice, regardless of the initial conditions the orbits lose energy through dissipation and eventually spiral to the atttactors at the bottom of the wells. Referring to the model of a sliding bead, the bead loses energy due to dissipation and eventually ends up at the bottom. The exception is for the double-well, where the bead can remain at rest at the top of the well. This result is analogous to the phase portrait for the damped pendulum except there are not as many atttactors. b. Let us consider the double-well potential and plot the orbits that spiral around the left well, right well, and both wells before converging to either the right or left wells. The solution follows from applying NDSol va to the damped Duffing equation. We have made a general user-defined function, dispDuff, to numerically solve the general forced Duffing equation, q"[t] - a q[t] + b q[t]3 + c q'[t] = fo cos[wdt] and then plots the solution. In this problem we consider the special case where fo = wd=O. 
4.3 Duffing Equation 245 Let { a=4 , b= 0 . OS} and consider examples where the orbits are around the left well, right well, and both wells. After some trial and error, you find that the list of initial condi- tions {qO , pO } for the four cases are In[133]:= values = {{-4, 4}, {4,4}, {4,23}, {-4, -23}}; The graphics for the four displacements are In[134]:= listb = dispDuff[ # , {4, 0.05, 0.1, 0, 0},30,1000, PlotStyle -+ HUe [Random [] ] , PlotRange -+ All ] 50 /@ values; Displaying the results for the first two cases,{qO,pO}{ -4, 4} and {qO,pO} { 4 , 4 }, you get In [135] := Show[ listb [ [{1, 2}]], PlotRange -+ {{O, 30}, {-14, 14}}, Displayl"uDction -+ $DisplayFUnction ] ; The plot for the top curve corresponds to the initial values {qO,pO}={4,4}. The displacement is confined to the right well and eventually decays to the atttactor at the bottom of this well. The plot for the bottom curve corresponds to the initial condition {qO ,pO}={ -4, 4}. Its displacement is confined to the left well and decays to the atttactor at its bottom. Displaying the results for the last two cases,{qO,pO}{4,23} and {qO,pO} {-4, -23}, you get 
246 Chapter 4 Nonlinear Oscillating Systems In [136] := Show[ listb[ [{3, 4}]], PlotRange -+ {{O, 30}, {-14, 14}}, Displayl"unction -+ $DisplayPunction ] ; Both motions start out oscillating between both wells and then decay to the at- ttactors located at the bottom of the right or left wells. The plot for the curve with {qO,pO}={4,23} decays to the atttactor at the left. The plot for the curve with {qO,pO}={ 4, -23} decays to the atttactor on the right. The phase diagrams reveal the details of these motions. The phase diagrams follow from applying parametricPlot to the {q, p} solutions. We have made a general user- defined function, phaseDuff, to make the phase graphics for the general forced Duffing equation q"[t] - a q[t] + b q[t]3 + c q'[t] = fa cos[wdt] In this problem you are considering the special case where fa = wd=O, a=4 and b=O. 05. The initial conditions are given by the rules in values. The phase diagrams for these four solutions are In[13?]:= listc = phaseDuff[ # , {4, 0.05, 0.1, 0, O}, 30, 1000, PlotStyle -+ Hue [0 . 6] , PlotRange -+ All ]&: /@values; Displaying all four phase ttajectories, you get In[138]:= Show[GraphicsArray[Partition[listc,2]], DisplayPunction -+ $DisplayPunction ] ; 
4.3 Duffing Equation 247 This again confirms our description of the motion. The phase ttajectories can be thought of as showing the bead moving back and forth before it settles to the bottom of the well. The bead in the last two graphs moves between both wells before falling into one or the other well. The ttajectories for any combination of initial conditions will eventually decay to one or the other of the atttactors. Let us combine the bottom right phase ttajectory with the phase portrait given by lista [ [1] ]: In [139] := Show[ {listc[[4]] ,lista[[l]]}, PlotRange -+ {{-15,15}, {-20, 20}}, DisplayPunction -+ $DisplayFunction ] ; 5 Each atttactor has a basin of initial conditions that lead asymptotically to that atttactor. . PROBLEM 3 Driven Duffing Orbits with No Damping. Let us consider the driven Duffing equation q"[t] - a q[t] + b q[t]3 + c q'[t] = fa cos[wdt] with no damping, so c=O. There is no dissipation to cause the bead to settle into an atttactor so the long time behavior of the motion is governed by the periodic forcing term. 
248 Chapter 4 Nonlinear Oscillating Systems a. Consider the single-well potential with a=-l and set b= 1, fo=l/ 4, w d =2. Choose the initial conditions {q [0] = 2. 038, q' [0] = -1. 5} and plot the displacement and phase ttajectory. Show that the phase ttajectory is confined to an elliptical band and discuss the SITucture of the phase ttajectory by enlarging a portion of the graph. Examine its periodic sITucture by making a Poincare map of the solution. b. Consider a second example of a weak double-well potential with {a=l /5, b=l, fo=1/4, w d =2} and for zero damping, c=O. Repeat the calculation in Part a for the initial conditions {q [0] =0.99, q' [0] =O}. Solution In[140]:= Clear[RGlobal' * R] a. If you assume the initial conditions are q [0] =2 . 038 and q' [0] = -1. 5 then the plot of the displacement follows from the function dispDuff: In[141]:= dispDuff[ {2.038, -1.5}, { -1,1,0 , 1/4, 2 }, 100, 10000 , Plotpoints -+ 200, DisplayPunction - > $DisplayPunction ] ; 2 1 o -1 -2 The displacement appears to be periodic with a beat in the oscillation. To exam the periodicity consider its phase ttajectory that follows from phaseDuff, In[142]:= pt1 = phaseDuff[ {2 .038, -1.5}, { -1 , 1 , 0 , 1/4, 2 }, 100 , 10000 , Plotpoints -+ 300, DisplayFunction - > $DisplayPunction ] ; 
4.3 Duffing Equation 249 2 -1 1 -2 Although the phase ttajectory is not a single path, it is clear that the ttajectory is confined to an elliptical band. To view the detailed sttucture of the band-like sttucture enlarge the left end of the elliptical disk, In[143]:= phaseDuff[ {2 .038, -1.5}, {-1,1, 0,1/4, 2}, 100, 10000 , Plotpoints -+ 300, PlotRange -+ {{1.93, 2.2}, {-3, 3}}, DisplayPunction -+ $DisplayFunction ] ; There appears to be sttucture in the band! To further illuminate the sttucture, plot the end sttucture for time periods of t=20 and t=50. The two graphs follow from In[144]:= list = phaseDuff [ {2 .038, -1.5}, { -1,1, 0,1/4,2 }, ., 10000 , Plotpoints -+ 300, PlotRange -+ {{1.93, 2.2}, {-3, 3}} ]&: /@ {30,50}; Displaying the results, you get In[145]:= Show[GraphicBArray[list]]; 
250 Chapter 4 Nonlinear Oscillating Systems 3  '2 ''2 .3 -3 The complex periodic structure is clearly revealed with its Poincare section, In[146]:= pt2 = poincareDuff[ {2 .038, -1.5}, { -1 , 1 , 0 , 1/4, 2 }, 0 , 300, 10000 , Disp1ayFunc:tion - > $Disp1ayFunction ] ; c:..... .. 2 . . . . . .. . . .. . . .. 1 .. .. ., ... , \ 1.9 1. 95 2.05 2.1 2.1 ",' . .. .. .1 .. .. . . .. . . ... . . . ,c....... . . -2 Superimposing the Poincare map on the band to see the relation between the map and phase ttajectory, it follows In[147]:= Show[pt1,pt2, p1otRange... {{1. 8,2.4}, {-3 , 3 }} ] ; 2.2 2.3 b. Consider the second example for a small double-well with {a=1/5, b=l, c=O, £0=1/4, wd=2}. If you assume the initial conditions are q [0] =0.99 and q' [0] =0 then the plot of its displacement follows from 
4.3 Duffing Equation 251 In[148J:= dispDuff[ {0.99,0}, {liS, 1,0,1/4, 2}, 200, 10000, Plotpoints -+ 200, DisplayPunction - > $DisplayPunction ] ; 1 0.5 00 -0.5 -1 As in Part a, the path appears to be somewhat periodic with a beat in the motion. To exam the periodicity consider its phase ttajectory, In[149J:= pt3 = phaseDuff[ {0.99,0}, { 1/5,1,0,1/4,2 }, 300, 10000, Plotpoints -+ 200, DisplayFunction - > $DisplayPunction ] ; The complex sttucture in this band is revealed by its Poincare map. In[150J:= pt4 = poincareDuff[ {0.99 , 0 }, { 1/5,1,0,1/4,2 }, 0,350,10000 , DisplayPunction -+ $DisplayFunction ] ; 
252 Chapter 4 Nonlinear Oscillating Systems c::::> 0.6 0.4 0.2 (-, . -0.75-0.5-0.25 0.25 0.5 0.7 -0.2 C-f _)-0.4 C_...- -0.6 . PROBLEM 4 Two Well Driven Duffing Oscillators with Damping. Consider the driven Duffing equation with damping, q"[t] - a q[t] + b q[t]3 + c q'[t] = fo cos[wdt] Let the parameters be {a=1/2, b=1/2, c=0.3,w d =1} with the initial conditions q [0] = - 0 .13 and q' [0] = - 0 . 7 and investigate the changes in the motion caused by small changes in the driving amplitude. This will lead to chaotic motion as it did in the case of the driven pendulum. a. Consider two values of the amplitude, fo=O. 05 and 0.24, and plot the displace- ments, phase ttajectories, and Poincare maps. Show that the two motions are periodic and correspond to a period one cycle and period two cycle, respectively. b. Increase the amplitude a little further by letting fo= 0.29 and 0.32. Plot the displacements, phase ttajectories, and Poincare maps. Show that the motion for the first case is chaotic and the second is a looping motion with a period three cycle. Solution In[151]:= Clear[nGlobal' * n] a. Consider the driven Duffing equation with parameters a= 1 / 2 , b= 1 / 2 , c = 0 . 3 , £0=.4, and wd=l. If you assume the initial conditions q [0] =-0.13 and q' [0] =-0.7 then the graphics for the two displacements with £0=0.05 and 0.24 follow from In[152]:= lista = dispDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, I, 1}, 50,10000, Plotstyle -+ Hue [Random [] ] , Plotpoints -+ 200 ]&: /@ {0.05 ,0.24}; Displaying the results, you get In[153]:= Show [GraphicBArray [Partition [lista, 2]]]; 
4.3 Duffing Equation 253 10 20 30 40 50 .0.2 10f\20On50 = l/ {\ fl J I'1 f ll \ I -1  V V V \ V V 'J V -1. 4 After the ttansients die out, the displacements appear to go into periodic motion around the left well. The right graph appears to have both a large and a small component in the oscillation. To get a better idea of the periodic sITuctures, consider the phase ttajectories that follow from the command phaseDuff. The phase ttajectories for these two examples are In[154]:= lista = phaseDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, #,1}, 300 ,10000, Plotpoints ... 200 ]& I@ {0.05 ,O.24}; Displaying the results, it follows In[155]:= Show[GraphicsArray[lista]]; The graph on the left corresponds to a ttajectory that goes into periodic motion about the atttactor. It has a period one sITucture. The graph on the right has a double SITucture. The Poincare plots for the ttajectories follow from the user-defined function poincareDuff. Applying this procedure to these examples, you get In[156]:= listb = poincareDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, #,1}, 100,400, 10000, PlotRange... {{-2, 2}, {-1,1}}, Ticks... False, Displayl"uD.ction... Identity ]& I@ {0.05, 0.24}; Displaying the results, it follows In[157]:= Show[GraphicsArray[listb] ]; 
254 Chapter 4 Nonlinear Oscillating Systems The Poincare plot on the left returns one point so you know that the motion completes its cycle in the same time as the forcing function completes its cycle. It has period one motion. The Poincare map on the right is for period two motion and repeats every second cycle of the forcing function. b. Consider the driven Duffing equation with a further increase of the driving amplitude to £0=0.29 and 0.32. The graphics for these displacements follow from In[158]:= listc = dispDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, #,1}, 50 ,10000, PlotStyle ... Hue [Random [] ] , Plotpoints ... 200 ]& I@ {0.29, 0.32}; In[159]:= Show[GraphicsArray[listc]]; 1 0.5 il -0. 5  , " -1 \ / \j The left graph suggests the motion goes randomly from one well to the other and back again. The right graph has a more periodic nature but with sttucture in the path. To get a better idea of the periodic nature of the sttucture, consider their phase ttajecto- ries, In[160]:= listd = phaseDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, #,1 },300 ,10000, Plotpoints... 200 ]& I@ {0.29, 0.32}; In[161]:= Show[GraphicsArray[listd]]; 
4.4 Exercises 255 -1 5 The left phase diagram appears chaotic, as the orbit has an inclination to jump somewhat randomly from one well to the other. The right phase orbit is more regular and appears to be period three. The type of motion follows from its Poincare map. Applying the user-defined function poincareDuff to these examples, you get In [162] := liste = poincareDuff[ {-0.13, -0.7}, {0.5, 0.5, 0.3, 1,1}, 100,400, 10000, PlotRange... {{ -2, 2}, {-1, 1}}, Ticks... False, DisplayFunction... Identity ]& /@ {0.29, 0.32}; Displaying the results, it follows In[163]:= Show[GraphicsArray[liste]]; . l" . ... . ." ..---- Our suspicions are confirmed. The chaos motion has SITucture but does not appear to repeat. The period three example repeats every third cycle of the forcing function. . 4.4 . EXERCISES The solutions to many of these exercises can be found at our web site. 4.1 van der Pol Oscillator and Limiting Cycles The van der Pol oscillator is a classical example that illustrates the concepts of limiting cycles. These equations appear in the study of some oscillating electrical circuit. The system can be represented by two first-order equations, y'[t] = a(l - x[tf)y[t] - wox[t] x'[t] = y[t] 
256 Chapter 4 Nonlinear Oscillating Systems The van der Pol equation represents a system with a limiting cycle. Let the parameters be a=2 and w o =l and consider two trajectories that are singled out by the initial conditions {x [0] =0.06, y[O] =O} and {x[O] =0, y[O] =4}. (a) Find the numerical solutions for these two cases and plot x [t] and y [t]. (b) Compare their phase trajectories, {x [t] , Y [t] }. 4.2 Springs A particle of mass m is held at rest by two identical springs, each of natural length b with spring constant k. The whole system is on a smooth table. The particle is pulled directly to the side and released. (a) Show the motion can be described by the equation mX II [t J +2kX[t J [ l-  ] =o 1+ b (b) Make a phase portrait and numerically solve the equations for several different phase trajec- tories. (c) Add damping and forcing terms to the equation and discuss the nonlinear properties of the solution. 4.3 Buckling Column System Consider the oscillations of a single, flexible, column that supports a mass within a horizontally constrained space. The dynamics are described by the equations: dx dt = Y dy - = (1 - m)( + b + cy) dt where x represents the sideways displacement of the column, and y the velocity of its movement. The parameters m and c (c> 0) represent mass and friction, respectively. (a) Make a phase portrait for the buckling column model and discuss its behavior. (b) Numerically solve for several different phase trajectories. (c) Add a forcing term to the equation and discuss the nonlinear properties of the solution. 4.4 Nonlinear Equation Consider the nonlinear system dx dt = Y dy ( 4 ) - = -(1 - x)x - + x dt 3 (a) Find the potential and analyze the dynamics. (b) Make a phase portrait and discuss its properties. 4.5 Inverted Pendulum Consider a plane pendulum of a light stiff rod of length L with a mass m attached to its end. Assume the pivot oscillates vertically as Acos[wdt] with frequency w d and amplitude A. 
4.4 Exercises 257 (a) Show that the motion is described by ifl'[t] + (W 2 - W COS[Wdt]) sin[lji] = 0 (b) Find the conditions under which the inverted vibrating pendulum is stable and analysis its motion. 4.6 Driven Nonlinear Equation Consider the nonlinear equation x"[t] + A x[t] + w x[t](l + k x[tf) + c x'[t] = A cos[t w] (a) Set A=O, make a phase portrait, and discuss the solution. (b) How do the phase space trajectories change if A is nonzero? 
CHAPTER 5 258 Discrete Dynamical Systems 5.1 . INTRODUCTION A dynamical system can be described by a discrete or continuous change. In the previ- ous chapter we dealt with the behavior of nonlinear systems, where the continuous time evolution was described by differential equations. We considered the behavior of the non- linear pendulum and the Duffing equations, and graphed examples of phase ttajectories that included fixed points, periodic motion, and chaotic behavior. Discrete maps were used to make Poincare sections, which are snapshots of the phase plane taken at each drive period; the maps reduced the periodic behavior to the study of points. Maps are discrete time analogs of a continuous system. Any numerical solution of a differential equation that uses discrete time steps in the approximation is effectively a map. Maps help explain, for example, why a continuous-time system, which should not exhibit chaos, may have numer- ical solutions which do. Many of the earliest numerical studies of chaos began by studying maps. In this chapter we explore the best known discrete systems. A map is an equation of the form Xl = f[x o ] that gives the state Xl resulting from the initial state xo' The map f[x] starts from some initial condition, feeds that number into the map to produce a second value, feeds that value back into the map to produce a third point, and so on. The orbit of the map is the sequence of points generated from an initial condition. A point on the orbit of a discrete map is indexed by an integer n, which may be thought of as the discrete analog of time. Maps that start from different initial conditions eventually settle into one of three dif- ferent types of behavior: fixed points, periodic orbits, or chaotic behavior. A fixed point is like an equilibrium point. For example, a harmonic oscillator with zero velocity located at its equilibrium position will remain at that point. Fixed points are unchanged by their maps and satisfy equations of the formf[f[...f[x]]] = X, where f is the map. Certain fixed points are atttacting; if you start from a point close to a fixed point, then the orbit will be atttacted to the fixed point. The damped pendulum is an example where the swing eventu- ally comes to rest at its atttactor. Repelling SITuctures tend to evolve away from the fixed point, like the motion near an unstable equilibrium position. Periodic orbits occur when points alternate between two or more fixed values. The properties of the orbit can change as the parameters of the map are varied. The values of a parameter where the nature of the motion changes are known as bifurcation points. For instance, at a bifurcation point a period one orbit can split into a period two orbit and eventually become chaotic. Chaos, the unpredictable long time behavior, is a consequence of the system's sensitivity to initial conditions. No matter how precisely you measure the initial condition in these systems, your prediction of its subsequent motion goes radically wrong after a short time. 
5.1 Introduction 259 In this chapter we consider two ways to quantify chaos, one with its Lyapunov exponent, and the other with its enttopy. The Lyapunov exponent quantifies the divergence of orbits in chaotic systems. More precisely, consider a map f[x] and allow the system to evolve from two slightly differing initial states, x and x + s. After n iterations the diverging orbits may be characterized by Ifnex + s) - fnex)1 "" se nAn where rex) = f[f[...f[x]]]. The parameter An represents the rate of divergence. In the limit that s goes to zero, the Lyapunov exponent is determined by the derivative of the map A ""! In l rex + s) - rex) I "" ! 1n I dr[X] I nn s n dx The Lyapunov exponent is defined as A = Limit[An' n  00]. It can be shown that this is equivalent to n-I A= lim!  ln l dr[X] 1 n....oo n L..J dx i=O The expression A measures the exponential separation rate between two nearby orbits. If A is negative, then the orbits converge, and the dynamical system is insensitive to its initial conditions. However, if A is positive, then the distance between nearby orbits grows exponentially, and the system is sensitive to the initial conditions. Another way to quantify the disorder in chaos is by its enttopy. If P is a list of probabil- ities {pJ, then the enttopy is defined as n enttopy = - L Pi 10g[p;J i=1 Enttopy measures the homogeneity of the system's distribution into its various states. A system with very low enttopy is usually found in one of a small number of possible states, and is said to be more predictable than a system that wanders around among a large number of states. If the system has only one allowed state we say it is perfectly ordered-we know in advance what state the system is in and hence have gained no new information. If the subintervals are equally probable then the enttopy has its maximum value. A study of chaos would not be complete without a comment about fractals. Chaotic systems almost inevitably give rise to fractals. Fractals exhibit self-similarity and are inde- pendent of scale-if you concentrate on one portion of the fractal the resulting pattern is similar to the original. In this chapter we consider the two canonical examples of this class, the Mandelbrot and Julia sets. There are three sections on problems: Logistic Map, Other Maps, and Fractals. At the beginning of each problem section we include an overview of the topic followed by several representative problems. This chapter concludes with a set of exercises. Before starting this chapter you might want to turn off the spell checker: In [lJ : = Off [General: : spell]; Off [General: : spelll]; 
X n = Jl Xn-l (1 - X n - 1 ) 260 Chapter 5 Discrete Dynamical Systems 5.2 . LOGISTIC MAP 5.2.1 . Overview In this section, we illusttate the various behaviors that maps can have by considering the simple logistic map. The map is defined by where Jl is a parameter in the range 0 to 4 and x n is between 0 and 1. All initial conditions eventually settle into one of three types of behavior: 1. Fixed points are points where the iterations approach a stable value like the motion of an overdamped harmonic oscillator. 2. Periodic orbits are points where the iterations alternate between two or more fixed values. 3. Chaotic orbits are points where the iterations continue to vary wildly. . PROBLEM 1 Logistic Map. Consider the logistic map described by x n = Jl xn-l (1 - x n - 1 ), where Jl is a parameter to be set anywhere from 0 to 4 and the range of x is between o and 1. As Jl varies, there are bifurcation points where the behavior of the orbit changes. a. Define a user-defined function that returns n iterations of the logistic map. Let Jl = 2.9 and find the first 50 iterations starting at xO=O .1. Show that the iterations approach a fixed point at 0.655. Define a user-defined function that automatically graphs the orbit. Apply the user-defined procedure to this example. b. As Jl increases the orbit period doubles, changing from 2 to 4, from 4 to 8, etc. Eventually the orbits become chaotic. Let Jl = 3.4 and plot the period two orbit. Let Jl = 3.54 and plot the period four orbit. Plot a period eight orbit by setting Jl = 3.55. Finally, show that Jl = 3.57 leads to a chaotic orbit. Solution In[2J:= Clear [oGlobal ' * 0] a. Define the logistic map In[3J:= map[.] :=#(l-#)&; If you start the map at xO, then the first two iterations give In [4J : = {xO, map [ ] [xO], map [] [map [ ] [xO]]} Out[4J= {xo, (l-xO)xO!1, (1-xO)x0!1 2 (1- (l-xO)xO!1)} 
5.2 Logistic Map 261 This sequence of iterations can be expressed very succinctly using NestList. Starting at xO and applying NestList to the logistic map n times, you get the following user- defined function for the orbi t, In [5] := orbit [j.L, xO_, n_] : = NestList [ j./# (1 - #) &:, xO , n ] where xO is the starting point and n is the number of iterations. For example, the first two iterations are In[6]:= orbit [j./, xO, 2 ] Out[6]= {XO, (1- xO) xO fJ., (1- xO) xO fJ.2 (1- (1- xO) xO fJ.) } Consider the map for J1 = 2.9 with a starting point at xO=O .1. The first 20 points are In [7] := orbit[2.9 ,0.1,20] Out[7]= {0.1, 0.261, 0.559349, 0.714785, 0.591215, 0.700871, 0.607987,0.691183,0.619003,0.683931,0.626891, 0.678306,0.6328,0.673856,0.637345,0.670296, 0.640898,0.667428,0.643707,0.66511,0.645942} The points appear to be approaching a fixed point. You can find the fixed point by considering 300 iterations or so, and drop all but the last 8 points. Doing this, you get the limiting value or fixed point In [8] := Take [orbit [2.9, 0.1, 300], -8] Out[8]= {0.655172, 0.655172, 0.655172, 0.655172, 0.655172,0.655172,0.655172,0.655172} To plot the orbit, you can define a user-defined procedure that applies ListPlot to the iteration points. Adding some additional options, the user-defined function is In [9] : = orbi tplot [j./_, start_, n_ , Opts___] : = ListPlot [NestList [ j./# (1- #) &:, start, n], Opts, PlotStyle... {AbsolutePointSize [4], RGBColor[l, 0, O]}, GridLines- > Automatic, Epilog ... ListPlot [NestList [j./# (1 - #) &:, start, n] , PlotJoined ... True, DisplayFunction... Identity ] [[1]] 
10 20 30 40 50 n , 262 Chapter 5 Discrete Dynamical Systems Applying orbitplot to this example, it follows In[lO]:= orbitplot[2.9,O.l,50, AxesLabel ... {n, Xi} ] ; x' , O. 0.6 0.6 0.6 0.6 10 20 30 40 50 n The graph illusttates how the orbit converges to the attracting fixed point at 0.655. This graph is very similar to a damped oscillator where the amplitude of the oscillations goes to zero. b. To show a period two orbit, let the starting point be xO=O.l and set J1=3. 4. The graphic for the first 50 iterations is In[ll]:= list = orbitplot [3.4,0.1,50, PlotRange... {Automatic, {O,l}}, AxesLabel ... {n, Xi}]; x' , O. ;Il{\ r f- i   O. O. O. The asymptotic points appear to be oscillating between two values. To locate the values, consider the first 200 iterations and drop all but the last 8 iterations: In[12]:= eql = Take [orbit [3.4, 0.1,200], -8] Out[12]= {0.451963, 0.842154, 0.451963, 0.842154, 0.451963,0.842154,0.451963,0.842154} The period two orbit oscillates between 0.84 and 0.45. An alternate way of exttacting just these two values is to apply union to this list, 
5.2 Logistic Map 263 In[13]:= Union [e Q 1, SameTest -+ (AbS [ (#2 - #1)] < 10- 12 .) ] Out[13]= {0.451963, 0.842154} A period four orbit follows from choosing a starting point at xO=O.l and setting J1=3. 54. The orbit plot for the first 50 iterations is In[14]:= list = orbitp1ot[3.54, 0.1, 50, P10tRange -+ {Automatic, {O, 1}} , AxesLabe1 -+ {n, Xi}]; Xi o. 10 20 30 40 n 50 o. o. o. The asymptotic points appear to be oscillating between four values. If you consider the first 200 iterations and drop all but the last 8 iterations then the four limiting values follow from In[15]:= eQ2 = Take [orbit [3 .54,0.1,200], -8] Out[15]= {0.521835, 0.883312, 0.364874, 0.820363, 0.521682,0.883336,0.36481,0.820302} This period four orbit oscillates between the four points, In [16] := Union [e Q 2, SameTest -+ (AbS [(#2 - #1)] < 10- 4 .)] Out[16]= {0.36481, 0.521682, 0.521835, 0.820302, 0.883312} To illusttate a period eight orbit let the starting point be xO=O.l and set J1=3. 55. The orbit plot for the first 50 iterations is In [171 := list = orbitp1ot[3.55, 0.1, 50, P1otRange-+ {Automatic, {O, 1}}, AxesLabe1 -+ {n, Xi}]; 
264 Chapter 5 Discrete Dynamical Systems X' 1 o. 10 20 30 40 n 50 o. o. o. The asymptotic points appear to be oscillating between eight values. If you consider the first 1000 iterations and drop all but the last 16 iterations, you get the pattern for the limiting values In[18J:= eq3 = Take [orbit [3.55, 0.1,1000], -16] Out[18J= {0.540475, 0.881684, 0.370326, 0.827805, 0.506031,0.887371,0.3548,0.812656, 0.540475,0.881684,0.370326,0.827805, 0.506031,0.887371,0.3548,0.812656} The orbit oscillates between the eight points: In[19J:= Union [e Q 3, sameTest -+ (AbS [(#2 - #1)] < 10- 12 &) ] Out[19J= {0.3548, 0.370326, 0.506031, 0.540475, 0.812656,0.827805,0.881684,0.887371} An additional increase in J1 eventually leads to chaotic orbits. Let the starting point be xO = 0 . 1 and set J1 = 3 . 7. The orbit plot for the first 200 iterations is In[20J:= list = orbitp1ot[3.', 0.1,200, P10tRange -+ {Automatic, {O, 1}}]; o. o. o. o. 50 100 150 200 There doesn't appear to be any repeatable order to the points. 
5.2 Logistic Map 265 . PROBLEM 2 Logistic Fixed Points. Fixed points are like equilibrium points in phase space; if the system starts at that point it will remain there. If the map starts at a fixed point the map does nothing. For example, if xO satisfies the equation f [xO , Jl] =xO, where f is the logistic map, then xO is a fixed point of period one. A period n point is a point xO that after n iterations the map comes back to xO . For example, a period two fixed point satisfies the equation f [f [xO , Jl] , Jl] =xO. The general periodic point satisfies an equation of the formf[f[...f[xO]...]] = xO. a. Find all period one and period two fixed points for a general Jl. Define a procedure to return the nth fixed point if the value Jl is given. Set Jl=7/2 and find the fixed points for periods 1 through 4. b. There is a graphic way to determine the solution of the fixed point equation x= f [f [ . . . [x] . . . ] ] . If you plot the left and right sides of this equation, then the fixed point is determined by the intersection of the curves. Graph the period one fixed points for Jl=7/2. Define a user-defined function for period n fixed points. Let Jl=7/2 and illusttate the period 1 through 4 fixed points. c. To see how the fixed points change as Jl changes, graph the period two fixed points for Jl=2 . 5, 3, and 3.5. Solution In [21] := Clear ["Global '*"] a. The period one fixed point satisfies the equation f [x] =x, where f is the logistic map. Since the map is given by Jl x (i-x) the equation for the period one fixed point becomes In [22] := period[l] =  xO (1 - xO) == xO/ /Solve [#, xO]. / / Flatten Out [22]= { J.1-1 } xO -> 0, xO -> ----;;- There are two fixed points, one at 0 and the other at J1-1 . The fixed point at the origin is J1 repulsive because points near the origin always tend away from it. The fixed point at J1-1 is an atttacting point because starting points near this value converge to this fixed point. J1 Period two fixed points follow from applying the map f [f [xO] ] =XO twice: In [23] := Nest [# (1- #)., xO,:2 ] == xO Out[23]= (1-xO)x0J.1 2 (1- (l-xO)xOJ.1) ==xO The solution for the period two fixed point is 
266 Chapter 5 Discrete Dynamical Systems In[24]:= eq1= Nest[lli(1-i)&,xO,2] ==xOII Solve [I, xO] & llPullSiq>lify I I Flatten Out[24]= { 11-1 11- .y (11-3) (11+1) +1 xO .... 0, xO .... - , xO .... , 11 211 11+ .y (11-3) (11+1) +1 } xO .... 211 Note the solution for the period two points contains period one fixed points. The ttue period n points are points that are not periodic for any smaller value of n.The ttue period two points are In [25] := period[2] = Comp1t [eq1, period [1] ] Out[25]= { 11- .y (11-3) (11+1)+1 xO.... , 211 11 + .y (11 - 3) (11 + 1) + 1 } xO .... 211 Let us consttuct a numerical function that returns the solutions for the general fixed point equation f [f [ .., f [x] . ..] ] =x. The user-defined function is In [26] : = fixedpoint [Il., IL, opts...] .- Module [ {temp1, xO), teD\P1 = Nest [Ili (1 - i)&, xO, n] == xOI I NSo1ve[i, xO, opts] & ; Select [xOI .temp1, Abs [J:m[i]] < 10- 10 &] where n is the period of the fixed point. Select was applied to eliminate the complex solu- tions. The period 1 through 4 fixed points for J1=7/2 are In [27] := {pt1, pt2, pt3, pt4) = fixedpoint [712, i ] &1@Range [4] II Rationalize; {pt1,pt2,pt3,pt4}IICo1umnForm Out[27]= {O, } {o,!,,} {o, "7} {O, 0.38282, 0.428571, 0.500884, 0.714286, 0.826941, 0.857143, 0.874997} The period one fixed points are at {O, }. Eliminating the lower period, you see that the ttue period two points are {, }: 
5.2 Logistic Map 267 In [28] := Comp1t [Pt2, pt1, SameTest -+ (AbS [ (#2 - #1)] < 10- 3 &:)] Out[28]= { - - } ,  There are no period three points, but the period four points are: In [29] := Comp1t [Pt4, pt2, SameTest -+ (AbS [ (#2 - #1)] < 10- 4 &:)] Out[29]= {0.38282, 0.500884, 0.826941, 0.874997} b. There is a graphic way to solve the fixed point equations x=f [f [ . . . [x] . . . ] ] . If you plot the left and right sides of x=f [f [. . . [x] . . .] ], then the fixed points are determined by the intersection of the curves. Let J1=7/2 and find the graph for the period one fixed points. The period one equation is x= x (i-x). If you combine the graph of the right side of this equation with the graph for a sttaight line x, then you get In [30] := P1ot[{7I2#(1-#)&:[x] ,x}, {x, 0,1), P1otSty1e -+ {Thickness [0.01], RGBCo1or[l, 0, 0]), GridLines -+ Automatic, Epilog -+ {pointSize [0.04], Hue [0.3], Map [Point, Transpose [{ fixedpoint [7/2,1], fixedpoint [712,1]}]]} ] ; o. o. o. o. The intersections give the two period one fixed points. A function that graphically solves for the period n fixed point is 
268 Chapter 5 Discrete Dynamical Systems In [31] : = fixedpointG [_, n_, Opts___] .- Plot [{x, Nest [# (1 - #)., x, n ] } / / Evaluate, {x, 0, l}, Opts, PlotStyle -+ {{Thickness [0.01], Hue [Random[] ] }, {Bue[Random[]]}}, DisplayFunction- > Identity, Epilog -+ {PointSize [0.04], Hue [0.3], Map [Point, Transpose [{ fixedpoint [, n], fixedpoint [, n] } ] ]} Consider the fixed points for periods one through four. The graphic solutions for periods one, two, three, and four follow from In [32] := list = fixedpointG [712, #, PlotLabel -+ #]. /@ Range [4,1, -1] ; Displaying the results with GraphicsArray, you get 4 In[33]:= Show [GraphicsArray [partition [list, 2]]]; 3 2 1 0.8 0.6 0.4 0.2 1 The intersection of the sttaight line and curves give the fixed points. The graph at the top left starts with the fixed point 4 solutions followed to the right by fixed point 3. The bottom left is for fixed point 2 and fixed point 1 is the right graph. Superimposing all the graphs illusttate how the lower period fixed points also occur in the solutions for the higher periods. In[34]:= Show [ list, DisplayFunction-+ $DisplayFunction]; 
5.2 Logistic Map 269 4 c. One can see period two points being "born" by watching the graph for f [f [x] ] change as the parameter J1 passes through 3. Consider the fixed point graphics for J1=2 .5, 3 and 3.5: In [35] := list2 = fixedpointG[#, 2, Ticks -+ HO, 1/2, l}, {O, 1/2, l}}, PlotRange -+ HO, l}, {O, l}}, PlotLabel-+ #]« /@ {2.5, 3, 3.5} Displaying the results, it follows In [36] : = Show [ GraphicsArray [ {{list2 [[l]]}, {list2[[2]], list2[[3]]}}], PlotRange -+ All]; +t2:= 1 1 "2 1 3 +ti2J 1 1 "2 1 "2 The graph starts out at J1=2 . 5 with only period one fixed points. As J1 increases to 3 the center of the graph dips down and the ends increase in height until finally at J1=3 . 5 the curve and sttaight line intersect at four locations, creating two period one fixed points and two period two fixed points. 
270 Chapter 5 Discrete Dynamical Systems . PROBLEM 3 Logistic Cobwebs. The logistic map has a visual equivalent for displaying its orbit and fixed points. Draw a line from x on the x-axis to the function on the y-axis. Take the y value and feed it back to the function and draw a horizontal line from {XI f [x] } to the line y=x. This takes you to the point {f [x] I f [x] }. The vertical line drawn from that point to the function takes you to {f [x] If [f [x] ] }. If the process is continued, then the lines form a pattern called cobwebs. If there are period n points, then the pattern of cobwebs will repeat. a. Define a user-defined function for the cobweb. Let J1 =7/2 and start the iterations at x= , , and 4. These three starting points illusttate period 1, period 2, and period 4 fixed points. b. Let J1=3. 99 and plot its chaotic cobweb. Solution In [371 := Clear [RGlobal ' * R] a. Let xO be the starting point of the logistic map. Notice the coordinates for the lines de- scribed in the problem form a pattern like { {xO I O} I {xO I f [xO] } I { f [xO] I f [xO] } I {f [xO] If [f [xO] ] }, ... }. To make a user-defined function, describe the pattern with a list, partition the list, and then join the coordinates with a line. The user-defined function is In[38]:= cobweb[f.,xO.,n., opts.._] := Module [ {templ, temp:2, points, s , x}, teD\Pl [s_] : = Nest [f [I] &, xO , s ] ; temp:2 = {templ [# ] , teD\Pl [# ] , templ [# ] , templ [# + 1] }&I@Range [1, n] ; points = {xO, 0, xO, f [xO], temp:2 } 1II'1atten II partition [I, :2] & ; Plot [{x, f[x]}, {x, 0, l}, Epilog- > {Rue [0 .9], Line [points]}, opts] where f is the map. The cobweb starts at xO and then performs n iterations. The argument opts___ means that you can add options to the cobweb. Let J1 =7 /2 and start the map at x= 517. After 30 iterations the cobweb-diagram is In[39]:= cobweb [712 #(1-#)&, 517,30]; 
5.2 Logistic Map 271 Since x=5/7 is a period one fixed point, the iterations do not change the pattern. The fixed points for period 2, and period 4 orbits are t and !. The graphics for these cobwebs follow from In[40]:= list = cobweb [712 #(1-#)&, #,10, Displayl'unction -+ :Identity] &/@ {3/7,112}; Displaying the results, you get In [41] : = Show [GraphicSArray [list ]]; These graphics single out the period 1, period 2. b. As J1 increases, the system eventually bounces about forever, but never repeats. For example, consider the cobweb for J1=3. 99: In[42]:= cobweb[ 3.99#(1-#)&,1/2,150]; 0.4 0.6 0.8 1 There does not appear to be any asymptotic pattern. 
272 Chapter 5 Discrete Dynamical Systems . PROBLEM 4 Logistic Bifurcations. An elegant way to examine the behavior of the map as j1 changes is to make a bifurcation diagram. A bifurcation diagram plots j1 on the hor- izontal axis and x n points on the vertical axis. Define a bifurcation diagram and plot the results for the logistic map. In[43] : = clear [nGloba1 ' * n] Solution Consider a user-defined function that calculates an orbit with 100 points starting at the initial point 0.62. Take the last 25 orbit points so that the ttansients have died away. The command that does this is In[44]:= Lva1ues = Compile [{}, ({, #}&) /@ Drop [NestList [# (1 - #) &, 0.62, 100], 75]]; The procedure has been compiled to make it faster. The bifurcation diagram follows from generating a table of these values for different j1. In[45]:= bifurcation[O_, L, n_] := Flatten [Table [Lva1ues [], {, O, 1, (1 - O) /n}] , 1] The starting value is j10, the final value is j11, and n is the number of j1-divisions. Let us apply bifurcation for n=400 and with j1 in the interval {3, 3.99}: In[46] : = Spoints = bifurcation [3, 3.99,400]; Plotting the points, it follows In[47]:= pt1 = ListP10t [Spoints, GridLines -+ Automatic, P1otsty1e -+ {Bue[0.9],Abso1utePointSize[1.4]}, Epilog -+ { Thickness [0.007], Line [H# , O}, { # , 1}} ] & /@ {3.45, 3.54, 3.564}} ] ; 
5.2 Logistic Map 273 O. O. O. O. We have added three vertical lines at J.l ={3.45, 3.54, 3.564} to show the beginning bifurcation points. The region beyond 3.57 has windows of periodic behavior interspersed with the chaos. . PROBLEM 5 Logistic Lyapunov Exponent and Entropy. Let us quantify the chaos by calculating the Lyapunov exponent and the enttopy. a. The expression for the Lyapunov exponent is given by the expression n-l A = lim!  In I dF[XJ I noo n L.J dx i=O Calculate and plot the Lyapunov exponent over a range of J.l values from 3.5 to 4. b. Calculate and graph the enttopy, - 2:7=1 Pi 10g[pJ, where Pi is probability for how many times each of the J.l-bins is hit by the map. Compare the enttopy graph with the Lyapunov graph. Solution In[48]:= Clear[RGlobal' * R] a. Let us define a user-defined function for the Lyapunov exponent: n-l A= lim! ln l dF[X] I . noo n L.J dx i=O The first step is to define the map In[49]:= f[L] :=u#(l-#)6i:; Next take the Log of the absolute value of its derivative, In[50]:= LGder[.] := Log[Ahs[* (1-2#)]]6i: The Lyapunov exponent for J.l between 3.5 and 4 follows from the table of values 
274 Chapter 5 Discrete Dynamical Systems In[51]:= data = Table [ {Il, 1/1000 LGder [Il ] [ NestList [Il * # (1 - #) &:, 0.1, 999]] /. List....Plus}, {Il,3.5,4.,O.001}]; where the command ListPlus was used to sum the terms. Plotting the results, you find In [52] : = ptl = ListPlot [data, PlotRange- > {-1, 1}, PlotJoined- > True, PlotStyle.... Thickness [0.001], AxesLabel .... {Il, .A}] ; J1 Slightly separated ttajectories converge if A is negative. If A is positive then nearby tta- jectories diverge and the evolution is sensitive to initial conditions, and is therefore chaotic. The sharp dips indicate positions of superstable orbits. b. Let us calculate the enttopy over the range 3.5 :$ J.l :$ 4. The enttopy follows from - L:7=1 Pi 10g[pJ, Define the enttopy function In [53] := Entropy[p-List] : = - p. Log[p] where p is the list of probabilities for how many times each of the J.l-bins is hit by the map. You must now calculate data for a range of J.l values. First, consttuct a list of iterates for the map starting at xO=O .1, In[54]:= fdata[Il_] := Drop[NestList[Il#(l- #)&:,0.1,500],400] where the orbits had 500 values but only the last 100 points were kept to avoid the ttan- sients. Now bin J.l. This step requires the command BinCounts found in the add on package: In[55]:= Needs [nStatisticS'DataManipulation,n] The BinCounts command does the following: 
5.2 Logistic Map 275 In[56]:= ?BinCounts BinCounts[{xl, x2, ...}, {xmin, xmax, dx}] gives a list of the number of el- ements in the data {xl, x2, ...} that lie in bins from xmin to xmax in steps of dx. The bin boundaries are {xmin < x <= xmin + dx, ..., xmax - dx < x <= xmax}. BinCounts[{{xl, yl}, {x2, y2}, ...}, {xmin, xmax, dx}, {ymin, ymax, dy}] gives a two-dimensional array of bin counts for the bivariate data {{xl, yl}, {x2, y2}, ...}. In general, BinCounts gives a p-dimensional array of bin counts for p-variate data. More... The probability for how many times each of the Jl-bins is hit by the map follows from In[57] := probUL] : = Select [ 1/S00 BinCounts[fdata[] , {0.,l,l/S00}] , Positive] where the bin width is 5 ' The Select command was used to eliminate the BinCounts that were zero. The enttopy data follows from In [58] := entropylist = Table[{, Entropy[prob[]] }, {,3.S,4, O.OOS}]; You get the enttopy plot by applying Listplot to entropylist, In [59] : = pt2 = ListPlot [entropylist, PlotJoined .... True, GridLines .... Automatic, PlotStyle.... 'l'hickness [0. OOS], AxesLabel .... {, "Entropy"}] ; Entropy 3 ..... A. , ., .... .., f" .... 'YV ,- II 5 3 6 3 7 3 8 3 9 v. _ r   J J1 The dip in enttopy occurs at values of Jl where the bifurcation diagram has windows. The enttopy is largest in the chaotic region where ttajectories lose information about their previous history. To compare the enttopy and Lyapunov exponent diagrams, you superimpose the previ- ous plots ptl and pt2: 
276 Chapter 5 Discrete Dynamical Systems In[60J:= Show[ptl,pt2, PlotRange.... {{3 .5,3 .9}, {-1.5, 1.5}}, Ticks.... {Automatic, None}]; A 11 . The top curve is the enttopy and the bottom is the Lyapunov exponent diagram. 5.3 . OTHER MAPS 5.3.1 . Overview In this section we consider four well-known maps: Salmon, sine-circle, Taylor-Greene- Chirikov, and the Henon maps. The first map is a generalization of the logistic map and is defined by the iterations X n = xn-l expfp(1 - x n - 1 )] Since this map has been used to describe the development of a salmon population, it is called the salmon map. The one dimensional sine-circle map is defined by On = 0n-l + n. +  Sin[ 21TO n_d where the angular coordinate ° is limited to the range of 0 :$ ° < 1. The boundaries at 0 and 1 are assumed to be periodic. This map with its Sin[2nB n _d term is reminiscent of the pendulum equation. A similar periodic boundary condition was applied to the motion of a pendulum because the physical range of its angle was between {-1T, 1T}. The properties of the sine-circle map are parameterized with two constants {n., K} in conttast to the single parameter J.l for the logistic and salmon maps. The value of K gives the sttength of the nonlinear term. Each orbit has a winding number w = lim F[Oo] - °0 n-+oo n where F[Oo] is the sine-circle map without its periodic boundary conditions. The winding number is like counting the number of times a pendulum loops over the top. 
5.3 Other Maps 277 The Taylor-Greene-Chirikov and the Henon maps are two-dimensional maps. The two- dimensional Taylor-Greene-Chirikov map is a generalization of the sine-circle map and is defined by the iterations 0n+l = On + in + k sin [On] & in+l = in + k sin[On] where ° and i have periodic boundary conditions over the interval 0 to 2n. Finally, the two- dimensional Henon map is one of the icons of chaos theory, and no tteatment of dynamical systems is complete without it. The two-dimensional Henon map is defined by x n + 1 = 1 - a  + Y n & Yn+l = b x n . PROBLEM 1 Salmon Map. Consider the salmon map x n + 1 = x n exp[p(1 - x n )]. a. Plot orbits for J.1. = 1.8, J.1. = 2.2, J.1. = 2.6, and J.1. = 2.99 and describe the results. b. Plot its bifurcation diagram. c. Plot the Lyapunov exponent and compare it to the bifurcation diagram. d. lllusttate the sttucture in chaos by comparing two series, one white noise (random numbers taken from a normal distribution with mean 1 and standard deviation 0.5) and the other points taken from the salmon map with J.1. = 2.9. Plot the return maps, where the return map is a plot of the pairs, {Xi' X i + I}' Solution In [61J : = Clear ["Global' * "] a. Define the salmon map. In [62J := map[.] := #1!:xp[(1- #)]Ii: Let the starting points be xO=O. 4. and consider the orbits for J.1. = 1.8, J.1. = 2.2, J.1. = 2.6, and J.1. = 2.99. The user-defined function to graph the orbit is In [63 J : = orbitG [_, start_, n_ , Opts___] : = ListPlot [NestList [map [ ] , start, n ] , Opts, Displa.yFunction- > :Identity] Consider the values J.1. = 1.8, J.1. = 2.2, J.1. = 2.6, and J.1. = 2.99: In[64J:= values = {1.8, 2.2,2.6, 2.99}; The graphics for the four orbits follow from In [65J := list = orbitG[#, 0.4, so, PlotStyle -+ AbsolutePointSize [2] , Ticks -+ PaIse, PlotLabel -+ # ] Ii: III values; 
278 Chapter 5 Discrete Dynamical Systems Displaying the results, you get In [66] := Show[GraphicsArray [ {list[[{1,2}]], list[[{3,4}]]}]]; 1.8 2.2 ...............-..-.- . . ... . . .... . . ........... 2.99 . . ..-. . . . . . . .. ............ ............. . . . a.- a._ .... . . . ... If j.1. is 1.8, there is one fixed point. The orbits with j.1. = 2.2 and j.1. = 2.6 show period 2 and period 4 orbits, respectively. The value of the fixed points follow from looking at the last four points of the orbits. The points for j.1. = {1.8, 2.2, 2.6} are In[67]:= Take [NestList [map[#], 0.5,200], -4]&:/80 {1.8, 2.2 ,2.6}//ColUJIIDForm {1.,1.,1.,1.} Out[67]= {1.50294, 0.497059, 1.50294, 0.497059} {1.90477, 0.181222, 1.52317, 0.390846} The orbit withj.1. = 2.99 is chaotic. b. The bifurcation diagram allows you to see the change in the salmon map as j.1. varies. Start by evaluating the orbit for 200 points and take the last 25: In [68] := SValues = Compile[{}, ({, #}&:)/8o Drop [NestList [#I!:xp [(1 - #)] &:, 0.5,200], 175]] ; The starting point was chosen atxO=O. 5 and the procedure was compiled to make it faster. The bifurcation diagram follows from generating a table of these values for different j.1., In[69]:= bifurcation[O.,l_,n_] := Flatten [Table [SValues [], {, O, 1, (1- O) /n}], 1] The starting value is j.1.0, the final value is j.1.1, and n is the number j.1.-divisions. If you take 1000 values of j.1. from the interval (1.9, 3.5) then you get the following list of points. In[70]:= gpoints = bifurcation[1.9, 3.5,1000]; The bifurcation diagram follows from displaying the data points: 
5.3 Other Maps 279 In[71]:= ptl=ListPlot[Spoints, GridLines .... Automatic, PlotStyle .... {Hue [ 0.9] , AhsolutePointSize [0.5]} ] ; C. Let us calculate the Lyapunov exponent to illusttate the sensitivity of the map to the initial values. If you define the map and the Log of the absolute value of its derivative, then you get two functions, In [72] := f[L] := # 1!:xp[(1-#)]6i:; fder[_] := Log[Ahs[ (1- #) Exp[(l- #)]]]6i: The values of the Lyapunov exponents follow from In!73]:= points[nO_] := Table [ {, Apply [Plus, fder [ ] [NestList [f [ ],0.1, nO - 1]] I nO]}, {, 2,3.5, l/nO}]; where nO is the number of points. The Lyapunov plot for 300 points follows from applying ListPlot to points, In[74]:= pt2 = ListPlot [points [300] , PlotJoined- > True, PlotStyle.... Thickness [0 .006]]; -1 -1.5 
280 Chapter 5 Discrete Dynamical Systems To compare the Lyapunov plot with the bifurcation diagram, superimpose the two dia- grams In[75]:= pt3 = Show [ptl, pt2]; d. To illusttate the sttucture in chaos compare a series of points taken from white noise and a second series of points taken from the salmon map with J.1. = 2.9. The white noise is determined by taking random values from a normal distribution with mean 1 and standard deviation 0.5. To find the random numbers from a normal distribution, load the package In[76]:= Needs[DStatistics'NormalDistribution'"] The command NormalDistribution is the relevant command: In[77]:= ?NormalDistribution NormalDistribution[mu, sigma] represents the normal (Gaussian) distribution with mean mu and standard deviation sigma. More... A table of 500 white noise random points follows from the table In[7B]:= WNdata = Table [Random [NormalDistribution [1, 0.5]],500]; Five hundred points for the salmon map with J.1. = 2.9 are given by In [79] := chaos = NestList [map[2.9], 0.95,500]; Displaying the two sets of values, you get In[BO]:= Show[ GraphicsArray[ ListPlot[#, PlotStyle.... AbsolutePointSize [2], Ticks.... {{100, 300, 500}, {O, 1, 2}}, Displa.yJ!'u.nction.... :Identity ] Ii: III {WNdata, chaos} ] ; 
5.3 Other Maps 281 It is not obvious that one has sttucture and the other does not. However, you can observe a clear difference between these two sets of values if you plot the return map. The return map is a plot of the pairs, {xi' x i +! }. The return maps for these two sets of points follows from In[81]:= Show[GraphicsArray[ ListPlot[Transpose[ {Drop [#1, -1], Drop [#1, 1] }], PlotRaDge .... All, AxesOrigin .... {O, O}, PlotStyle.... AhsolutePointSize [2], DisplayFunction.... :Identity ] Ii: III {WNdata, chaos} ] ; 1. If\ 0.5 0.511.52 The points for the white noise in the left figure are concenttated around the point {I, 1 } but don't display any other sttucture, while the chaotic values in the right figure lie on the salmon curve. . PROBLEM 2 Sine-Circle Map. Consider the sine-circle map 0n+! = On + .0. +  Sin[21TO n ] where the angular coordinate ° is restricted to the range 0 :$ ° < 1. Periodic conditions at the boundaries 0 and 1 are assumed. a. Let {K = 0,.0. = t} and draw the cobwebs. Show that the orbit repeats after 7 iterations. In fact, the map for {K = 0,.0. = E}, where p and q are integers, al- q ways repeats after q iterations. Consider a second map with .0. = Sqrt[2] and draw its cobwebs. The value of .0. is irrational and the orbit never repeats. The orbit is said to be quasiperiodic. To conclude, set K = .9 and draw the cobwebs for .0. = {0.04, 0.61, 0.65}. 
282 Chapter 5 Discrete Dynamical Systems b. Let.o. = 0.5 and draw the bifurcation diagram as a function of K. c. Set K = 1.2 and plot the winding number w = limn..."" r[(}]-(}o for a range of .0. values and for 00 = 0.3. Solution In [82] := Clear [nGlobal ' * n] a. The user-defined function for the sine-circle map is In [83] : = map [ tL, K..] : = Mod [ (I + Q - K/(27r) Sin[2 71'1]) ,1]&: where Mod is used to impose the periodic boundary condition. Thus, the mapping moves the ttajectory around the circle in steps of size .0.. Consider cobwebs for two cases: {K=O, .o.=ll7} and the irrational value{K=O, .0. = Sqrt [2] }. This problem requires the user-defined procedure cobweb derived in a previous problem: In[84]:= cobweb [f. , xO.,n., opts__.] .- Module [ {teJI\Pl, teJI\P2, points, s ,x}, teJI\Pl [s.] : = Nest [f [I] &:, xO , S ]; teJI\P2 = {teJI\Pl [I ] , teJI\Pl [I ] , teJI\Pl [I ] , templ [I + 1] }&:/@.RaDge[l, n] ; points = {xO, 0, xO, f [xO], teJI\P2 } II Flatten II partition [I, 2]&: ; Plot[{x,f[x]}, {x,O,l}, Epilog- > {Hue[0.9], Line [points] }, opts] The cobweb for the rational value of.o. returns a periodic orbit: In[85]:= cobweb [map [117, 0],1/10, SO] ; 
5.3 Other Maps 283 The case with K=O consists of simply adding the number.o. to the previous angle value. For .0.= 1/7 , you have a periodic orbit where the angle e repeats after 7 cycles. This periodic behavior is verified by looking at the map. Only seven values follow from the union of 400 iterations In[86]:= Take [NestList [map [1/7, 0], 1/10,400] ]// union { 1 1727374757 67 } Out[86]= 10 ' 70 ' 70 ' 70 ' 70 ' 70 ' 70 It is obvious that the orbit repeats after every 7 points. Consider the irrational value.o.= Sqrt [2] . Its cobweb follows from In[87]:= cobweb [map [Sqrt [2], 0],1/10,50] ; 1 0.8 0.6 0.4 0.2 The orbit never repeats for an irrational value .0.. To see the affects of the nonlinear term K on the iterations, let K=O. 9 and draw the cobwebs forO. = {0.04, 0.61, 0.65}. The graphics for all three cobwebs are In[88]:= list = cobweb [map [I, 0.9] ,0.45,50, Ticks -+ {{O, 0.5, 1}, Automatic}, P1otLabe1-+ I, DisplayFunction -+ Identity ]& /@ {0.04, 0.61, 0.65} ; Displaying the results, you find In[89]:= Show[GraphicsArray[ {{list [ [1]]}, list [[ {2, 3}]]}]] ; 
284 Chapter 5 Discrete Dynamical Systems 0' Ld1 o'04 0.6 0.4 0.2 0.5 1 0.61 0.  0.65 0.6 0.4 0.2 0.5 1 In the graph at the top left (0 = 0.04) there is a fixed point at 0.045: In [90] : = Take [NestList [map [0 .04, 0.9 ],0.45,200], -9 ] Out[90]= {0.0450434, 0.0450434, 0.0450434, 0.0450434, 0.0450434, 0.0450434,0.0450434,0.0450434,0.0450434} The bottom right (0 = 0.65) repeats after 3 cycles: In[91] : = Take [NestList [map [0 .65, 0.9 ], 0.45,200], -9 ] IIt1nion Out[91]= {0.414541, 0.649123, 0.99127} The bottom left map (0 = 0.61) doesn't repeat and the ttajectory eventually fills the complete range of e. b. To see how the properties of the orbit change as It varies, consider its bifurcation diagram. Set 0 = 0.65 and let It vary from 0 to 6. To speed up the calculation define the compiled sine-circle procedure In[92]:= orbit = Coq)ile [{K}, Map[{K, I}&:, Drop [ NestList [ Mod [ (# + 0.65 - K/(2 71") Sin[2 71"#] ) , 1]&:,0.1,100],75] ] ; This map evaluates 100 orbit points but keeps only the last 25 values. The bifurcation follows from In[93]:= bifurcation [KO_, KL, n..] .- Platten [Table [orbit [K], {K, KO, Kl, (Kl - KO) In}], 1] 
5.3 Other Maps 285 and its diagram is In[94]:= ListPlot [bifurcation[O, 6,800], PlotStyle- > AbsolutePointSize [1. 1] ]; 1 3 4 5 6 Notice the beginning periodic behavior followed by chaotic behavior mixed with win- dows of nonchaotic behavior. c. Let us calculate the winding number = lim,.->oo r[(}]-(}o . The user-defined function is In[95]:= wind[r.L,L,e_]:= Module [{tem;pl }, tem;pl = NestList [( 1 + Q - K/(2;1\") Sin[2 ;1\"1] )&:, e, 699 ] ; (1/600) ( Last [ tem;pl] - Pirst [tem;pl]) If you let K=l. 2 and 0=0.3 then the winding numbers for different values of.o. are In [96] := ptl = ListPlot[{I,wind[l, 1.2 ,0.3]}&:/@. Range[0.25, 0.75, 0.008], PlotJoined -+ True, PlotStyle -+ {Thickness [0.006], Bue [0.6] }, GridLines -+ Automatic, AspectRatio -+ 1 ] ; 
286 Chapter 5 Discrete Dynamical Systems 0.4 0.5 0.6 The result is a monotonic increasing staircase. The level parts of the curve correspond to frequency-locking plateaus, over which the winding number does not change for a sub- stantial range of .0.. These plateaus are called the Devil's Staircase. . PROBLEM 3 Taylor-Greene-Chirikov Map. Consider the two-dimensional Taylor- Greene-Chirikov map On = 0n-l + i n - 1 + k sin[On_d and in = i n _ 1 + k sin[On_d where ° and i have periodic boundary conditions over the interval from 0 to 211'. a. Fix k=O . 97 and plot the orbit in the plane {O, i} for several different starting points. Randomly select the starting points {eo, io} restricted to the range 0 and 211'. b. Fix k=O. 97 and plot just the ° values that follow from the map. Consider two ex- amples, one with starting points {eo' io} = {3, I} and the other with starting points {0.65,3}. c. Let {K = 0.47, ° = 0.2} and plot the winding number w = limn->oo f"[II]-lio for a range of i values. Solution In [971 := Clear[oGlobal' * 0] a. Define the Taylor-Greene-Chirikov map with the user-defined function, In[98]:= map [k_] [{EL, L}] = {Mod[9+i+k Sin[9]12;1\"], Mod[i + k Sin[9] 12;1\"]}; 
5.3 Other Maps 287 where we have used Mod to return the orbit after the value of 211'. Let k=O. 97 and imple- ment the iterations with NestList: In [99] : = orbit [eO_, iO_] : = NestList[map[0.97 ], {eO, iO}, 150] The values {eo, iO} are the starting points, the value of k is 0.97, and the number of iterations is 150. The plot of the orbit as a function of {e, i} follows from In[lOO]:= orbitG[eO_, iO_, Opts__] := ListPlot [ orbit [eo, iO ] , Opts, Prame -+ True, Axes -+ None, PrameLabel-+ {ne n , ni n }, PlotStyle -+ {Bue [Random [] ] , PointSize [0.009 ] } , DisplayPunction -+ Identity where {eO, iO} are the starting values. You next want to plot {e, i} when the starting points are randomly selected in the interval from 0 to 211'. Picking 60 random starting points, the {e, i} graph follows (it takes several seconds), In[lOl]:= Show[ orbitG[Random[Real, {O, 2;1\"}], Random[Real, {O, 2 ;I\"}] ] &/(1. Range [60 ] , DisplayPunction -+ $DisplayPunction, GridLines -+ Automatic, AspectRatio -+ Automatic] ; The closed loops correspond to stable regions with fixed periodic points at their centers. The hazy regions are unstable and chaotic. 
288 Chapter 5 Discrete Dynamical Systems b. To plot the orbit in the O-n plane you must take just the 0 values from the orbit. The user-defined function to take the 0 values is In[102];= Cha[{aO_, iO_}] := IIap[First, orbit [aO, iO]] Consider the two different starting points {OO, iO} ={3,l} and {0.65, 3}. The graphics for the last 40 orbit points are In[103];= ptl = ListPlot[Take[Che[#], -40] , PlotJoined -+ True, AxesLabel -+ { n, a }, Displa.yPunction -+ Identity ]& /@ {{ 3, 0.1}, {0.65, 3}} ; Displaying the results, it follows In[104];= Show[GraphicsArraY[{Ptl}]]; e e 1M 10 20 30 40 n The graph on the left is for the starting point {OO, iO} = {3, 0.1} and the graph on the right is for {0.65, 3}. Notice the variety of behaviors that follow from the map. c. Let us graph the winding number. The user-defined winding function is defined as the w = lim,.....oo r[(}]-(}o , where the restriction of the map to the {0,21l'} range has been dropped. The user-defined function follows from In[105] ;= wind[ L, a_, L] : = Module [{mapl, orbit2, wind3, aa, pb}, mapl [{aa_, pb_}] : = {aa+pb+K Sin[aa],pb+K Sin[aa]}; orbit2 = NestList [mapl, {a, i}, 400 ] ; wind3 = Map [First, orbit2] ; (1/400 ) ( Last [ wind3] - First [wind3] ) If you let K=O. 4. 7 and 0=0.2 then a plot for different values of i follows from In[106];= ListPlot[{#,wind[0.45 ,0.2,#]}&/@ Range[0.15, 0.24, 0.005], PlotJoined -+ True, PlotStyle -+ {Thickness [0.005] , Bue[0.6]}, PlotLabel-+ {nK = 0.47, a = 0.2 n }, AxesLabel -+ {i, None}]; 
5.3 Other Maps 289 {K=0.47,9=0.2} 0.66 0.64 0.22 i 0.24 which is similar to the Devil's Staircase in the circle map. . PROBLEM 4 Henon Map. Consider the two-dimensional Henon map x n +! = 1 - a  + Y n and Y n +! = b xn' a. Plot the orbit in the{x,y} plane for {b=O.3, a=1.4} and with starting points {x, y}= {O, 0 . 1}. Enlarge a portion orbit to show more details. b. ConsITuct a bifurcation diagram for the Henon map by plotting the x-values of the orbit (after allowing ttansients to die away) as a function of the conttol parameter a and forb=O .3. Choose the starting point at {x,y}= {O.3, O.6}. Solution In[107]:= Clear [nGlobal' * n] a. Define the Henon map In [108] : = map [a_, b_] [{x-, y_}] : = { 1 - a x 2 + y , b x } The orbit follows from applying NestList to the map. Let us plot the orbit in the {x, y} planefor {b=O. 3, a=1. 4} with starting points {x, y }={O, 0 .1}. The plot for 20,000 points is In[109]:= ptl= ListPlot [ NestList[map[1.4, 0.3], {O, O.l}, 20000 ] , PlotStyle -+ AbsolutePointSize [2] , GridLines -+ Automatic] ; 
290 Chapter 5 Discrete Dynamical Systems -1 As smaller and smaller portions are enlarged the orbit shows more and more detail. Magnifying a portion of the orbit, it follows In[110]:= Show[ptl, PlotRange -+ {{0.3, 0.f.7}, {0.2, 0.217}}, GridLines -+ Automatic]; Further enlargement produces more sttucture. b. Let us consttuct a bifurcation diagram for the x-component of the Henon map. Fix b=O.3 and choose the starting point at {x,y}= {O. 3, O. 6}. The user-defined function that takes just the x-values of the map is In[lll]:= Hx[a_] := Map [First, Drop[NestList[ map [a, 0.3], {0.3, 0.6}, 200], 150] ] The x-bifurcation diagram follows from In [112] : = bifurcation [aO_, al_, IL] : = Flatten[Table[Hx[a], {a,aO,al, (al-aO)/n}], 1] If you set n=300 and let a vary from 1.05 to 1.1, then the bifurcation points are In[113]:= pts = bifurcation [1.05 , 1.1, 300] ; 
5.4 Fractals 291 Displaying the results, you get In[114]:= ListPlot[pts, Plot Style -+ AbsolutePointSize [1.4] , AspectRatio -+ 1, Ticks -+ {{}, Automatic} ] ; 1 - 0.5 - Notice how some of the atttactors abruptly appear and then disappear. This type of event is called a crisis. . 5.4 . FRACTALS 5.4.1 . Overview Chaotic systems almost inevitably give rise to fractals. Fractal analysis is often useful in describing the geometric sttucture of a chaotic system. They exhibit self-similarity and are independent of scale-if you concenttate on one portion of the fractal, the resulting pattern is similar to the original. Nature abounds with self-similarity, including coastlines, clouds, lightning bolts, and snowflakes. In 1975 Benoit Mandelbrot coined the term fractal to describe such irregular shapes. The essential feature of a fractal is the existence of a similar sttucture at all length scales. That is, a fractal object has the property that a small part resembles a larger part, which in turn resembles the whole object. Fractal images can be obtained by iterating a function applied over and over to itself. We consider just two examples of maps that have self-similar sttucture, the Mandelbrot and Julia sets. The Mandelbrot set is consttucted from the map zn+! = z + c, where C is a point in the complex plane and the iterations start at Zo = O. Each complex number c is in the Mandelbrot set if its iteration remains finite. The Julia set is also consttucted from the map zn+! = z + c, where c is a point in the complex plane. For the Julia set the c is fixed 
292 Chapter 5 Discrete Dynamical Systems but the starting value Zo is changed. The value of Zo is in the Julia set if its iteration remains finite. . PROBLEM 1 Mandelbrot Set. Consider the map Zn+l = Z + c, where c is a point in the complex plane and the starting point is Zo = O. Each point c that remains finite is in the Mandelbrot set. a. Find the algorithm that for each c it checks if the orbit escapes. It is impossible to apply the Mandelbrot process because you cannot iterate the map an infinite number of times to see if the point goes to infinity. However, it can be shown that if the distance of the point from the origin becomes greater than two, it will grow without limit. As a result of this, if the absolute value of zn reaches the value of two before the first 70 iterations, then we can stop the process and this value of c is not in the set. Show that the value of c = fa belongs to the set but c = 1 does not. b. Assign a color according to the number of iterations performed on each value of c. Plot the results using Plot3D and DensityPlot. To observe the self-similar SITucture magnify a portion of the set near the boundary. Solution In[115]:= Clear[nGlobal' * n] a. To find whether c is in the Mandelbrot set, you need only to check whether any point of the iterations has absolute value larger than 2. Once this occurs, you are guaranteed that the orbit escapes to infinity and the corresponding c does not belong to the Mandelbrot set. The compiled algorithm for first 70 iterations of the orbit are In[116]:= MandO = Coq)ile [{ {c, _Coq)lex}}, PixedPointList [#-2 + cs:, 0, 69, SameTest- > (Abs [#2] > 2 .S:)]] ; This procedure uses the command FixedPointList to generate the iterations of the map. FixedpointList is like NestList but has the additional option of same test. The FixedpointList function iterates the map 70 times or until the SameTest criteria is satisfied. The value of c belongs to the set if all 70 iterates are returned. If this is the case then the absolute value of the final iterate will be less than 2. If the points are diverging the same test will stop the list before all 70 iterations are reached. The value of c=1/10 belongs to the set since after 70 iterations its value is less than 2. The last iterate has the value In[117]:= Take[MandO[1/10],-1]//Chop Out[117]= {O.112702} The value of c=l does not belong to the set since 
5.4 Fractals 293 In [118] : = MandO [ 1 ] / /Chop Out[118]= {a, 1., 2., 5., 26.} After just three iterations the value of the map is greater than 2. b. We can assign a color to the map according to how many iterations are needed for the absolute value of the map to become greater than 2. A small number of iterations means that the point is rapidly going to infinity. On the other hand, if c belongs to the Mandelbrot set, the distance from the origin will never become greater than two, no matter how many iterations are done. The number of iterations follow from In [119] := Mandelbrot [c_] : = Lenr;rt:h [MandO [c] ] We now use Plot3D to display this result. Let c=x+ I y, where x is in the range { - 2, 0.5} and y ranges from {-I.!, 1.1}. The Mandelbrot graph is In [120] : = Plot3D [Mandelbrot [x + J: y] , {x, -2., 0.5}, {y, -1.1, 1.1}, AspectRatio- > Automatic, Colorl'uDction- > Rue, PlotRange -+ All, Plot Points -+ 100] ; The points that have 70 iterations are in the set. Another way to make a visual display follows from DensityPlot: In[121]:= DensityPlot [Mandelbrot [x + J:y], {x, -2, 0.5} , {y, -1,1}, Mesh- > False, AspectRatio- > Automatic, Frame -+ True, Colorl'uDction- > Rue, Plot Points -+ 100 ] ; 
294 Chapter 5 Discrete Dynamical Systems The center of the image are all those complex numbers whose first 70 iterations lie within a circle of radius two, centered at O. To observe the self-similar sITucture, magnify a portion of the set near the boundary: In[122]:= DensityPlot [Mandelbrot [x + J:y], {x, -1.45, -1.25}, {y, -0.12, 0.12} , Mesh- > False, AspectRatio- > Automatic, Frame -+ True, Colorl'unction- > Rue, Plotpoints -+ 100] ; Notice how the pattern is repeated. . PROBLEM 2 Julia Set. The Mandelbrot set is the domain of convergence of the series built up from the mapZn+! = Z+C, where c is a point in the complex plane and the iterations start at zo= O. If the iteration remains finite, then c is in the Mandelbrot set. When making a Julia set we fix c but let the value of Zo change. If the points of the map for fixed c and starting value Zo remain finite, then Zo is in the Julia set. 
5.4 Fractals 295 a. Find the algorithm that for each Zo checks if the orbit escapes within the first 50 iterations. Let c = -1 and show that Zo = 0.1 is in the set but Zo = 1.9 is not. b. Set c = -1 and use Plot 3D and DensityPlot to display the set. Solution In[123]:= Clear [wGlobal' * W] a. For a given c the following algorithm checks whether a point zO is in the complex plane and the Julia set. In[124] : = JUliao = compile [{ {zO, .complex}}, l'ixedpointList [#-2 + c&:, zO, 50, SameTest- > (Abs [#2] > 2 .&:)]] ; If c=-l, then zO=1/10 belongs to the set In[125]:= c=-l; JUliao[O.l]//Chop Out[125]= {0.1, -0.99, -0.0199, -0.999604, -0.000791863, -0.999999, -1.25409 x10- 6 , -1.,0, -1., 0, -1., 0, -1., 0, -1" 0, -1., 0, -1., 0, -1., 0, -1" 0, -1" 0, -1" 0, -1" 0, -1.,0, -1" 0, -1.,0, -1., 0, -1., 0, -1. , 0, -1. , 0, -1. , 0, -1. , 0, -1. , o} but zO=l. 9 does not belong to the set since Abs [x] is greater than two after the first iteration. In[126]:= JUliao[1.9 ]//Chop Out[126]= {1.9} b. To visualize the set, define the procedure In [127] : = Julia = Compile [{ {zO, .complex} } , Length [l'ixedPointList [#-2 + c&:, zO, 50, SameTest- > (Abs [#2] > 2 .&:)]]]; If c=-l then the set is visualized with Plot3D In[128]:= c = -1; Plot3D [Julia [x + J: y] , {x, -2., 2}, {y, -1,1}, AspectRatio- > Automatic, Colorl'uDction- > Hue , Plotpoints -+ 100, PlotRange -+ All]; 
296 Chapter 5 Discrete Dynamical Systems Note that the Julia set need not be connected while the Mandelbrot set is. The DensityPlot follows from In[129]:= DensityPlot [J'ulia[x + :Iy], {x, -2, 2}, {y, -1,1}, Mesh- > I'alse, AspectRatio- > Automatic, I'rame -+ True, Plotpoints -+ 100, Colorl'unction- > Rue ] ; . 5.5 . EXERCISES The solutions to many of these exercises can be found on our web site. 5.1 Gaussian Map Consider the Gaussian map x n +! = Exp[ -b ] + c. This map is characterized by two control parameters, labeled b and c. (a) Draw the cobwebs for b = 7.5, c = 0 and c = -0.5. (b) Make a bifurcation diagram for b = 7/2 as a function of c. 
5.5 Exercises 297 (c) Plot the Lyapunov exponent n-! ,\ = lim  "In I dr[x] I n-+oo n L...J dx i=O and the entropy. 5.2 Return Maps for the Henon Map Consider the two-dimensional map x n +! = 1 - a  + Y n and Y n +! = b xn' lllustrate the structure in the chaos by making return maps. The return maps are plots of the pairs, (x i _ n , x i + n ). Do this for a = 1.4, b = 0.3, starting point {O, 0.1}, and n = 1,2,3 and 4. 5.3 Cubic Maps Explore the cobwebs, bifurcation diagrams, Lyapunov exponents, and entropies for the following cubic maps: 27 Map 1: x n +! = 16 r(1 - x n ) (0 ::5 r ::5 4) r Map 2: x n +! = ..{j x n (l - ) (0::5 r::5 4.5) Map 3: x n +! = x/I - 0 + p) (0 ::5 P ::5 4) 5.4 Two-Dimensional Map Explore the orbits, bifurcation diagram, Lyapunov exponent, and entropy for the following two- dimensional controlled Logistic map: x n +! = r x n (l - x n ) - b x n + Y n and Y n +! = b xn' 5.5 Tent Map Explore the cobwebs, bifurcation diagram, Lyapunov exponent, and entropy for the following Tent map: X n +! = 21 x n for X <! - 2 and X n +! = 21(1 - x n ) for x >  where 0 ::5 t ::5 1. 
CHAPTER 6 298 Lagrangians and Hamiltonians 6.1 . INTRODUCTION Classical mechanics serves as the starting point for several branches of physics. This chap- ter illusttates the application of Mathematica to problems in advanced mechanics. We con- sider problems solved with Lagrangians, Hamiltonians, and Hamilton-Jacobi equations. Our approach to mechanics closely parallels the discussions found in the typical texts on classical mechanics. It is very convenient to express Newton's Laws of motion in terms of a scalar quantity called the Lagrangian. The Lagrangian for a system described by n generalized coordinates q i and q; is L[ q', q, t], where q; = . The generalized coordinates can be distances, angles, or other quantities relating to the description of the motion. If the forces are conservative, then they can be expressed in terms of a potential V. The Lagrangian becomes L = T - V, where T is the kinetic energy and V is the potential. The equations of motion follow from Lagrange's equations:  ( BL ) _ ( BL ) _ 0 dt Bqj Bqj- To describe systems with consttaints the Lagrangian method can be generalized by adding Lagrange multipliers to handle the consttaints. Another formulation of Newton's Laws follows from the Hamiltonian. The Hamiltonian is defined in terms of the Lagrangian L[q', q, t] by  dqi [ ' ] H= LJPidi-Lq,q,t 1=1 where Pi are the generalized momentum and are related to the generalized coordinates by Pi = dLdt] . Eliminate the q; variables in H and then express H in terms of the canonical coordinates {q, p}, i.e., H[q, p, t]. The equations of motion follow from , BH[q, p, t] Pi = B ' qi , BH[q, p, t] qi = BPi The Hamilton-Jacobi technique seeks a ttansformation to a new set of canonical vari- ables {q, p} -+ {Q, P}, where the new Hamiltonian is zero. These new canonical variables {Q, P} will be constants, and the problem is reduced to solving algebraic equations. 
6.2 Lagrangian Problems without Lagrange Multipliers 299 This chapter is divided into four problem sections: 6.2, Lagrangian problems without Lagrange multipliers, 6.3, Lagrangian problems with Lagrange multipliers, 6.4, Hamilto- nian problems, and 6.5, Hamilton-Jacobi problems. Exercises are included in section 6.6. Before starting the problems you might find it convenient to turn off the spell checker: In!l]:= Off [General :: spell]; Off [General: : spelll]; 6.2 . LAGRANGIAN PROBLEMS WITHOUT LAGRANGE MULTIPLIERS 6.2.1 . Overview A system of n particles is described by at most 3n coordinates {xl' ..., x 3n }. Not all these coordinates are independent; consttaints may restrict them. These consttaints are easiest to handle when they are of the form f[x l , ...,x 3n , t] = 0, in which case, they are called holonomic. Consttaints not expressible in this fashion are called nonholonomic. If there are k holonomic consttaints, then k of the 3n coordinates can be eliminated, leaving 3n - k independent variables {ql' ..., q3n-k} known as the generalized coordinates for the motion. The ttansformation from the 3n coordinates Xi to the 3n - k generalized coordinates qi is represented by the ttansformation equations xi = xJql' ..., q3n-k' t]. The generalized coordinates can be distances, angles, or other quantities relating to the description of the motion. The number of generalized coordinates is the number of independent degrees of freedom. In terms of generalized coordinates qi' the equations of motion follow from the 3n - k equations  ( 8T ) _ ( 8T ) =Q. dt 8qj' 8qj J where T is the kinetic energy and Q j are the generalized forces. If Fj is the j-component of the force, then the generalized force Q j is defined by 3n a. Qj = L: 1'; xJql...., q3n-k' t] i=1 8qj If some of the forces are conservative, then they can be expressed in terms of a potential  --"" V, where F = - VV. Expressing the conservative forces by a potential V and nonconser- vative forces by the generalized forces Qi' the equations of motion follow from Lagrange's equations: d ( 8L ) ( 8L ) dt 8qj - 8qj = Qj The Lagrangian L = T - V describes the conservative forces. 
300 Chapter 6 Lagrangians and Hamiltonians All the problems in this section are for conservative forces so Lagrange's equation re- duce to the form  (  ) _ ( 8L ) _ 0 dt 8q/ 8qj- 6.2.2 . Initialization for Lagrangian Problems The Mathematica command to calculate these equation is EulerEquations, found in the add-on package Calculus 'VariationalMethods'. Before starting these prob- lems load the add-on package In[2J:= Needs[RCalculus'VariationalMethods'R] The EulerEquations command is In[3J:= ?EulerEquations EulerEquations[f, U[X], x] or EulerEquations[f, U[X,y,. ..], {x,y, ...}] re- turns the Euler-(Lagrange) equation obeyed by u[x] for the functional de- fined by f. EulerEquations[f, {u[x,y,.. .],v[x,y, ...], ...}, {x,y, ...}] re- turns a list of Euler equations obeyed by the functions {u[x,y, ...], v[x,y, ...], .. .}. More... For example, consider the Lagrangian, In[4J:= L = m/2 x' [tr2 - k/2 x[t]-2 1 2 1 , 2 Out[4J= -2 kx[t] + 2 mx [t] The equations of motion follow from In[SJ:= EulerEations[L,x[t],t]//ExpandAll Out[SJ= -kx[t] -mx" [t] == 0 A command to compute the first integrals is also found in the add-on package. First inte- grals follows from the command FirstIntegrals: In[6J:= ?FirstXntegrals Firstlntegrals[f, U[X], x] or Firstlntegrals[f, {u[x],v[x], ...}, x] returns a list of first integrals corresponding to those coordinates u, v, ... of the integrand f that are ignorable; when f is independent of x and depends on the coordinates and their first derivatives only, the first integral cor- responding to x is also returned. More... You get the following first integral (conserved energy) for our example, In[7J:= FirstXntegrals[L,x[t],t]//ExpandAll Out [7J= {FirStIntegral [t] -7  kx[t] 2 +  mx' [t] 2} 
6.2 Lagrangian Problems without Lagrange Multipliers 301 . PROBLEM 1 Particle Sliding on a Movable Incline. Consider a particle of mass m sliding on a smooth inclined plane of mass II, that is itself free to slide on a smooth hori- zontal surface. The length of the incline is LO, the height is h, and the angle of the incline is e. h xl a. Write the Lagrangian and derive the equations of motion for the particle and incline. b. Find two first integrals for the problem. c. Solve the equations of motion and calculate how long it takes the particle to reach the bottom of the incline. Solution In[B]:= Clear[nGlobal' * n] a. Consider a particle of mass m sliding on a smooth inclined plane with mass II that slides on a smooth horizontal surface. The length of the incline is LO, the height is h, and the angle of the incline is e. Let xl be the coordinate position to the bottom edge of the incline. Let {x,y} be the Cartesian coordinates for the sliding particle, where x is the horizontal coordinate and y is the vertical coordinate. The kinetic energy and potential energy are In[9]:= T= M Xl'[t]2+m(x'[t]2+y'[t]2); V = mgy[t]; The problem simplifies if we let one of the coordinates be the distance along the incline. Call this coordinate 8 [t] . The particle's coordinates {x, y} are related to 8 [t] by In[lO]:= change = {x -+ «xl [I] + (LO - B [I]) COB [e]) &:) , Y -+ « (LO - B [I]) Sin [e]) &:) }; where 8=0 is at the top of the incline and 8=LO is at the bottom. Let the generalized coordinates be xl and 8. In terms of xl and 8, the Lagrangian is In [11] := L = T - VI . change I ISimplify 
302 Chapter 6 Lagrangians and Hamiltonians Out[ll]=  (-2gm(LO-s[t]) Sin[e] +Mx1'[t]2+ 2 m (S'[t]2 -2 cos[e] s'[t] x1'[t] +x1'[t]2)) The equations of motion follow from EulerEquations: In [12] : = eq:l = EulerEq:uations [L, {xl [t] , s [t] }, t] Out[12]= {mCos[e] s"[t] - (m+M) x1"[t] == 0, m (g Sin[e] - s" [t] + Cos [e] xl" [t]) == O} that reduce to In[ 13] : = eq:Motion = Solve [eq:l, {xl" [t], s" [t]}] / /I'latten { 1 " gm Cos [e] Sin [e] Out[13]= x [t] -7 - , -m - M + mCos [e] 2 " g (m+M) Sin[e] } s [t]-7 -m - M +mCos [e] 2 b. One first integral follows from the conserved horizontal momentum and the other from the conservation of energy. Notice the total horizontal momentum, In[14]:= xmomentum=Mxl'[t] +mx'[t]/.change// Simplify Out[14]= -mCos[e] s'[t] + (m+M) x1'[t] is a constant as is verified by taking its derivative and using the equations of motion In[15]:= D[xmomentum,t] /.etion//Simplify Out[15]= 0 Likewise, the conserved energy is a second first integral, In[16]:= energy = T +V/ . change/ /Simplify 1 Out[16]= - (2gm(LO-s[t]) Sin[e] +Mx1'[t]2+ 2 m (S'[t]2 -2 Cos[e] s'[t] x1'[t] +x1'[t]2)) Again, verifying it is a constant by taking its derivative and using the equations of mo- tion, you get In[17]:= D[energy,t]/.change/.etion// Simplify Out[17]= 0 In a less physical manner, these same two first integrals also follow from the add-on command FirstIntegrals: In[18] : = l'irstIntegrals [L, {xl [t], s [tD, t] 
6.2 Lagrangian Problems without Lagrange Multipliers 303 Out[18]= {FirstIntegral [xl] -> mCos[e] s'[t] - (m+M) xl'[t], FirstIntegral [t] -> l. . 2" (2gLOmSJ.n[e] -2gms[t] SJ.n[e]+ m s' [t] 2 - 2 m Cos [e] s' [t] xl' [t] + mxl'[t]2 +MXl'[t]2)} c. The solutions for the particle's and incline's motion are trivial and follows from ap- plying DSolve to eqMotion. If we start the motion at the top (s[O] = 0) of the incline with zero speed, it follows In[19] := Sol = DSol ve [ { ( eq'Motion/ . Rule -+ Equal), s[O] == 0, s' [0] == 0, xl[O] == 0, xl' [0] == O} / /I!'latten, {xl [t], s [t] }, t ] / / Siq>lify / /I!'latten { gmt2 Sin[2e] xl [t] -> - , -2 (m+ 2M) + 2m Cos[2 e] g (m+M) t 2 Sin[e] } s[t]->- -m - 2 M + m Cos [2 e] Out[19]= The particle reaches the bottom after a (squared) time of In [20] := « (s [t] / .Sol) == LO / /Siq>lify //Solve[#/.t-2 -+x,x]& ) /.x -+ t-2 / /I!'latten / / I'UllSiq>lify) { t 2 -> 2 LO (M Csc [e] + m sin [e]) } g (m+M) Out[20]= . PROBLEM 2 Bead Sliding on a Rotating Wire. The upper end of a sttaight frictionless wire is fixed at point A and the wire makes an angle 1/1 with the downward vertical drawn from A. The wire rotates around the vertical axis with constant angular velocity w. A bead of mass m is consttained to move on the wire. a. Solve for the bead's motion assuming the initial conditions are r [0] = rO and r' [0] = vO. b. Let rO be zero at t=O and find the time it takes for the bead to move a distance Len. Evaluate the time for the special case 1/1=0. c. Let vO=O and rO=O at t=O and graph the motion of the bead as a function of time. Remarks and Outline Use spherical coordinates {r, (), <p} to express the position of the bead. The variable r is the distance along the wire, () is the constant angle the wire makes 
304 Chapter 6 Lagrangians and Hamiltonians u A with the vertical, and <P = wt. Instead of (), use the angle defined relative to the downward vertical /fl. There is only one generalized coordinate, r [t] . The equation for r [t] follows from the add-on command EulerEquations. The equation of motion is solved with DSol ve. Solution In [21] := Clear[RGlobal' * R] a. Assume a spherical coordinate system with the origin at the vertex of rotation A. Let r be the distance to the bead from point A. Let () be the angular variable, where () is the angle the wire makes with respect to the downward vertical. The Cartesian coordinates {x, y, z} for the bead can be expressed in terms of {r, (), <p}, where the <p coordinate is wt. In [22] := x2rRule = {x, y, z} -+ { (r [I] sin [9] Cos [61 #]) &, (r[#] Sin[9] Sin [61 #]) &, (r[#] COS[9])&}//'l'hread; The coordinates have been expressed in their pure form to enable substitutions in dif- ferential expressions. Instead of () use the angle defined relative to the downward vertical /fI: In [23] := l/fRule = 9-+ (7f- I/f) ; Since /fI is assumed to be fixed the only independent variable is r [t] . The kinetic and potential energies and the Lagrangian are In [24] := T =  m (x' [t]2 +y' [t]2 + z' [t]2); V=mgz[t]; L = T - v / .x2rRule / .l/fRule / / Simplify 
6.2 Lagrangian Problems without Lagrange Multipliers 305 1 Out[24]= 2 m (2 g Cos [1/1] r[t] + w 2 r[t]2 Sin [1/1] 2 + r' [t]2) The equation for r [t] follows from the command EulerEquations: In [25] := eql = EulerEquations [L, r[t], t] Out[25]= m (g Cos[l/I] +w 2 r[t] Sin [1/1] 2 -r"[t]) == a Solve eql for r' , [t]: In [26] := rSol = ( Solve [eql, r" [t]] [ [1, 1]] I I ExpandAll ) I I. Rule -+ Equal Out[26]= r"[t] ==gCos[l/I] +w 2 r[t] Sin [1/1] 2 Assume the initial conditions are r [0] =0 and r' [0] =vO and apply DSolve to rSol. Solving for r [t], you get: In [27] := eq2 = DSolve[{rSol,r[O] ==O,r'[O] ==vO}, r[t],t] [[1,1]] IISiq>1ify II PowerExpand I I ExpandAll; This expression reduces to In [28] := rRule = MapAt[ Collect[#, {Exp[-x_] }] &, eq2, 2] g Cot [1/1] Csc[l/I] Out [28]= r[t] -7 w 2 + twSin[I/rJ [ gcot[l/I] Csc[l/I] e 2 w2 + vaCsc[I/I]3 _ va Cos[21/1] CSC[I/I]3 ) + 4w 4w e.twSin[l/r] [ g Cot [1/1] Csc[l/I] 2 w 2 va CSC [1/1] 3 + va Cos [21/1] CSC [1/1] 3 ) 4w 4w b. The time it takes for the bead to go a distance Len follows from setting Len=r [t] and solving for t, 
306 Chapter 6 Lagrangians and Hamiltonians In [29] := tRule = ( Solve [Len == r [t] I .rRule , t , InverseFunctions -+ True] [ [2]] I I Simplify l/PowerExpand Out[29]= {t-7(CSC[I/I] ( - Log [2] - Log [g Cos [1/1] + vO w Sin [1/1] ] + Log [ 2 g Cos [1/1] + W (2LenW+Y2y'(2V0 2 +Len 2 w 2 +4 gLen Cos [1/1] - Len 2 w 2 Cos [ 21/1]) CSC[I/I]) Sin[I/I]2]))} We want the time to be positive so we kept the positive solution. To find the time for the special case of ift=O, apply Series to tRule: In[30]:= Series [t/.tRule, {1/1, 0, O} ] IINormal II Siq>lify -vO + ,/ 2 gLen + v0 2 Out[30]= g This is the expected free-fall solution. c. Plot the three-dimensional motion for the bead with the parameters: In [31] : = values = {1/1-+ 71"/13, If -+ 1, 6/-+ 2, vO -+ O}; The position of the bead at time t is In [32] := position = {x[t], y[t], z [t]}1 I .x2rRulel I .rRule/. r/lRulel I. values; Plot this in three dimensions with the output suppressed: In[33]:= pi = parametricPlot3D [position II Evaluate, {t, 0, 6}, Boxed -+ True, Axes -+ False, BoxRatios -+ {1, 1, 1}, Displayl!'Unction -+ Identity] ; To embellish this plot, we plot the positions at discrete time points using 
6.2 Lagrangian Problems without Lagrange Multipliers 307 In[34]:= discretepoints = Table [position, {t, 0, 6, O.S}]; discreteGraphics = Graphics3D[{pointSize[0.03], point/8discretepoints}]; Overlaying discreteGraphics with the original plot pi results in In[35]:= Show[discreteGraphics,pl, BoxRatios -+ {1,1,1}]; . PROBLEM 3 Bead on a Rotating Hoop. A bead of mass m is consttained to move on a hoop of radius r. The hoop rotates with constant angular velocity w around a vertical axis that coincides with the hoop's diameter. The only external force is gravity. a. Consttuct the Lagrangian and derive the equations of motion. Also find the energy and verify that it is conserved. b. Define a potential for the system and find the equilibrium points. Show the charac- teristics of the potential change at w = wc' where w =  and g is its acceleration constant. Graph the potential for the two types of potentials. c. Make a phase portrait for the motion. d. Numerically solve for /fI [t] and /fI' [t] and plot the data, where /fI is the azimuthal angle measured relative to the downward vertical. e. Animate the numerical results. 
308 Chapter 6 Lagrangians and Hamiltonians 0) 9+'V=1t Remarks and Outline Choose spherical coordinates {r, e, rp} with the origin at the cen- ter of the hoop. Let r be the radius of the hoop and rp be given by w t. Change e to the downward directed angle if/ = 7r - e. The bead's motion is described by one inde- pendent variable if/ [t] and the equations of motion follow from the add-on command EulerEquations. The expression for the conserved energy follows from the expres- sion for the Hamiltonian. An effective potential follows from the energy expression. Solution In[36]:= Clear[nGlobal' * n] a. Let the origin of the coordinates be at the center of the hoop and r be the radius of the hoop. The coordinates of the bead are given by In[3?]:= x2rRule = {x,y, z} -+ {(r Sin[B[#]] COS[Id#])&:, (r Sin[B[#]] Sin[Id#])&:, (r COS[B[#]])&:}//Thread; It is more convenient to measure the azimuthal angle e relative to the downward vertical e=7r-if/: In[38]:= r/lRule = {B-+ (7f- I/r[#]&:)}; The kinetic and potential energies follow from 
6.2 Lagrangian Problems without Lagrange Multipliers 309 In[39J:= T =  m (X'[t]2 +y' [t]2 + z' [t]2) II .x2rRule I. l/fRulellSiq>lify Out[39J= mr2 (w 2 Sin[i/J[t]]2+Ij/[t]2) 2 In[40J := V = mg z [t] I I .x2rRule I .l/fRulel I Simplify Out[40J= -gmr Cos[i/J[t]] and the Lagrangian is In[41J:= L= (T-V) Out[41J= gmr Cos [i/J[t]] +  mr 2 (w 2 sin [i/J[t]] 2 + i/J' [t] 2) 2 The equation of motion follows from applying EulerEquatioDs to L In[42J:= eql=EulerEquations[L, I/r[t],t] Out[42J= mr ((-g+rw 2 Cos[i/J[t]]) Sin[i/J[t]]- ri/J"[t]) == 0 and solving for ifl" [t]: In[43J:= l/rSol = (Solve [eql, I/r" [t]] 111!'1atten) I. {g -+ 61C 2 r} II ExpandAll Out[43J= {i/J" [t]  _wc 2 Sin [i/J [t] ] + w 2 Cos [i/J [t]] sin [i/J [t] ] } We have set we?- = [. r The energy of the system follows from H = ifl' : - L: In[44J:= energy = (I/f[t] D[L,I/f[t]] -L)/.{g-+61c 2 r}/I Simplify 1 2 Out[44J= -2 mr (2 wc 2 Cos [i/J[t]] + w 2 Sin [i/J[t] ]2 _1/1 [t]2) To verify that energy is conserved we take the derivative of energy and use /fISol to show its time derivative is zero: In[ 45J : = D[energy, t] I .l/rSol/. {g -+ 61c A 2 r} I I Simplify 
310 Chapter 6 Lagrangians and Hamiltonians Out[45J= 0 This same result is retumed by the command Firstintegrals In[46J:= FirstIntegrals[L, I/r[t],t]/.{g-+ldc 2 r}// Siq>lify Out[46J= {FirstIntegral[t] -7-mr2 (2 wc 2 Cos [i/J[t]] + w 2 Sin [i/J[t]] 2 _1/1 [t] 2) } b. The terms independent of velocity in the expression for the energy give the effective potential, Veff: In [47 J : = Veff = energy / / . {I/I [t] -+ O} / /ExpandAll Out[47J= _mr 2 wc 2 Cos[i/J[t]] -mr2w2Sin[i/J[t]]2 2 The equilibrium positions are determined by setting d1f to zero. The derivative of the potential is In[48J:= dVeff = D[Veff, I/r[t]] Out[48J= mr 2 wc 2 Sin[i/J[t]]- mr 2 w 2 Cos [i/J[t]] Sin [i/J [t] ] Setting the derivative to zero and solving for /fI, it follows In[49J:= sol = Solve [dVeff ==O,I/r[t], InverseFunctions -+ True] Out[49J= {{i/J[t] -70}, {i/J[t] -7-ArcCos [ Ww2 ]}, { i/J [t] -7 ArcCos [ WW2 ]} } 2 If  is less than one, then there are three equilibrium positions: one at the bottom and w two along the sides. There is another equilibrium point at the top of the hoop /fI = 7r so the total number of equilibrium positions is four: In [50J : = eqRule = Join [{{I/r[t] -+:If}}, sol] Out[50J= {{i/J[t] -77f}, {i/J[t] -70}, { i/J [t] -7 - ArcCos [ Ww2 ]} , {i/J [t] -7 ArcCos [ WW2 ]}} Substitute eqRule into dVeff to verify they are solutions: 
6.2 Lagrangian Problems without Lagrange Multipliers 311 In[51J:= dVeff == O//.eqRule Out[51J= {True,True,True,True} Let us plot the potential as a function of 1ft and w. Without the loss of generality, set In [52J : = values1 = {r -+ 1, lAIC -+ 1, m -+ 1}; Let 1ft range from -7r to 7r and W range from we to 3w e . The plot of the potential is In[53J:= Plot3D[Veff/.values1//Evaluate, {I/r[t], -71:, 7I:}, {IAI, 1, 3}, ColorFunction -+ Hue , Ticks -+ {7I: Range [-1, 1, 1/2] , Automatic, Automatic} ] ; JTl The potential has an unstable equilibrium position at the top of the hoop (1ft = =F7r) and another equilibrium position at the bottom of the hoop (1ft = 0). The other two equilibrium positions are stable but exist only if w 2 is greater than w. Notice a bifurcation point occurs at we = 1. To plot the potential diagram for the two characteristic kinds of potentials we consider two values for w: W = 0.2 (w < we' slow spin) and W = 2 (w > We' fast spin). The potential plots for these two cases are In[54J:= Plot[ (Veff/ / .values1/ .IAI-+ #) & /@ {2, 0 .2} / / Evaluate, {I/r[t], -71:, 7I:}, Ticks -+ {{ -71: , 0, 7I:}, Automatic}, Epilog -+ { Hue[O.6],AbsolutePointSize[6], Map [Point, { I/r[t] , Veff}/ .eqRule / .valuesl/. IAI-+ 2] } ] ; 
312 Chapter 6 Lagrangians and Hamiltonians The double-well potential corresponds to the fast spin and the single-well potential is for slow spin. The dots mark the equilibrium points. For the fast spin case the equilibrium points at the top and bottom are unstable positions. The two stable positions are to the right and left of the bottom where the gravitational and centrifugal forces balance. For slow spin the stable equilibrium position is at the bottom. c. Making a phase portrait follows from the Mathematica command ContourPlot. A ContourPlot of the energy plots the curves {1ft [t] ,1ft' [t]} for different values of the energy. For the preceding two examples the phase portraits are In [55] := ptl = ContourPlot[ energy/ .valuesl/. {m -+ 2, r -+ 1 } /. (III -+ #) / /Evaluate, {I/r[t], -4:1f, 4 :If}, {r/I[t], -3,3}, I!'rameTicks -+ {:If Range [-4, 4, 2], Automatic}, Colorl!'unction -+ Hue, Plotpoints -+ 100, I!'rameLabel -+ {nl/r n , nr/l n} , Displayl!'unction -+ Identity]& /@ {2, 0.2 }; Displaying the graphs, it follows In[56]:= Show[GraphicsArray[ptl]];  27T 47T 27T 47T o 27T 47T Ijr o 27T 47T Ijr 
6.2 Lagrangian Problems without Lagrange Multipliers 313 The graph on the left is for the double-well potential with w = 2 and the one on the right is the single-well potential with w = 0.2. The large values of if! correspond to repeated motion around the top of the loop. If the initial energy is sufficiently large the bead will continue to loop over the top and without dissipation will never come to rest. The physical points repeat every 2n interval, so it is convenient to draw the energy contours on a cylinder that repeat every 2n. The graphics for a cylinder are In [57] := cylind = ParametriePlot3D[ {v, Sin [u] , Cos [u] }, {u, -7r, 7r}, {v, -3, 3}, Displayl'unetion -+ :Identity]; Combining the cylinder with the phase ttajectories for the double-well, it follows In[58]:= Show[cylind, Graphies3D[ {AbsoluteThiekness[3], Cases[Graphies[ptl[[l]]],-Line, 00]/. {x.,y_} :> {y,1.02 Cos[x], 1. 02 Sin [x] }} ] , ViewPoint -+ {I, l,l}, DisplayFunetion -+ $DisplayFunetion] ; 1 where the curves were lifted slightly above the cylinder with the value of 1.02. The contours that circle the cylinder have sufficient energy to go over the top of the hoop repeatedly. The orbits that don't circle the cylinder are bounded by one or both the potential wells. d. Solve if! numerically for the rapidly spinning loop. If we let In [59] := values2 = {w -+ 2, we -+ I}; then the values of the equilibrium points are 
314 Chapter 6 Lagrangians and Hamiltonians In[60]:= eu1e/.va1ues21IN Out[60]= {{Ijr(t] .d.14159}, {Ijr[t] ....D.}, {Ijr[t] .... -1.31812}, {Ijr(t] .71.31812}} The equation for ifI follows from iflSol: In[61]:= eq1 = t/fSo11 I. {g.... wc 2 r}1 . Rule .... Equal Out[61]= {Ijr"[t] == _wc 2 Sin[ljr[t]] + w 2 Cos [Ijr(t]] Sin[ljr[t]]} Instead of solving this second order equation, solve two equivalent first order equations: In [62] := eq2 = {eq1/.{I/f'[t] ....dl/f[t]}, I/f[t] == dt/f[t]} II Flatten Out[62]= {dljr' [t] == -wc 2 Sin[Ijr(t]] + w 2 Cos [Ijr(t]] Sin[Ijr(t]], Ijr' [t] == dljr[t]} Start the motion at the bottom of the well with e [0] ==1.318. For one example pick the initial value for difI [0] so that the motion is bounded by the well and another example where the energy carries the bead around the loop. In particular, let difI [ 0 ] = 1 and 2 . 5. Applying NDSolve to eq2, you get In[63]:= ndso11 = NDSo1ve[{eq211.va1ues2, t/f[0] == 1.1318, dt/f[O] ==#}IIF1atten, {t/f[t],dt/f[t]}, {t, 0, 10}][ [1]]&: /1# { 1,2.5} Out[63]= {{Ijr(t] .... Interpo1atingFunction [{ {D., 1D.}}, <>] [ t], dljr[t] .... InterpolatingFunction[ {{D., 1D.}}, <>] [t]}, {Ijr[t] .... InterpolatingFunction [ {{D., 1D.}}, <>] [t], dljr [t] .... InterpolatingFunction [ { { D., 1 D . } }, <>] [t] } } The top two solutions correspond to bound motion and the bottom two correspond to unbound motion. If we define the functions, In[64]:= t/f[1] [t_] = t/f[t]/.ndsoll[[l,l]]; dt/f[l] [t.] = dt/f[t] I .ndsoll [[1,2]]; t/f[2] [t_] = t/f[t]/.ndsoll[[2,1]]; dt/f[2] [t.] = dt/f[t] I .ndsoll [[2,2]]; then the plots for difI and ifI are 
6.2 Lagrangian Problems without Lagrange Multipliers 315 In [65] := pt2 = Plot [ {dt/f[#] [t], t/f[#] [t]} II Evaluate, {t,O,10}, P1otSty1e -+ {Dashing [ {O . 04} ], Abso1uteThickness[2] }, Ticks -+ { Automatic, 7r/2 Range [1,12,3] }, DisplayFunction -+ :Identity ] &: III Range [ 2] ; Displaying the results, it follows In[66]:= Show[GraphicsArray[pt2]]; JT "2 JT ,'J' j ' \ \ 2 \.,/ \. '.... 2 4 6 8 10 The dark line is a plot of ifI and the dashed line is a plot of ifI'. The plot on the left is for a small push and the one on the right is for a larger push. The particle with the small push just oscillates around the bottom of the potential well while the energetic particle continues to go over the top of the loop. The phase trajectory for the motion follows from In[67]:= pt3 = parametricP1ot[ { t/f[#] [t], dt/f[#] [t]} II Evaluate, {t,O,10}, P1otSty1e-+ Abso1uteThickness[2], Disp1ayFunction -+ :Identity] &: III {1, 2} ; Combining the two phase trajectories with the phase pomait, we get In[68]:= Show[pt1[[1]],pt3, Disp1ayFunction -+ $Disp1ayFunction] ; 
316 Chapter 6 Lagrangians and Hamiltonians -2 JT 2JT 4JT e. To animate the solution, consttuct the Graphics for the bead on the hoop at an instant of time t: In [69] := bead[t_] .- Graphics[{PointSize[0.03], Point [{Sin [t/f[1] [t]], Cos[t/f[l] [t] ]}]}]; Generate a set of graphics with a Do loop. This can be animated to see the motion (all but one frame is suppressed): In [70] := frames = 1; Do[ Show [ {bead[t], Graphics [{Hue [0 .1], Circle [{O, O}, 1] }, P10tRange -+ {{-2, 2}, {-2, 2}}, AspectRatio -+ 1 ]} , {t, 0, 10, 10/(frames -1)}] '_.--- . o, '-, '-- \ \ , The value of frames determines the nudt>er of frames displayed. 
6.2 Lagrangian Problems without Lagrange Multipliers 317 . PROBLEM 4 Springs Mounted on Top of a Carriage. A massless carriage runs along rails pointed in the x-direction. The carriage is attached to one end of a spring with equi- librium length rO and force constant K. The other end is attached to a fixed point denoted by A. Riding on top of the carriage is a beam pointing in the y-direction. Another spring is attached to the top of the carriage and runs along the beam with its other end attached to a particle of mass m. The whole system is forced to rotate with constant angular speed w around the point A in the {x, y} plane. co k m C: K L a. Express the Lagrangian in terms of coordinates fixed to the beam. Call these coordi- nates {xb, yb}. The coordinate xb runs in the direction of the rails and yb is along the beam. Find the equations of motion. b. Let k=l, K=l, m=1, and rO=l and solve the equations of motion for an arbittary w. Plot the motion of the mass in the reference frames of the beam and in an inertial reference frame for different values of w. c. Draw the phase ttajectory {y, y,} in the body and inertial frames. Solution In[71]:= Clear [RGlobal , * R] a. Let the particle's position be {xi, yi }, where the Cartesian coordinates are defined relative to an inertial reference frame with origin at A. The kinetic energy is In [72] := T =  m (xi' [t]2 +yi' [t]2); Let {xb, yb} be coordinates fixed to the beam, where xb is in the direction of the rails and yb is along the beam. The potential energy is 
318 Chapter 6 Lagrangians and Hamiltonians 1 1 In[73]:= V = - K (-rO +xb[t])2 + - kyb[t]2; 2 2 where rO is the length of the unsttetched spring. Since the system is rotating around A the two coordinate systems are related by a rotation matrix: In[74]:= change = { xi -+ «(xb [I]) Cos [w #] - yb [I] Sin [w I]) &:) , yi -+ «(xb[#]) Sin[w#] +yb[#] Cos[w#])&:)}; If we express all the quantities in terms of {xb, yb} then the Lagrangian becomes In [75] := L = T-V/.change//FUllSiD1Plify 1 2 2 2 Out[75]= "2 (-KrO + (-K+mw ) xb[t] - k yb [t] 2 + 2 xb [t] (K rO + m w yb' [t] ) + m ( (-w yb [t] + xb' [t] ) 2 + yb' [t] 2) ) The equations of motion follow from In[76]:= eqmotion = EulerEquations[L, {xb[t],yb[t]},t]// Solve [#, {xb" [t], yb" [t]}] &: Out[76]= {{xb"[t]-> -KrO- (-K+mw 2 ) xb[t] -2mwyb'[t] m -(-k+mw 2 ) yb[t] +2mwxb'[t] }} yb" [t] ->- m b. The two equations of motion have an analytic solution. To simplify the results set In [77] : = values = {K -+ 1, k -+ 1, m -+ 1, rO -+ 1}; The equations of motion become In[78]:= {eq1, eq2} = (eqmotion [[1]] / .va1ues/ . Rules -+ Equal) Out[78]= {xb"[t] ->1+ (_1+w 2 ) xb[t] +2wyb'[t], yb"[t] -> (-1+w 2 ) yb[t] -2wxb'[t]) These equations can be reduced to a single complex equation. Multiply the second equa- tion by I and add it to the first equation In [79] : = eq3 = xb" [t] +:I yb" [t] == (xb" [t] +:I yb" [t] / .eq1/ .eq2) Out[79]= xb"[t] +iyb"[t] ==1+ (_1+w 2 ) xb[t]+ i ((-1+w 2 ) yb[t] -2wxb'[t]) +2wyb'[t] 
6.2 Lagrangian Problems without Lagrange Multipliers 319 Now let xb+J: yb-+u, In[80]:= eq4=eq3/.xb-+ «u[#] -I yb[#])&:)I/ Sill\Plify Out[80]= u"[t] ==1+ (-1+w 2 )u[t] -2iwu'[t] For a particular set of initial conditions, xb [0] =1, xb' [0] =0, yb [0] =0, andyb' [0] =, the solution is In[81]:= uSo1=u[t]/. DSo1ve[{eq4, u[O] == 1,u'[0] == O}, u[t],t][[l]]// ExpTOTrigl/ Simp1ify//Expand 1 w 2 Cos [t] Cos [t w] Out[81]= - _1+w2 + -1+w 2 iw 3 Cos[tw] Sin[t] -1 + w 2 iw 2 Cos[t] Sin[tw] w 3 Sin[t] Sin[tw] -1 + w 2 + -1 + w 2 + The real part of the solution is x: In [82] := xSo1 = uSo1/. Coq>lex [a_, b.] -+ Coq>lex [a, 0] / / Sill\Plify -1+w 2 Cos[t] Cos[tw] +w 3 sin[t] Sin[tw] Out[82]= -1 + w 2 and the complex part is y: In[83]:= ySo1= (uSo1-xSo1//Together)/.I-+11/ Sill\Plify w 2 (w Cos[tw] Sin[t] -Cos[t] Sin[tw]) Out[83]= 2 -1 + w Let us graph the motion for the following values of w, In[84]:= wva1ues = {0.2, 0.4, 0.6, 0.8}; The motion relative to the beam's frame is In[85]:= 1istb = parametricP1ot[ {xSo1, ySo1) /.w -+ # / /Eva1uate, {t, 0, 100}, P1otpoints -+ 100, AspectRatio -+ 1, AxesLabe1 -+ {nxb n , nyb n }, Ticks -+ False, Disp1ayFunction -+ Identity] &: III wva1ues; 
320 Chapter 6 Lagrangians and Hamiltonians Displaying the results, it follows In[86]:= Show[GraphicsArray[Partition[listb,2]]]; yb yb Xb  yb yb e The motion in the inertial frame follows from In[87]:= change Out[87]= {xi.... (xb[#1] Cos[w#1] -yb[#1] Sin[w#1]&), yi.... (xb[#l] Sin[w#l] +yb[#1] Cos[w#l]&)} so the inertial coordinates {xi [t] , yi [t] } are In[88]:= eq2 = {xi [t], yi [t]}1 . change I . xb[t] -+ xSol/. yb[t] -+ ySol IISiD1Plify { W 2 Cos[t] -Cos[tw] w 3 Sin[t] -Sin[tW] } Out[88]= -1 + w 2 ' -1 + w 2 The graphics for the inertial motions are In[89]:= listi = parametricPlot [eq2/.w -+ #11 Evaluate, {t,O,100}, AxesLabel -+ {n xi n, nyi n } , AspectRatio -+ 1, Ticks -+ False, Disp1ayFunction -+ :Identity] &oj@. wva1ues ; Displaying the results, we get 
6.2 Lagrangian Problems without Lagrange Multipliers 321 yi In[90]:= Show[GraphicsArray[Partition[listi,2]]]; yi yi xi xi yi xi xi C. Let us draw the phase ttajectories {y, y' } in the body and inertial frames. The phase ttajectory in the body frame is In[91]:= listpb = ParametricPlot[ {ySol, D [ySol, t]} I.w -+ III Evaluate, {t, 0, 100}, AspectRatio -+ 1, AxesLabe1 -+ {nyb n , n yb' n}, Ticks -+ False, Disp1ayl'unction -+ :Identi ty] &: III wvalues; yb' In[92]:= Show[GraphicsArray[Partition[listpb,2]]]; yb' yb' yb yb yb' yb yb 
322 Chapter 6 Lagrangians and Hamiltonians In the inertial frame, we get In[93]:= 1istpi = ParametricP1ot[ {eq2 [[2]], D[eq2 [[2]], t]} I.w -+ II I Evaluate, {t, 0, 100}, AspectRatio -+ 1, AxesLabe1 -+ {DybD, D yb' D}, Ticks -+ False, Disp1ayFunction -+ :Identity] &: Iii wva1ues; yb' In[94]:= Show[GraphicsArray[Partition[listpi,2]]]; yb' yb' . yb yb yb' yb yb PROBLEM 5 Mass Falling through a Hole in a Table. 1\\'0 mass points mi andm2 are connected by a sITing of length len passing through a hole in a smooth table. The mass mi rests on the table's surface, and m2 hangs suspended and moves only along a vertical line. Place the origin of the coordinate system at the hole and use polar coordinates {r, f/J} to describe the motion of mass mi. The distance from the hole to mi is r, and f/J is its angular position around the hole. Describe the hanging particle by the vertical distance from the hole, z=len-r. The direction of the coordinate z is along the direction of the gravitational force. 
6.2 Lagrangian Problems without Lagrange Multipliers 323 {r. 9} /_-----  ----- r --. - , - , ,/" ..",' , I cI> _- : I ......... '" - - - - -- - - - - - -} - --- - -- I z m2 a. Show that the equations of motion for r [t] and 4J [t] can be expressed as " [ ] g m2 h 2 ml rt=- + , ml + m2 (ml + m2)r[t]3 , h 4J [t] =  r[t] b. Find the effective potential and analyze the motion. c. Numerically solve for the motion of the particle on the table and plot the results. Solution In [95] := Clear[nGlobal' * n] a. Let us proceed by finding the Lagrangian. The kinetic and potential energies for the particle on the table are In[96]:= Tl= ml (r'[t]2+ r [t]2t/1'[t]2); Vl = 0; The hanging particle is described by the coordinate z [t] =len-r [t] : In[97]:= zRule= {z-+ «len-r[#])&:»; and its kinetic and potential energies are In [98] := T2 =  m2 z' [t] 2/ .zRule; 2 V2 = -m2 g z [t] / .zRule; The Lagrangian for the system is In[99]:= L= (Tl+T2) - (Vl+V2) 1 Out[99]= gm2 (len-r[t]) +-m2r'[t]2+ 2 1 - ml (r' [t] 2 + r [t] 2 <1>' [t] 2 ) 2 
324 Chapter 6 Lagrangians and Hamiltonians and the equations of motion follow from EulerEquations: In[100]:= eq1 = EulerEquations [L, {r[t], t/J[t]}, t] Out[100]= {-gm2+mlr[t] <I>'[t]2- (ml+m2)r"[t] ==0, -ml r[t] (2 r' [t] <1>' [t] + r[t] <1>" [t]) == O} Simplifying by solving for {If>" [t] ,r" [t]}, it follows In[101] : = eq2 = Solve [eq1, {t/J" [t], r" [t]}] / / Flatten; eq2 / / ColumnForm , gm2-mlr[t] <I>'[t]2 r'[t]-> -ml-m2 <1>" [t] -> _ 2 r' [t] <1>' [t] r[t] Out[101]= The first equation can be integrated once to give In[102]:= FirstXntegrals[L, {r[t],t/J[t]},t]// ColumnForm FirstIntegral[<I>] ->-mlr[t]2<1>'[t] FirstIntegral [t] ->  (-2 g lenm2 + 2 g m2 r [t] + (ml + m2) r' [t] 2 + ml r [t] 2 <1>' [t] 2) 2 Out[102]= The first term is the conservation of angular momentum and the second term is just the conserved energy. The angular momentum FirstJ:ntegral gives the following rules { , h" 2 h r' [t] } In[103]:=eqt/J= t/J[t]-+,t/J [t]-+- 3 ; r[t] r[t] The constant h is a consequence of the conservation of angular momentum. We can use eqlf> to eliminate the angular dependence from the radial equation In[104]:= eqR = eq2 [[1]] / .eqt/J/ /Simplify / /ExpandAll Out[104]= r" [t] -> h 2 ml mlr[t]3 +m2r[t]3 gm2 r[t] 3 mlr[t]3 +m2r[t]3 The equations of motion are In [1 05] : = eqMotion = {eqt/J [ [1] ] , eqR} / .Rule -+ Equal/ / Flatten; eqMotion / / ColumnForm , h <I> [t] == r[t]2 h 2 ml r" [t] == mlr[t]3+ m 2r[t]3 Out[105]= gm2 r[t] 3 mlr[t]3 +m2r[t]3 
6.2 Lagrangian Problems without Lagrange Multipliers 325 b. To find the effective potential we define the total energy In[106]:= energy = T1 + T2 + V1 + V2/ .eqofJ/ /Simplify / / ExpandAll h 2 ml -g len m2 + --"2 + 2 r[t] I 2 I , 2 gm2r[t] + 2"mlr'[t] + 2"m2r [t] Out[106]= The effective potential is obtained by setting r' [t] to zero In[107]:= Effpot = (+g len m2 + energy) / . {r'[t] -+O,r[t] -+r}//Apart h 2 ml Out[107]= +gm2r 2r where, without loss of generality, we have added a constant term. The potential has a minimum at In[108]:= min = D[Effpot, r] == O//Solve[#, r] [[1]]&: h 2 / 3 ml 1 / 3 Out[108]= { r-7 1/3 1/3 } g m2 To plot the potential consider the parameters In[109]:= values = {h-+ l,m1-+ 1, m2 -+ 1, g-+ 1}; The potential plot follows from In[llO]:= Plot[Effpot/.values//Evaluate, {r,O.2,3}]; 5 4.5 4 3.5 3 2.5 1.5 The radial motion is bounded from above and below for h not zero. Another way of visualizing the motion follows from plotting the energy contours: 
326 Chapter 6 Lagrangians and Hamiltonians In[lll]:= ContourPlot [energy/ .values/ .len -+ 10 / / Evaluate, {r[t], 0.2, 6}, {r' [t], -1, 1}, ContourSbading -+ True, ColorFunction -+ Rue ]; Again, it is obvious that the r-motion is bounded from above and below for h not zero. c. Let us numerically solve for r and 4J with the parameters In[112]:= values = {h-+ 1,ml-+ 1,m2 -+ 1, g-+ 1}; The numerical solution is In[113]:= ndsol = NDSolve[ {eqMotion/.values"fJ[O] == 0, r[O] == 2,r'[0] == O}//Flatten, {tfJ[t], r[t]}, {t, 0, 70}] [[1]] ; If we define the functions, In [114] := tfJl[t_] = tfJ[t]/.ndsol; rl[t_] = r[t]/.ndsol; then the plot of the ttajectory for the particle on the table follows from {r Cos [4J], r Sin [4JJ}: In[115]:= parametricPlot[ rl [t] {Cos [tfJl [t]], Sin [ tfJl [t]]} / / Evaluate, {t, 0, 70}, AspectRatio -+ AutOllllAtic, Epilog -+ {AbsoluteThickness [3], Circle [{O, O}, 2], Circle [{O, O}, 0.55]} ] ; 
6.2 Lagrangian Problems without Lagrange Multipliers 327 The two dark circles show the upper and lower bounds for r. The particle rotates around the table top confined within these two circles. . PROBLEM 6 Spring Pendulum. A spring pendulum has a mass m suspended by an elas- tic spring of stiffness k and force-free length LO. Assume the motion is confined to a plane. a. Write the Lagrangian in polar coordinates {r, O} and show that the equations of motion are k(LO - r[t]) r"[t] = gcos[O[t]] + + r[t]B'[tf m 
328 Chapter 6 Lagrangians and Hamiltonians B"[t] = g sin[B[t]] _ 2r'[t]B'[t] r[t] r[t] b. Solve the equations when there is no angular motion and show the equilibrium length of the spring is LO + g; . c. Find a numerical solution with initial conditions so the mass does not loop over the top. Plot the coordinates { r, B}, the position of the bob, and the phase ttajectory. d. Find a second numerical solution where the pendulum is given sufficient initial an- gular motion to rotate over the top. Plot the coordinates, position of the bob, and phase ttajectory. e. Animate one of the numerical solutions. Solution In[116]:= Clear[nGlobal' * n] a. Consider a bob of mass m attached to a spring with spring constant k. Assume the motion is in a plane. Let {x,y} be the coordinates of the bob, where the origin is at the support of the pendulum. Let the x coordinate point downward in the direction of the gravity and y point to the right of x. The length of the pendulum is In[117]:= lsrule=lst.... ( -V X[ll]2+Y[ll]2&:); The kinetic and potential energies, expressed in Cartesian coordinates, are In[118]:= T= m(x'[t]2+Y'[t]2); 1 vsp= -k(-LO+lst[t])2; 2 Vgr=-mgx[t]; where LO is the length of the spring with no load. Express the elastic pendulum in polar coordinates {r, B}. The relations between the Cartesian and polar coordinates are In [119] : = polarrule = {x.... «r [I] Cos [8 [I]] ) &:) , Y.... «r[l] Sin[8[1] ])&:)}; The Lagrangian is In[120]:= L = T - Vsp - vgr/ .lsrule/ .polarrule/ / Simplify/ /powerExpand 1 Out[120]= "2 (2gmCos[S[t]] r[t] +kLO (-LO+2r[t])+ m r' [t] 2 + r [t] 2 (-k + m s' [t] 2) } and the equations of motion follow from 
6.2 Lagrangian Problems without Lagrange Multipliers 329 In[121J:= eqMotion = « EulerEquations [L, {r[t], e[t]}, t] II ( Solve [#, {r" [t], e" [t]}] [ [1]] &: ) ) I .Rule -+ Equal l/EXpandAll ) ; eqMotion I I ColumnForm Out [121J = r" [t] == k LO + g Cos [e [t]] _ k r [t] + r [t] e' [t] 2 ID ID e" [t == _ g Sin[e [t]] _ 2 r' [t] e' [t] ] r[t] r[t] b. A special solution is vertical motion with no angular motion. The condition for no angular motion is In [122J := vertical = {e-+ (O&:)}; The equations for this case are In[123J:= vertMotion = eqMotionl .Rule -+ Equal I . vertical { " kLO kr[t] } Out[123J= r [t] ==g+-;--,True The angular equation is automatically satisfied and the solution for the radial equation becomes In[124J:= vert Sol = DSolve [vertMotion [[1]] , r[t], t] I I FlattenllExpandAll Out[124J= {r[t] ....LO+ gk ID + [ Vkt ] C [1] Cos vm + C [2] . [ Vkt ]} Sn - vm The bob oscillates with frequency ..{f; around the length of the spring under the load: In[125J : = vert Soli . C [1] -+ 01. C [2] -+ 01 II!'1atten I I ExpandAll Out[125J= {r[t] ....LO+ gk ID } C. Let us find the numerical solution for the motion with the parameters In [126J := valuesc = {LO -+ 40/9, n -+ 1, k -+ 4, g -+ 1, m -+ 1}; and the initial conditions 
330 Chapter 6 Lagrangians and Hamiltonians In[127]:= initialc = {r[O] == (LO + gm/k) + 1, r' [0] == 0.1, 8[0] == 1/2 7f, 8' [0] == O.}I .valuesc; The initial conditions have been chosen so the solution does not loop over the top. The equations of motion and initial conditions become In[128]:= neqc = {eqMotion, initialc} 1 .Rule -+ Equal I. valuescllFlatten ; and its numerical solution follows from In[129]:= nSolc = NDSolve [neqc, {r [t], 8 [t] }, {t, 0, 110}, MaxSteps -+ 2000 ] II Flatten; If we define the interpolating functions In[130]:= rc[t.] =r[t]/.nSolc; 8c[t_] =8[t]/.nSolc; then the plots for r [t] and () [t] follow from In[131]:= Plot [ {rc[t], 8c[t] }IIEvaluate, {t, 0, 110}, PlotStyle -+ {Bue [0.7], Bue [0.9]} , Ticks -+ {Automatic, 7f Range [-1, 2, 1 ] } , Epilog -+ Map[Line, HO, #7f}, {125, #7f} }&: I@ Range [-1, 2]] ] ; The top curve is the variation of the radial coordinate and the bottom is the angular coor- dinate. The graphics for the motion of the bob follow from 
6.2 Lagrangian Problems without Lagrange Multipliers 331 In[132]:= ParametricPlot[ rc[t]{Sin[8c[t]], -Cos[8c[t]]} II Evaluate, {t, 0, 110}, PlotStyle -+ Bue [0 .9], AspectRatio -+ 1, PlotRange -+ {Automatic, {-8, 8}}, Epilog -+ {Circle [{O, O}, #] &:/@{6, 4, 2} } ] ; 8 .8 The phase ttajectories, {r [t] , r' [tJ} and {e [t] ,e' [tJ}, follow from In[133]:= ptl = parametricPlot [ {# [t], #' [t] } II Evaluate, {t, 0, 110}, PlotStyle -+ {Hue [0.7], Hue [0 .9] }, Ticks -+ l"alse, DisplayFunction -+ Identity ] &: I@ {rc, 8c}; Sbow[GraphicsArray[pt1]]; The graph on the left is for { r, r'} and the one on the right is {O, O'}. d. Let us find the numerical solution of the equations of motion for the parameters In[134]:= valuesd = {LO -+ 5, n -+ 1, k-+ 2, g-+ l,m-+ 1}; 
332 Chapter 6 Lagrangians and Hamiltonians and the initial conditions In [135] := initiald = {r[O] == (LO+ gm/k+O.Ol) ,r'[O] ==0, 8[0] ==7f -0.07,8'[0] == O}/.valuesd; The initial conditions have been chosen so the solution loops over the top. The equations of motion and initial conditions become In[136]:= neqd = {etion, initiald}/ .Rule -+ Equal /. valuesd//Flatten; and the numerical solution is In[137]:= nSold = NDSolve[neqd, {r[t], 8[t]}, {t, O,llO}, MaxSteps -+ 2000] / /Flatten; We define the interpolating functions for r and (): In[138]:= rd[t_] =r[t]/.nSold; ed[t_] = 8[t] / .nSold; The plots for the r [t] and () [t] follow from In[139]:= Plot [ {rd[t],ed[t] }//Evaluate, {t,O,llO}, PlotStyle -+ {Hue [0.7], Hue [0. 9J} , Ticks -+ {Automatic, 7f Range [-5, 2, 1 ] } , Epilog -+ Map [Line, HO, #7f}, {125, #7f} }&: /@ Range [-5,2]] ] ; If 2lf -If -2 If -3 If -4 If - 5 If ". 
6.2 Lagrangian Problems without Lagrange Multipliers 333 The top curve is the variation of the radial coordinate and the bottom is the angular coordinate. The level parts of the angular graph correspond to the times when the bob loops over the top. The graphics for the motion of the bob follow from In[140]:= parametricPlot[ rd[t]{Sin[ad[t]],-Cos[ad[t]]}// Evaluate, {t, O,l10}, Plot Style -+ Bue [0.9], PlotRange -+ All, AspectRatio -+ Automatic, Epilog -+ { Circle [{O, O}, #] &:/GI-{8, 6, 4}} ] ; and the phase ttajectories are In [141] : = ptl = parametricPlot [ {# [t], #' [t] }/ /Evaluate, {t, 0, 110}, Plot Style -+ {Bue [0.7], Bue [0.9] } , Ticks -+ False, Displayl!'unction -+ Identity ] &: /GI- {rd, ad}; Show[GraphicsArray[ptl]]; 
334 Chapter 6 Lagrangians and Hamiltonians e. To animate the motion define In[142]:= line[t_] := Show [ Graphics [ {{Line [{{O, O}, rc[t]{Sin[8c[t]],-Cos[8c[t]]}}], {PointSize[O.l], Point [ rd[t] {Sin[8c[t]], -Cos[8c[t]]}]}}}, PlotRange-+ {{-10, 10}, {-13, 13}} The motion follows from (all but two frames are suppressed) In[143]:= frames = 2; movie = line [I] &: /8- Range [0,30,30/( frames - 1) ] ; e  . 
6.3 Lagrangian Problems with Lagrange Multipliers 335 6.3 . LAGRANGIAN PROBLEMS WITH LAGRANGE MULTIPLIERS 6.3.1 . Overview of Nonholonomic Constraints and Lagrange Multipliers For nonholonomic systems, the coordinates qj are not independent of each other and it is impossible to reduce them by means of consttaint equations. However, if there are k consttaints of the form 2:1 Ajk{jqk = 0, where j = {l, ..., k}, then Lagrange multipliers can be used to describe the consttaints. The equations of motion that follow from these consttaints are xl d ( BL ) ( BL ) dt Bqj - Bqj = Qj where Qj = 2:=1 AZAlj' The k parameters Al are called Lagrange multipliers. Lagrangian equations give a coupled set of second order differential equations. Throughout this chapter, you will need to compute Lagrange's equations of motion with consttaints. The user-defined function Lag[qi,L,Qi,t:t] will compute this in one step in the case of one or more variables. Before starting these problems load the user-defined function Lag [qi, L, Qi, t : t] : In[144] : = Lag [qL, L., QL, t_ : t] : = D[D[L, (D[qi[t],t])],t] -D[L,qi[t]] ==Qi; Lag [qLList, L_, QLList, t. : t] : = (D[D[L, (D[qi[[#]][t],t])],t] -D[L,qi[[#]][t]] ==Qi[[#]] )& /@ Range [1, Length[qi]]; This command computes Lagrange's equations of motion given the canonical coordi- nate qi, the Lagrangian L, and the generalized force Qi. The generalized coordinate qi can be entered as a list or as a single coordinate. Finally we apply Protect to the user-defined procedure to kept it from being deleted with Clear ["Global' *"] : In[145]:= protect[Lag]; . x2 PROBLEM 1 Atwood Machine. An Atwood machine consists of two weights with masses ml and m2 connected by a light, inextensible cord of length Len. The cord passes over a frictionless pulley. Let xl be the coordinate of mass ml and let x2 be the coordinate of mass m2. The coordinates xl and x2 are the vertical distances from the pulley to the masses. Assume the masses move only in a vertical direction. Express the Lagrangian in terms of xl and x2. Find the Lagrange multipliers from the consttaint that the cord does not sttetch. Find the equations of motion for xl and x2 using Lagrange multipliers. Solve for the motion. Remarks and Outline The variables xl and x2 can be tteated as independent and the consttaint Len=xl+x2 can be used to get a Lagrange multiplier. The user-defined func- tion Lag gives two equations. A third equation follows from Len=xl+x2. 
336 Chapter 6 Lagrangians and Hamiltonians Solution In[146] : = Clear [RGlobal' * R] Let us solve the Atwood problem using two independent variables and a Lagrange multi- plier. The potential and kinetic energies are In[147]:= T =  Sum [m[i] x[i]' [t]2, {i,l, 2}]; v= (-g) Sum[m[i] x[i] [t], {i,l,2}]; The Lagrangian in terms of x [ 1] and x [2] is In[148]:= L = T-V Out[148]= g (m[l] x[l] [t] +m[2] x[2] [t])+ 1 - (m[l] x[1]'[t]2 +m[2] x[2]'[t]2) 2 where x [2] is tteated as an independent variable. The consttaint equation follows from the fixed length of the sITing and is given by f [1] : In[149]:= f[l] =x[l][t] +x[2][t] -Len; The differential form of f [1] gives the consttaint forces {Q [1] , Q [2] } as expressed in terms of the Lagrange multiplier A [1] : In[150]:= Qeq=D[f[l],x[#] [tJ] A[1]&:/GI-{l,2} Out[150]= {A[l],A[l]} Two equations of motion follow from the user-defined command Lag: In[151]:= eq2 = Lag [{x[l], x[2)}, L, Qeq] Out[151]= {-gm[l] +m[l] x[l]"[t] ==A[l], -gm[2] +m[2] x[2]"[t] ==A[l]} where eq2 gives two equations for the three unknowns x [ 1], x [2 ], and A [ 1]. The third equation follows from the f [1] ==0 consttaint: In [152] := f[l] == 0 Out[152]= -Len+x[l] [t] +x[2] [t] == 0 You get an equation more relevant to the calculation by taking the second derivative of length, In[153]:= eq3 = D[f[l] == 0, {t, 2}] Out[153]= x[l]"[t] +x[2]"[t] == 0 
6.3 Lagrangian Problems with Lagrange Multipliers 337 You get three equations by applying Solve to eq2 and eq3: In[154]:= eq4 = «Solve [{eq2, eq3} IIFlatten, {A[l], (x[2])"[t], (x[l])"[t]), t] Iisimplify I/Flatten ) I. {Rule -+ Equal} ) ; eq4 I I ColumnForm 2 gm[l] m[2] A[l] == - m[l] +m[2 j Out[154]= x[2]" [t] == g (-m [ l +m[2]) m[l] +m[2] x[l]"[t] == g (mIl ] -m [ 2 ] ) m[l] +m[2] These three equations are uncoupled and it is a trivial task to solve them. Assuming the initial conditions In[155]:= initial = {x[l] [0] == xO, (x[l])' [0] == vO}; the solution for x [1] follows from part three of eq4: In [156] := soll = DSolve [{eq4 [[ {3}]], initial} II Flatten, {(x[l]) [t]},t]IIFullSimplify II Flatten Out[156]= { X[l] [t] -7tvO+xO+ gt 2 (m[l] -m[2]) } 2 (m[l] + m[2]) The solution for x [2] follows from the length consttaint: In[157]:= so12 = {x[2] [t] -+Len-x[l] [t)/.soll} Out[157]= { X[2] [t] -7Len-tvO-xO- gt 2 (m[l] -m[2]) } 2 (m[l] +m[2]) . PROBLEM 2 Hoop Rolling on an Incline. Consider a hoop of radius r rolling down a fixed incline without slipping. Let rp be the inclination angle of the incline. Specify the position of the hoop by the distance x ttaveled by the center of mass along the incline and let e be the rotation angle of the hoop. Let x=O at the top of the incline and x=Len at the bottom of the incline. a. Express the Lagrangian in terms of x and e. Write the slippage consttaint and use Lagrange multipliers to obtain the equations of motion for the variables x and e. b. Solve for x [t] and e [t] and plot the motion of a fixed point on the hoop as the hoop rolls down the incline. 
DB Chapter 6 Lagrangians and Hamiltonians r x=9r Remarks and Outline The problem simplifies if the generalized coordinates are chosen to be the center of mass along the incline x [t], and the motion about the center of mass as described by the angular variable 0 [t] . The Lagrange multiplier follows from the con- dition that there is no slippage, r dO- dx=O. The equations of motion follow from Lag and they are solved with DSolve. Solution In[158]:= Clear[nGlobal' * n] a. The kinetic energy can be resolved into the kinetic energy of the center of mass, plus the rotational energy about the center of mass. Let x [t] be the position vector of the center of mass and 0 [t] be the angular variable around the center of mass. The kinetic and potential energies and Lagrangian are In [159] := T =  m (x' [t]2 +:r'I e' [t]2); V=mg (Len-x[t]) Sin[I[J]; L=T-V Out[159]= -gm Sin[c/>] (Len - x[t]) + 1 _ m (x' [t] 2 + r 2 e' [t] 2) 2 where Len is the length of the incline and rp is the angle of slant. The no slippage consttaint is In[160]:= eql = re[t] -x[t] == 0; The derivatives of eql gives the consttaint forces {Q [ 1] , Q [2]} as expressed in terms of the Lagrange multiplier A [1] : In[161]:= constraintForce = {Q [1] -+ A D[eql [[1]], x[t]], Q [2] -+ A D[eql [[1]], e[t]]} Out[161]= {Q[l] -+ -A, Q[2] -+ r A} The constraintForce gives the expression for the generalized slippage force {Q [1] , Q [2] }. The equations of motion follow from applying Lag to L 
6.3 Lagrangian Problems with Lagrange Multipliers 339 In[162]: = {eqX, eq8} = Lag [ {x, e}, L, {Q[1], Q[2]}] I I. constraintForce; {eqX,eq8}IIColumnForm Out[162]= -gm Sin[c/>] +mx" [t] ==-A m r 2 e" [t] = = r A You now have two equations of motion and one consttaint equation. These three equa- tions can be solved for the three unknowns x, 0, and A. b. Solve the equations of motion given the following initial conditions: In[163]:= initial = {x[O] ==xO,x'[O] ==vO, e[O] == xO/r, e' [0] == vOir}; Next, use DSo1ve to solve for x[t] and O[t]: In[164]:= xtsol = DSolve[{eqX,eq8,initial}IIFlatten, {x[t], e[t]}, t] [[1]] { 2mtvO+2mxO-t2A+gmt2 Sin[c/>] x[t] 2m ' 2 m t vO + 2 m xO + t 2 A } e[t] 2mr Out[164]= The expression for A follows from the slippage consttaint in eql. Use xtSo1 to elim- inate x[t] and O[t] in eql: In[165]:= ASol = Solve [eq1/.xtSol, A] Out[165]= {{AgmSin[c/>]}} If we use ASo1 to eliminate A in xtSo1 then the expressions for x [t] and 0 [t] become In[166]:= xtSol2 = xtSoll .ASoll /EXpandAlll /Flatten Out[166]= {X[t] tvo+xO+gt2 Sin[c/>], t vO xO g t 2 Sin [c/>] } e[t] ++ 4r C. Let us plot the motion of a point on the hoop as the hoop rolls down the incline. Consider the values: In[167]:= values = {xO-+0,vO-+0,g-+-0.1,t[I-+7r/4, r-+2.}; The x and y coordinates for a fixed point on the hoop are In[168]:= posx = (x[t]Sin[t[I] + rsin[e[t]]); posy = (x[t]Cos[t[I] +rCos[e[t])}; 
340 Chapter 6 Lagrangians and Hamiltonians The point on the hoop is given by In [169] := point = posx, posy/ .xtSo12/ / .values; This is easily displayed with parametricPlot: In[170]:= ParametricPlot[point//Bvaluate, {t, 0, 70}, AspectRatio -+ 1 ]; . PROBLEM 3 Sphere Rolling on a Fixed Sphere. A sphere of radius a and mass m rests on top of a fixed sphere of radius b. The first sphere is slightly displaced so that it rolls (without slipping) down the second sphere. Let the { z, x} plane be chosen to pass through the centers of the two spheres and assume the motion is in the {z, x} plane. Choose a spherical coordinate system at the center of the fixed sphere. Let r [t] be the radial vari- able as measured from the origin of the coordinates to the center of the moving sphere. Let 0, be the angular variable measured from the origin of the fixed sphere. The motion of the 
6.3 Lagrangian Problems with Lagrange Multipliers 341 moving sphere's center of mass can be described by the variables {r [t] ,° 1 [t]}. The motion of the moving sphere about its center mass can be described by the variables 01 [t] and 02 [t] where 02 [t] is the angular measure relative to spherical coordinates centered at the moving sphere's center of mass. Note 02 is measured from the contact point of the two spheres. a. Assume the generalized coordinates are {r [t] ,° 1 [t] ,° 2 [t] } and consITuct the Lagrangian. Write the consttaints that there is no slippage and that the spheres are in contact. Use Lagrange multipliers to obtain the equations of motion. b. Show that the equation 01 can be reduced to a first integral. c. Find the angle at which the sphere falls off. Remarks and Outline The total kinetic energy is the kinetic energy of the center of mass plus the kinetic energy of the motion about the center of mass. There are two consttaints: a. the consttaint of contact, r [t] =a+b, and b. the consttaint of no slippage, b 01 [t] -a 02 [t] =0. These two consttaints give the expression for the generalized consttaint forces. The equations of motion follow from Lag. The point at which the sphere falls off follows from setting to zero the Lagrange multiplier associated with the contact consttaint. Solution In[l71]:= Clear[OGlobal' * 0] a. The kinetic energy of the rolling sphere is the energy associated with the motion of its center of mass plus the rotational energy about its center of mass. The kinetic energy of the center of mass of the moving sphere is In[172]:= Tcm= m (r'[t]2 +r[t]2 81 '[t]2); The rotational energy associated with the motion about the sphere's center of mass is 1 In[173]:= Trot = - 11 (81'[t] +82'[t])2; 2 where :[1 is the moment of inertia of the sphere. The rotational energy is a function of the sum (01 [t] + e2[tD, since the first variable is the contribution from the curved surface of the fixed sphere and the second term is from the motion about the center of the moving sphere. The total kinetic energy is In[174]:= T = Tcm + Trot; The potential energy (up to a constant) is In[175]:= V=m g r[t]Cos[81[t]]; The Lagrangian is 
]42 Chapter 6 Lagrangians and Hamiltonians In [176] : = L = T - V Out[176]= -gmCos[el(t]] r[t]+ 1 -m (r'(t]2 +r(t]2 el'[t]2)+ 2 1 -11 (el'[t] +e2'[t])2 2 The two consttaint equations are In[177]:= constraints = {b 81 [t] - a 82 [t] == 0, r[t] - a - b == O} Out[177]= {bel[t] -ae2(t] == 0, -a-b+r[t] == O} The first equation is the condition that there is no slippage. The second equation is the contact condition and states that the distance between the centers of the two spheres is the sum of their radii. The algebra simplifies if you express these equations in terms of pure rules (we use DSolve to obtain this form): In[178]:= constraintRule = DSolve[constraints, {82, r}, t] Out[178]= {{e2....Function[{tL be[t] ], r....Function({t}, a+b]}} The expressions for Q [i] follow from taking the differential of the consttaints. First, obtain a list of the coordinates as a function of t: In[179]:= vars= {r[t],81[t],82[t]}; Then define Q [i] via 2:7=1 Ai ; , where I j is the jth consttaint equation: In[180]:= Qeq = Sum[A[j] * D[constraints [[j, 1]], vars[ [#]]], {j,l, 2}]&: /@ {1, 2, 3} Out[180]= {A[2], bA[l], -aA(l]} The equations of motion are In[181]:= eqMotion= Lag[{r,81,82},L,Qeq]; eqMotion / /ColumnForm gm Cos[el [t]] -mr(t] el' [t]2 +mr" [t] == A[2] Out[181]= -gmr[t] Sin(el[t]] +2mr[t] r'(t] el'[t] +mr[t]2 e l"[t] +11 (el"[t] +e2"[t]) ==bA[l]11 (el"(t] +e2"(t]) ==-aA[l] These three equations plus the two consttaint equations give five equations for the five unknowns: 01,02, r, A [1], and A[2]. b. Use constraintRule to eliminate 02 and r in eqMotion and solve the three equations for 01, A [1], and A [2]. 
6.3 Lagrangian Problems with Lagrange Multipliers 343 In[182]:= p.2Sol, 8Sol, J.1Sol} = (Solve [eqMotionll .constraintRulel IFlatten, {81" [t] , J. [1] , J. [2] } ] I. Rule -+ Equal II Flatten } ; {J.2Sol,8Sol,J.1Sol}IIColumnForm A [2] == gm Cos [e1 [t]] - (a + b) me1' [t] 2 " a 2 gm Sin[e1[t]] e1 [t] == Out[182]= (a+b) (Il+a 2 m) g Il m Sin [e1 [t] ] A [1] == - 2 11 + a m The equation 9801 is the equation for the variable 91 [t]. This equation gives a first integral if we multiply by 91' [t] and integrate both sides of the equation. Move all terms to the left side of the equal sign In[183]:= eq8= (8Sol[[1]] -8S01[[2]]) Out[183]= _ a 2 gm Sin[e1 [t]] + e1" [t] (a + b) (Il + a 2 m) Multiply by 91' [t] and integrate, In[184]:= int8 = rntegrate [eq8 81' [t], {t, 0, t}] II. {81[0] -+0,81'[0] -+O}IISimplifYII Apart a 2 gm(-1+Cos[e1[t]]) 1 1 ' [ ] 2 Out[184]= +-e t (a + b) (Il + a 2 m) 2 (Note that initial conditions are assumed for 91). Next, solve for 91' [t] : In[185] := so18 = Solve [int 8 == 0 , {81' [t]} ] [[1]] I. .y -1 + Cos [x..] -+ i .yl - Cos [x] { -{2a-vgvm v 1-COS[e1[t]] } e1' [t] -7 va + b V Il + a 2 m Out[185]= c. The sphere loses contact when it [2] goes to zero. Setting the expression for it [2] equal to zero, it follows In[186]:= eql = J.2Soll .J.[2] -+ 011 .so18 Out[186]= 0-- 2a 2 gm 2 (1-Cos[e1[t]]) + gm Cos [e1 [t]] 11 + a 2 m Solving for Cos [91 [t] ], you get In[187] := so12 = Solve [eql, Cos [81 [t]]] I/Flatten { 2a 2g m 2 } Cos[e1[t]] -7- 2 2 (Il+a 2 m) ( -gm- ) Il+a m Out[187]= 
344 Chapter 6 Lagrangians and Hamiltonians The sphere falls off when 91 has the value In[188]:= so13 = Solve [so121 I. {Rule -+ Equal}, 81 [t], rnverseFunctions -+ True] II Flatten Out[188]= { [ 2 a 2 m ] 81 [t] -7 -ArcCos 2 ' 11 + 3 a m [ 2 a 2 m ] } 81 [t] -7 ArcCos 2 11 + 3 a m Finally, substitute the moment of inertia for a sphere and convert the angle from radians to degrees: In[189]:= {81[t]/o)ll.so13[[2]]II. { 2 a 2 m } n -+ ----s- I IN Out[189]= 53.9681 . 6.4 . HAMILTONIAN PROBLEMS 6.4.1 . Overview of Hamilton's Equations Consider those systems described by n generalized coordinates qi and the Lagrangian L[ q', q, t]. The Hamiltonian is defined in terms of the Lagrangian L[ q', q, t] by n d H = LPi d qi - L[q', q, t] i=1 t The Pi are the generalized momentum and are related to the generalized coordinates by p[i] = dLt] . By solving these n equations for the q; in terms of the P and q, you can write q; as a function of q and P, q' = q'[p, q]. Eliminate the q; variables in H and express H in terms of the canonical coordinates. The equations of motion follow from , BH[q, p, t] p. = - , I Bqi , BH[q, p, t] q. = I BPi These first-order differential equations are called Hamilton's canonical equations. You will need to compute Hamilton's equations of motion. It is not necessary to under- stand the details of the user-defined procedures until you have done all the problems; then you can go back and examine the procedure. The user-defined function Hamilton will compute this in one step for the case of one or multiple variables: 
6.4 Hamiltonian Problems 345 In[190] : = Hamilton [L., xList.List, PList_List, t. :t] := Module[{xx,vv,pp,sol,ham,eqp,e, eqs}, xx = 'l'hrough[xList [t]]; vv = D[XX, t]; pp = 'l'hrough[pList [t]]; sol = Solve [ (D[L, #]&:/@vv) == pp, vv]11 Flatten; ham = pp.vv - LI I .soll I Simplify I I Expand; eqp = D[pp, t] == -Map [D[ham, I]&:, xx] II Thread; e = D[XX, t] == + Map [D[ham, I]&:, pp] II Thread; eqs = Join [eqp, e]; Return [ {sol, ham, eqs}] Hamilton returns the expression for the canonical momentum, the Hamiltonian, and Hamilton's equation of motion. For example, consider the simple one-dimensional La- grangIan, In[191]:= Clear[L,x,V] 1 In[192]:= L = -V[x[t]] + - mx' [t] 2; 2 You can easily compute Hamilton's equations of motion: In[193]:= {pRule,hamiltonian,eqMotion} = Bamilton[L, {x}, {px)]; pRule hamiltonian eqMotion Out[193]= {x'[t] -7 pxt] } pX[t]2 +V[x[t]] 2m {px' [t] == -V' [x[t]], x' [t] == pxt] } Out[193]= Out[193]= Note how the three separate expressions returned by Hamilton are exttacted. The first equation is the relation between the generalized coordinate x [t] and the canoni- cal momentum, px [t]. The second expression is the Hamiltonian expressed in terms of canonical variables {x [t] ,px [t]}. The equations of motion follow from the third list. Next, consider a two-dimensional Lagrangian: 
346 Chapter 6 Lagrangians and Hamiltonians In[194]:= L=-V[x[t],y[tJ] +m(x'[t]2+y'[t]2); Bamilton[L, {x,y}, {px,py}] Out[194]= {{x' [t] -7 pxt] ,y' [t] -7 pyt] }, px;:] 2 + PY2[:] 2 +V[x[t], y[t]], {px' [t] == _V(l,O) [x[t], y[t]], py' [t] == _V(O,l) [x[t], y[t]], x' [t] == pxt] ,y' it] == pyt] }} Finally we apply Protect to the user-defined procedure to keep it from being deleted with Clear ["Global' * "] : In[195]:= Protect[Bamilton]; . PROBLEM 1 Harmonic Oscillator. Consider a particle of mass m moving in a har- monic potential, V =  . Find the canonical momentum, Hamiltonian, and Hamilton's equations. Verify that the equations also follow from the user-defined function Hamil- ton. Solve Hamilton's equations. Remarks and Outline Express the Lagrangian in terms of {x [t] , x' [t] }. The canon- ical momentum p follows from taking the derivative of the Lagrangian relative to the vari- able x' [t]. The Hamiltonian is H=p x' -L [x,x']. The equations of motion follow from Hamilton's equations. Solution In[196]:= Clear [nGlobal' * n] The kinetic and potential energies are 1 In[197]:= T= -mx'[t]2; 2 1 V= -kX[t]2; 2 and the Lagrangian follows from In[198]:= L=T-V 1 1 Out[198]= --kx[t]2+- rnx '[t]2 2 2 The momentum conjugate to x [t] is In[199]:= eql = p[t] == D[L, x' [t]] Out[199]= p[t] == rnx' [t] 
6.4 Hamiltonian Problems 347 Solving eql for x' [t], you get In[200]:= xpRule = Solve [eq1, x' [t]] [[1]] Out[200]= {x'[t] -7 p] } Expressing the Hamiltonian in terms of the canonical variables {XI p}, it follows In[201]:= H= (p[t] x'[t] -L)//.xpRule p[t]2 1 Out[201]= -+-kX[t]2 2m 2 Hamilton's equations of motion are In[202]:= eq2 = {p'[t] == -D[H,x[t]], x' [t] == +D[H, p[t]]} Out[202]= {p' [t] == -kx[t], x' [t] == pt] } The user-defined function Hamilton automatically returns eql, H, and eq2: In[203]:= Hamilton[L, {x}, {p}]//ColumnForm {x' [t] -7 pt] } Out[203]= p[t]2 +  kx[t]2 2m 2 {p' [t] == -kx[t], x' [t] == P] } If we assume the initial conditions are In[204]:= initial = {p[O] == pO, x[O] == xO}; then the solution follows from applying DSol ve to eq2: In [205] := dsol = DSolve[eq2-Join-initial, {p[t],x[t]}, t] / /Flatten / /FullSimplify Out [205] = {p (t) -7 pO Cas [ t ] - Vk -vrnxO Sin [ t ] , [ ] pO Sin ( Yk t J x (t) -7 xO Cas t + Vk -vrn YID } 
348 Chapter 6 Lagrangians and Hamiltonians . PROBLEM 2 Nonlinear Oscillator. Consider the nonlinear oscillator described by V - .!L2 _ .! EX 4 . - 2 4 ' a. Find the Lagrangian and apply the user-defined function Hamil tOil to get the Hamiltonian and Hamilton's equations. b. Draw the potential and phase diagrams for k 1 and E 1 / 2. c. Use the user-defined procedure firstDiffSeries to find the power-series so- lution. Find the first-order perturbation solution in the parameter E using the user- defined procedure firstOrderPert. The user-defined command is listed in the next paragraph under Remarks and Outline. Let kl and El/2 and compare the previous results with the numerical solution. In[206]:= Clear[DGlobal' * D] Remarks and Outline The user-defined function firstDiffSeries returns the ex- pansion for the solution of two first order equations in powers of t. In[207]:= firstDiffSeries[eqin., {z_,p_}, initRule_List, order_, t_ It] := Module [ {eq, zSer, pSer, eSer, vars, sol, zpsol}, eq = Table [eqin [[i, 1]] - eqin [ [i, 2]] == 0, {i,2}]; zSer = Series[z[t], {t, 0, order}]; pSer = Series[p[t], {t, 0, order}]; eSer = eq//. ({z[t] -+ zSer,p[t] -+pSer})// ExpandAll; vars = (Table[{D[z[t], {t, j}], D[p[t], {t, j}]}, {j, 1, order + 1}] /.t -+ 0) / / Flatten; sol = Solve [eSer, vars] / /Flatten; zpSol = {zSer, pSer} / / . sol / / . ini tRule; Return [zpSol] For example, consider the harmonic oscillator described by the two coupled, first-order equations: In[20B]:= e q 1={"Jx[t]+P'[t] ==O,p[t] ==x'[t]}; firstDiffSeries[eq1, {x,p}, {x[O] -+xO, p[O] -+pO}, 4, t] //ColumnForm 
6.4 Hamiltonian Problems 349 Out [208] = 1 1 1 xO+pOt-- (xO) t 2 __ (pO) t 3 +-W 4 xOt 4 +0[t]5 2 1 6 1 2f pO -  xO t - - (pO ) t 2 + - w 4 xO t 3 + - pO w 4 t 4 + 0 [t] 5 2 6 24 The command firstDiffSeries returned a time series expansion for x and p. The user-defined command firstOrderPert returns the first-order perturbative cor- rection to the term with coefficient eps In[209]:= firstOrderPert [eq1_, x_, {xO_, vO_}, eps_ :eps, t_ :t] := Module[{xRule,eq2,eqEps,initConO, initCon1,dsol1,dso12}, xRule = {x -+ (x[O] [I] + eps x[l] [I] &:) ); eq2 = eq1 [[1]] - eq1 [[2]] l.xRule; eqEps = CoefficientList [eq2, eps] == 011 Thread; initConO = {x[O] [0] == xO, (x[O])'[O] ==vO}; initCon1 = {x[l] [0] == 0, (x[l])'[O] == OJ; dsol1 = (DSolve [Join [ {eqEps [[1]]}, initConO], {x[O] [t]},t]IIFlatten); dso12 = (DSolve[Join[{eqEps[[2]]},initCon1]11. dsol1, {x[l] [t]}, t] II Flatten) ; Return[x[t]/.xRulell. Join[dsol1,dso12]] For example, applying firstOrderpert to eql, In[210]:= eq1 = x" [t] == _k 2 x[t] + epsx[t]2; we get In[211]:= firstOrderPert[eq1,x, {xO,O},eps,t]11 Simplify II Collect [I, eps] &: Out[211]= xO Cos[kt]- epsxO (2xO Cos[kt] +xO (-3+Cos[2ktJ)) 6 k 2 Solution a. As a second example of Hamilton's equation, consider a nonlinear oscillator. The kinetic and potential energies are 
350 Chapter 6 Lagrangians and Hamiltonians 1 In[212]:= T= -mx'[t]2; 2 1 2 1 4 V=2 kx [t] -4 6X [t]; The Lagrangian follows from In[213]:= L =T-V; The canonical momentum, Hamiltonian, and Hamilton's equations follow from the user- defined function Hamil ton: In[214] := {xpru1e,hami1tanian,etion} = Hamilton [L, {x}, {p}]; {xpru1e,hami1tonian,etion}// Co1umnForm Out[214]= {x' [t] -7 p[t] } 2 m p[t] 1 2 1 4 - + - kx[t] - - EX[t] 2m 2 4 {p' [t] == -kx[t] + EX[t]3, x' [t] == pt] } b. Consider the values In[215]:= values = {k-+ 1, 6-+1/2,m-+1}; The potential graphics and phase diagram follow from In[216] := pt1 = Plot [V / .va1ues/ /Eva1uate, {x[t], -2,2}, Disp1ayFunctian -+ rdentity] ; In[217]:= pt2 = CantourP1ot [ hami1tonian / .va1ues/ /Eva1uate, {x[t], -2, 2}, {p[t],-l,l}, ColorFunction -+ Hue, Contours -+ 15, DisplayFunction -+ rdentity] ; Displaying the results, we get In[218]:= Show[GraphicsArray[{pt2,pt1}]]; o. 01/j .5 0.4 0.3 .2 o 1 -2 -1 1 2 -0. 
6.4 Hamiltonian Problems 351 The phase porttait is on the left and the potential graph is on the right. Particles near the origin with sufficiently small energy are bounded. c. Use the user-defined command firstDiffSeries. Return a time series solution for the equations of motion: In [219] := solt = firstDiffSeries[eqMotion, {x,p}, {x[O] -+xO,p[O] -+O},6]IINormal II Simplify Out[219]= { ----- 72 rn 3 (xO (720 rn 3 - 360 rn 2 t 2 (k - x0 2 E) + 30 rn t 4 (k 2 - 4 kx0 2 E + 3 x0 4 E2) _ t 6 (k 3 _ 25 k 2 x0 2 E + 51 kx0 4 E 2 - 27 x0 6 E3) ) ) , 1 2 - ----- (t xO (k - xO E) 120 rn 2 (120rn 2 -20rnt 2 (k-3x0 2 E)+ t 4 (k 2 -24kx0 2 E+27X0 4 E 2 )))} where we have calculated x [t] and p [t] to order t 6 . The perturbative solution follows from the user-defined function firstOrderpert. To apply f irstOrderpert we express the equations of motion as a second-order dif- ferential equation: In[220]:= eql= (eqMotionllFirst) I. {p' [t] -+ mx" [t]} Out[220]= rnx"[t] ==-kx[t] +EX[t]3 Apply firstOrderPert to eql: In[221]:= sols = firstOrderPert[eql,x, {xO,O},s]11 Collect [I, {xO,s, Cos[x.] }]&:II Short [I, 1]&: 
352 Chapter 6 Lagrangians and Hamiltonians Out[221]= [ 5 Cas ( VI< t J [ ] ym 3-{kt E - 32 k + «5» + Cas ,;m [ 3t Tan (  J Sec 2 (  J 32 -{k,;m «1» +-+ 16 k Sin (  J «1» Sec 2 (  J ) ) 128 k [ -{kt ] x0 3 + Cas ,;m xO The time series and perturbation solution should agree if we keep only the first order terms in E and 6th order in t. Keeping first order in E terms in the time series solution, we get In [222] := test1 = solt [[1]] 1 .eAn-l; n > 1-+ 011 Apart II Collect [I, t]&: ( k3 xO 5 k 2 x0 3 E J Out[222]= xO + t 6 -  + 3 + 120m 144m t4 ( k 2 XO _ kX0 3 E J +t2 ( _ kxO + X0 3 E J 24m 2 6m 2 2m 2m This is to be compared with the time series expansion of the perturbation solution: In [223] := test2 = Series [sole, {t, 0, 6}]IINormal 6 ( k3 xO 5 k 2 x0 3 E J xO + t - - + + 720 m 3 144 m 3 t4 ( k2 xO _ k x0 3 E J + t2 ( _ k xO + x0 3 E J 24 m 2 6 m 2 2 m 2 m Out[223]= As to be expected, they are in agreement. In[224]:= test1 == test2 Out[224]= True To compare with the numerical evaluation of the equation of motion we let In[225]:= values = {xO-+1.2,pO-+0,k-+1,m-+1, e -+ 1/2}; 
6.4 Hamiltonian Problems 353 The numerical solution is In [226] := nsol = NDSOlve[{eqMotion/.values,p[O] == 0, x[O] == 1.2 }, {p[t],x[t]}, {t, 0 , 30 }] / /Flatten; Comparing the series expansion, perturbative solution, and numerical solution, it fol- lows In [227] := Plot[ {sole, solt[ [1]], x[t] }/.nsol/. values //Evaluate, {t,0,30}, PlotStyle -+ {Dashing [{O. 01}], Dashing[{O.OS}], Thickness[O.OOS]}, GridLines .... Automatic] ; 1 1 , , , , " , , , , , -1 The solid curve is the numerical solution, the large dashing curve is the time series expansion, and the short dashing curve is the perturbative solution. The perturbative and time series solution only agree with the numerical solution for small t. . PROBLEM 3 Cylindrical Coordinates. Consider the orbit of a particle with mass m moving in a time-independent potential V [r, (), z] , where {r, (), z} are cylindrical coor- dinates. a. Find the expressions for the canonical momentum, the Hamiltonian, and Hamilton's equations. b. Consider the potential V=- v}+z? and restrict the orbit to the z=o plane. Find the first order differential equations for { r , pr}, where pr is the canonical momentum. c. Derive the time series solution for the equations in Part b. In [228] := Clear [RGlobal' * R] 
354 Chapter 6 Lagrangians and Hamiltonians Remarks and Outline Express the position vector and the kinetic and potential ener- gies in terms of cylindrical coordinates. The momentum relations, the Hamiltonian, and Hamilton's equation follow from the user-defined function Hamilton. The power-series solution of Hamilton's equations follows from the user-defined function firstDiff- Series. In [229] : = firstDiffSeries [eqin_, {z_, p_}, initRule_List, order_, t_ :t] := Module [ {eq, zSer, pSer, eSer, vars, sol, zpsol}, eq = Table [eqin [ [i, 1]] - eqin[ [i, 2]] == 0, {i,2}]; zSer = Series [z [t], {t, 0, order}]; pSer = Series [p [t], {t, 0, order}] ; eSer= eq//.({z[t] ....zSer,p[t] ....pSer})/1 ExpandAll; vars = (Table[{D[z[t], {t, j}], D[p[t], {t, j}]}, {j, 1, order + 1}] /.t .... 0) / / Flatten; sol = Solve [eSer, vars] / /Flatten; zpSol = {zSer, pSer} / / . sol / / . ini tRule; Return [zpSol] Required Packages In[230]:= Needs[RCalculus'VectorAnalysis'R] Solution a. The position vector in cylindrical coordinates is described by the rule In [231] := rRule = rVector .... (Evaluate [CoordinatesToCartesian [ {r [#], e [#], z [I] }, Cylindrical]] &0) Out[231]= rVector-7 ({Cos[e[#1]] r[#1], r[#1] Sin[e[#1]], z [#1] }&) The kinetic and potential energies are In [ 232] : = T = (m rVector' [t] . rVector' [t] ) / / . rRule/ /Sim;plify L = T - v[r [t], e [t], z [t]] / / Sill\Plify 1 Out [232] = - m (r' [t] 2 + z' [t] 2 + r [t] 2 e' [t] 2) 2 
6.4 Hamiltonian Problems 355 Out[232J= -V[r[t],e[t], z[t]]+ 1 - m (r' [t] 2 + Z' [t] 2 + r [t] 2 e' [t] 2 ) 2 The Hamiltonian and Hamilton's equations follow from In[233J:= {pRule,hamiltonian,eqHotion} = Hamilton[L, {r,e,Z}, {pr,pe,pz}]; In[234J:= pRule Out [234J = { r' (t) -7 pr (t) ,e' (t) -7 pe (t) ,Z' (t) -7 pZ (t) } m mr(t)2 m In[235J:= hamiltonian Out[235J= pr{t)2 + PZ{t)2 +V(r{t),e(t),Z(t)) + pe{t)2 2m 2m 2mr(t)2 The first part of the list is the expression for the canonical momentum; the second is the Hamiltonian; the last are the six Hamilton first-order equations. The equations of motion read In [236J := eqHotion//ColumnForm pr' (t) == pe{t)2 _V(l,O,O) (r{t), e{t), z (t)) mr(t) 3 pe' (t) == _V(O,l,O) (r{t), e{t), z (t)) pz' (t) == _V(O,O,l) (r (t), e (t), z (t)) Out[236J= r' (t) == pr(t) e' (t) == p(t) mr(t)2 z' (t) == pz (t) m The first part of the list is the expression for the canonical momentum; the second is the Hamiltonian; the last are the six Hamilton first-order equations. The equations of motion read In [237J := eqHotion//ColumnForm pr'[t] == pe[t]2 _V(l,O,O) [r[t],e[t], z[t]] mrJt]3 pe' [t] == -V( ,1,0) [r [t], e [t], z [t]] pz' [t] == _V(O,O,l) [r[t], e[t], z [t]] Out[237J= r' [t] == pr[t] e' [t] == pt] mr[t]2 z' [t] == pz [t] m b. Let us express the gravitational potential in pure form with the rule 
356 Chapter 6 Lagrangians and Hamiltonians In[238]:= vRule= { v-+ ( - k &: J} ; "' #1 2 + #3 2 v[r[t], e [t], z [t]] / / .vRule Out[238]= k ,j r[t]2 +Z[t]2 and restrict the orbit to the z=O plane In [239] := zRule = {z -+ (0&:), pz -+ (O&:)}; Applying vRule and zRule to Hamilton's equations of motion, you get In[240]:= eql = eqMotion//.vRule/.zRule// PowerExpand; eql / /ColumnForm pr' [t] == pe[t]2 _  mr[t]3 r[t]2 pe' [t] == 0 True Out[240]= pr[t] r'[t] ==- e' [t] == p[t] mr[t] 2 True The z equations are automatically satisfied. Note that pO [t] must be a constant. Setting pO [t] =m h, Hamilton's equations reduce to In [241] := eq2 = eql//.p8-+ (mh&:) { h2 m k Out[241]= pr' [t] ==  - ,True, True, r[t] r[t] , pr [ t ], h } r [t] == -,e [t] == ,True m r[t] The equations of motion for {r, pr} are In[242]:= rEq=eq2[[{1,4}]]; rEq / /Columnl"orm h 2 m k pr'[t] ==--- Out[242]= r[t J 3 r[t]2 , pr[t r [t] ==- m C. The user-defined function firstDiffSeries returns a power-series solution for two first-order equations. Apply firstDiffSeries to the r equations of motion rEq with the initial conditions: In[243]:= initial = {r[O] -+ rO,pr[O] -+ OJ; 
6.4 Hamiltonian Problems 357 The results are In[244]:= pert = firstDiffSeries[rEq, {r,pr},initial, 4, t] II Sill\Plify Out[244]= { (h2 m- krO) t 2 rO + - 2 m r0 3 (3 h 4 m 2 - 5 h 2 k m rO + 2 k 2 r0 2 ) t 4 24 (m 2 r0 7 ) + 5 (h 2 m - k rO) t o [t] , 3 rO (3 h 4 m 2 - 5 h 2 km rO + 2 k 2 r0 2 ) t 3 } + 0 [ t ] 5 6 (mr0 7 ) . PROBLEM 4 Swinging Atwood Machine. Consider the Atwood machine, which con- sists of two weights of mass m and M connected by a light, inextensible cord of length LO. The cord passes over a frictionless pulley. The mass Mis consttained to move in a vertical direction but the mass m can swing in a plane. Let {xl, yl} be the coordinate of mass m and x2 be the coordinate of mass M. The length of the cord is related to the positions of m and M by LO =  x12 + y1 2 + x2 m {y1,x1 } a. Find the Hamiltonian and Hamilton's equations of motion. Express the results in terms of the coordinates {r, O} and their canonical momentum, where xl= r Cos [0] , yl= r Sin [0] . The angle 0 is measured from the downward vertical. b. Numerically solve for the motion and graph the results. Solution In [245] := Clear [DGlobal' * 0] 
358 Chapter 6 Lagrangians and Hamiltonians a. The potential and kinetic energies are In[246]:= T= {Xl'[t],Yl'[t)}. {xl'[t],yl'[t)}+ 2 M "2 x2' [t] 2 ; V = -g m xl [t] - g M x2 [t] ; The polar coordinates for m are In[247]:= change = {xl.... (r [I] COB [8 [I] ] &:) , yl.... (r[#] Sin[8[#]]&:)}; The length of the cord is related to x2 and r by In[248]:= LORule = x2.... (LO - r[#]&:); If we eliminate the x2 coordinate, then the Lagrangian is In [249] := L = T-V/.LORule/.change//Simplify 1 Out[249]= 2" (2gLOM-2g (M-mCoS[e[t]]) r[t]+ (m+M) r' [t]2 +mr[t]2 e' [t]2) The canonical variables, Hamiltonian, and equations of motion follow from the user- defined function Hamilton: In [250] := {xpRule, ham, eQ.Motion} = Hamilton [L, {8, r}, {pe, pr}] / / Sill\Plify; In[251]:= xpRule Out[251]= { e'(t)-> pelt) ,r'(t)-> pr(t) } mr(t)2 m+M In [252] := ham Out[252]= ((m+M) pe(t)2 +mr(t)2 (pr(t)2- 2 g (m + M) (LO M + (m Cos (e (t) ) - M) r (t) ) ) )/ (2m (m+M) r(t)2) In [253] : = eqMotion / /ColumnForm. pe' (t) == -gmr(t) Sin(e(t)) , pe(t)2 gM+pr (t) ==  +gm Cos(e(t)) mr(t) Out[253]= pelt) e'(t) ==- mr(t) 2 r' (t) == pr (t) m+M The first part is the canonical variables (xpRule), the second is the Hamiltonian (ham), and the equations of motion are given by part three (eqMotion). The equations of motion reduce to the "normal" Atwood problem if p8 [t ] -+ 0, () [t ] -+ 0, and r-+xl: 
6.4 Hamiltonian Problems 359 In[254]:= eqMotion/.{p8[t] ....0, 8[t] ....O}/. r.... (xl[#]&:) Out[254]= {pe'[t] ==O,gM+pr'[t] ==gm, , ,pr[t] } e [t] ==O,xl [t] == m+M Or, in terms of the familiar second order equation, it follows xl"[t] == gem - M) m+M b. Let us find the numerical solution for the motion with the parameters In[255]:= values = {m....l,M....1.0S,g....1}; and let the initial conditions be In [256] := initial = {r[O] == 10, pr[O] == 0,8[0] == 7r/12, 1'8[0] == O}; The equations of motion and initial conditions are In [257] := eql = {eqMotion, initial}/.values// Flatten; The numerical solution follows from In [258] := nSol = NDSolve [eql, {r, pr, 8, p8}, {t,0,2S0} ]//Flatten; Define the functions In [259] := {rl[t_], 81[t_], prl[t_], 1'81 [t_] } = {r[t],8[t],pr[t], p8[t]}/.nSol; The plots for r and () are In[260]:= plot[{rl[t], 81[t]}//Evaluate, {t, 0, 2S0}, Plot Style .... {Dashing[{O.Ol}], Thickness [0.008]} ]; 
360 Chapter 6 Lagrangians and Hamiltonians 10 .... ,. /--\ " '\ ,'''-\ , I \ I \ \ I \ " \ ,/ \ 8\ :' \ ,/ \ "", ,/' 6 \ :' \ :' \ \': \,: \ \,' \,' \ I I,' \ / \,' \ ,/ \ :' \ " 'I \ I I I  1 , 4 2 The solid curve is 0 and the top curve is r. Notice that as the cord shortens the frequency of oscillation increases. The rapid oscillation eventually stops the decreasing length and the cord starts to increase. The pattern repeats in a periodic fashion. The graphics for the motion of m follow from In[261]:= ParametricPlot[ {rl[t] Sin[81[t]],-rl[t] COS[81[t]]}// Evaluate, {t, 0, 80}]; 1 2 Finally, the phase ttajectories {O, pO} and {r, pr} are In [262] := ptl = ParametricPlot[#//Evaluate, {t,0,250}, Ticks.... False, DisplayFunction .... :Identity ] &: /@ {{ rl [t] , prl [t] }, { 81 [t] , p81 [t] }}; In[263]:= Show[GraphicsArray[ptl]]; The graph on the left is {rl [t] ,prl [t]} and the right is {Ol [t] ,pOl [t]} 
6.4 Hamiltonian Problems 361 . PROBLEM 5 Spherical Pendulum. Consider a pendulum of mass m suspended by a rigid, weightless rod. The motion is not restricted to a plane. Use the spherical angular coordinates {O, l/J land their conjugate variables {pO, pl/J} to describe the motion. a. Use the user-defined function Hamiltonian and find the canonical momentum, Hamiltonian, and Hamilton's equations of motion. Eliminate the l/J variable and re- duce Hamilton's equations to a nonlinear equation for O. Restrict the pendulum mo- tion to a plane and show that the solution reduces to the standard pendulum equation. b. Assume g=1, m=1, LO=1, and find a typical numerical solution. Required Packages In[2641:= Needs[nGraphics'Shapes'R] Solution In [2651: = Clear [RGlobal' * n] a. The kinetic and potential energies for a spherical pendulum are 1 In [2661: = T = - m (x' [t] 2 + y' [t] 2 + z' [t] 2) ; 2 V=mgz[t] ; The Cartesian coordinates are related to spherical coordinates by In [2671: = change = {x.... (LO Cos [,p[I]] Sin[ e[l] ]&:), Y .... (LO Sin [,p [I]] sin [ e [I]] &:), z .... (LO Cos [e [I]] &:) }; Instead of 0 we can express the equations in terms of an angle defined relative to the downward vertical 1ft: In[2681:= ule= e.... (7r-[I]&:); The Lagrangian is In [2691: = L = T - V / . change/ .ule/ / Si1l\Plify 1 Out[2691= 2LOm(2gCoS[Ijr[t]]+ LO Sin [Ijr [t] ] 2 rt/ [t] 2 + LO Ijr' [t] 2) Applying the user-defined function Hamilton to L, you get In[2701:= eql = {prule, ham, eQ,Motion} = Hamilton[L, N, ,p}, {p, p,p}, t]; 
362 Chapter 6 Lagrangians and Hamiltonians In [271] := prule Out[271]= { if/ (t) -7 pljr(t) , rt/ (t) -7 Csc 2 (Ijr(t)) Pr/J(t) } L0 2 m L0 2 m In [272] := ham Out[272]= Csc 2 (Ijr(t))pr/J(t)2 + pljr(t)2 _ LOmCos ( ''' ( t )) 2 L0 2 m 2 L0 2 m g '" In[273]:= eqMotion //ColumnFor.m pljr'(t) == Cot(ljr(t)) Csc 2 (Ijr(t)) pr/J(t) 2 -gLOmSin(ljr(t)) L0 2 m Pr/J' (t) == 0 Out[273]=, pljr(t) Ijr (t) == L02 m r/J' (t) == Csc 2 (Ijr (t)) Pr/J (t) L0 2 m The first part of eql (prule) are the canonical momenta, the second part (ham) is the Hamiltonian, and the equations of motion follow from the third part (eqMotion). Consider the equations of motion In[274]:= eqMotion//ColumnFOr.m pljr'[t] == Cot[ljr[t]] csc[ljr[t]]2 p r/J[t]2 -gLOmSin[ljr[t]] L0 2 m Pr/J' [t] == 0 Out[274]=, pljr[t] Ijr[t]==- L0 2 m r/J'[t] == csc[ljr[t]]2 pr/J[t] L0 2 m and notice that the solution for pl/J is a constant: In[275]:= pl/lRule= {pl/l.... (mhrc)}; Eliminating pl/J [t] from the equations, it follows In[276]:= eqMotion/.pI/lRule//ColumnFor.m h 2 mCot[ljr[t]]Csc[ljr[t]]2 . [ [ ] pljr'[t]== 2 -gLOmSmljrt] LO True Out[276]= Ijr' [t] == pljr[t] L0 2 m r/J' [t] == hCsc [Ijr}t]] 2 LO The equations of motion have been reduced to three first order differential equations for the variables ptft [t], l/J [t], and l/J I [t]. In the absence of l/J motion (h=O) the equations of motion reduce to the following first order equations: In [277] : = eqMotion /. pI/lRule/.h.... 0/ /ExpandA1l / / Flatten 
6.4 Hamiltonian Problems 363 Out[277]= {PI/r' [t) == -gLOm Sin[l/r[t)), True, 1/1 [t) == PI/rt) ,rj/ [t) == O } LO m The equivalent second order equation is In[278]:= Solve[{eotion[[l]], D[eqMotion[[3]],t]} ,I/f'[t]] I. Rule -+ Equal I . pt/lRule/.h -+ 011 ExpandAll II Flatten Out[278]= {I/I' [t) == _ g Sin:[t)) } This is the well-known planar pendulum equation. b. Let us consider the numerical solutions of Hamilton's equations In[279]:= eotion { , Cot[l/r[t))Csc[l/r[t))2 p </>[t)2 pi/r [t) == L02 m gLOm Sin[l/r[t)), P</>' [t) == 0, 1/1 [t) == PI/r[t) , </>' [t) == Csc [I/r[t)) 2 P</> [t) } L0 2 m L0 2 m Out[279]= Choose the parameters In [280] := values = {LO -+ 1, g-+ 1,m-+ 1}; and let the initial conditions be In[281]:= initial = {t/I[O] == O,pt/l[O] == 0.1, I/r[0] == 1£/2, pl/r[O] == O}; The numerical solution is In[282]:= nSol = NDSolve[ {eqMotion,initial}/.valuesll Flatten, {I/r,t/I,pl/r,pt/l}, {t, 0, 25}] II Flatten ; Define the functions In[283]:= {l/rl[t_] ,t/ll[t_]} = {I/r[t], t/I[t] }/.nSol; The graphics for the motion follow from 
364 Chapter 6 Lagrangians and Hamiltonians In [284] := ptl = parametricPlot3D[ {x[t], y[t], z [t], Thickness [0.01] } I. change I .r/fRulel .values/.I/1 -+ 1/11/. t[J -+ t[Jl II Evaluate, {t, 0, 25}, DisplayFunction -+ Identity ] ; To \his motion we add the surface of a sphere found in the add-on package In[285]:= Needs[RGraphics'Shapes'R] The graphics for a sphere are In[286]:= sphere = Graphics3D[Sphere [0.96]] Displaying the results, it follows In[287]:= ptl = Show [ sphere, ptl, Boxed -+ False, Shading -+ False, ViewPoint -+ {1, 1, O}] ; We can also display the results against a ttansparent sphere: In[288]:= Show[ ptl/. Polygon [x..] -+ {Hue [0.8] , Line [x] }, ViewPoint -+ {1, 0, 1/2}]; . 
6.5 Hamilton-Jacobi Problems 365 6.5 . HAMilTON-JACOBI PROBLEMS 6.5.1 . Overview The Hamilton-Jacobi technique seeks a ttansformation to a new set of canonical variables {Q, P}, where the new Hamiltonian is zero. These new canonical variables {Q, P} will be constants, and the problem is reduced to solving algebraic equations. If {q, p] are the old canonical coordinates and {Q, P} are the new coordinates, the ttansformation between the coordinates is given by Q = Q[q, p, t] and P = P[q, p, t]. The ttansformation is said to be canonical if there exists a new Hamiltonian K[P, Q], where the new coordinates obey Hamilton's equations: , aK Q = ap , aK P =-- aQ Canonical ttansformations can be obtained from generating functions. In particular, gen- erating functions of the form S[q, P, t] are considered for the Hamilton-Jacobi technique. The ttansformation between the variables {q, p} and {Q, P} follows from derivatives of the generating function: as[q, P, t] p= aq Q = as[q, P, t] ap Solve the first set of equations to get P[q, p, t]. The remaining equations give the expres- sion for Q[q, p, t]. Next, search for a canonical ttansformation whereby the new Hamilto- nian K is zero; this will render the equations of motion for {P, Q} trivial. The new and old Hamiltonians are related by K - H( ) as[q,p,t] - q, p, t + at If K is zero, then it follows from Hamilton's equations, aK = Q' = 0 ap _ aK = P' = 0 aQ that the new variables Q and P are constants. The consttaint K = 0 implies the generating function S satisfies as[q, P, t] H(q, p, t) + at = o. Replacing p in this equation with iiS[Z:,t] you get the Hamilton-Jacobi equation H ( as[q, P, t] ) as[q, P, t] = 0 q, aq , t + at The generating function for the Hamilton-Jacobi variables is called Hamilton's principal function. 
366 Chapter 6 Lagrangians and Hamiltonians The Hamilton-Jacobi equation is a partial differential equation for the generating func- tion S[q, P, t]. It contains n+ 1 variables, one time variable and nqi variables. A complete so- lution of the partial differential equation involves n+ 1 independent constants of integration. One of the n + 1 constants is just a trivial additive constant and can be set equal to zero. The remaining n constants of integration {ai' ..., an} are taken to be the new canonical momen- tum P. The problem of finding Hamilton's principal function, S[q, P, t], is simplified if the Hamilton-Jacobi equation is separable. That is, S[q, P, t] = WI[qd + W 2 [q2]'" + Wn[qn] -at. The W's are called Hamilton's characteristic functions. The Hamilton-Jacobi equation is reduced to a set of ordinary differential equations, one for each W. The solution for W can then be integrated. In the separable case, the problem is reduced to a set of integrals. The ttansformations between the old coordinates {q, p} and the new ones {Q, P} follow from 8S[q, P, t] p= 8q Q = 8S[q, P, t] 8p The coordinate q is solved by inverting the second equation to give q = q[Q, a, t]. You will need to compute the Hamilton-Jacobi equations of motion. Define the Hamil- tonJacobi function to compute this systematically: In [289] := Clear [nGlobal , * n] In [290] : = BamiltonJacobi [L_, xList..List, pList...List, wList.List, a_, t_ : t] : = MOdule[{xx,vv,pp,sol,ham,ww, hamPrincFunc,pHewRule,BJeq}, xx = Map[#[t]&:, xList]; vv = Map [I' [t] &:, xList]; pp = Map [# [t] &:, pList] ; sol = Solve [ (D [L, #] &:/@vv) == pp, vv] I I Flatten; ham = (pp.vv - L) I I .soll I Sill\Plify I I Expand; ww = Map [# [t] &:, wList, {2}] ; hamPrincFunc = (PlusNww) - at; pHewRule = {pp -+ (D[hamPrincFunc, #] &:/@xx) I I Thread} II Flatten; BJeq = (haml I .pNewRule) - a == 0; Return [{sol, hamPrincFunc, BJeq}] HamiltonJacobi returns the expression for the canonical momentum, Hamilton's Principal Function, and the Hamilton-Jacobi equation. The procedure assumes that Hamil- ton's Principal Function can be expressed in the form W [q] -a t. For example, consider a system described by the Lagrangian: 
6.5 Hamilton-Jacobi Problems 367 1 In[291J:= L= +-mx'[t]2 -V[x[t]]; 2 {pRule,hamPrinCFunc,eqRamJac} = HamiltonJacobi [L, {x}, {p}, {W[x]}, a]; In[292J:= pRule Out[292J= {x' (t) -7 P) } In[293J:= hamPrincFunc Out[293J= W(x(t)) - a t In [294J := eqRamJac //ColumnForm W'(X(t))2 -a+V(x(t)) Out [294J = 2 m o Note how the separate parts returned by HamiltonJacobi are exttacted. Finally, consider the second example, In [295 J : = L = +  m (x' [t] 2 + y' [t] 2) - V [x [t] , Y [t]] ; HamdltonJacobi[L, {x,y}, {px,py}, {Wl [x] , W2 [y] }, a] Out[295J= {{x'[t] -7 pxt] ,y'[t] -7 pyt] }, -at+Wl[x[t]] +W2[y[t]], -a + V[x[t], y[t]] + Wl'[x[t]]2 + W2'[y[t]]2 ==o } 2m 2m We apply Protect to the user-defined procedure to keep it from being deleted with Clear [ "Global' *"] : In[296J:= Protect[HamdltonJacobi]; . PROBLEM 1 Harmonic Oscillator. Consider a one-dimensional harmonic oscillator. a. Express the Hamiltonian in canonical variables and derive the Hamilton-Jacobi equa- tion for W using the user-defined function Hamilton. b. Solve the Hamilton-Jacobi equation forWto obtain the oscillator solution for {x,p}. Solution In [297J := Clear ["Global' *"] a. The kinetic and potential energies for a harmonic oscillator are 
368 Chapter 6 Lagrangians and Hamiltonians 1 In[298]:= '1'= -mx'[t]2; 2 1 2 V = "2 kx[t] ; L='1'-V 1 1 Out[298]= --kX[t]2 + -mx'[t]2 2 2 The Hamiltonian follows from In [299] := {xpRule, ham, eqMotion} = Hamilton[L, {x}, {p}]//.{x_[t] -+x}; In[300]:= xpRule Out[300]= {x' -7} In[301]:= ham p2 kx2 Out[301]= - +- 2m 2 In[302]:= eotion Out[302]= {p' == -kx, x' ==} where {x,p} are the canonical coordinates. The momentum p and Hamilton's principal function S [x, t] are related by p= as[:,t] : In[303]:= pRule = {p -+D[S[x, t], x]}; The Hamilton-Jacobi equation follows: In[304]:= eqRJ= (ham+D[S[x,t],t]) ==O//.pRule kx 2 S(l,O) [x t]2 Out[304]= _+S(O,l)[x,t]+ ' ==0 2 2m Assume the solution for S is of the form In[305]:= sRule= {S-+ (W[#1] -P#26i:}}; where the new canonical momentum p is a constant. Substitute S into eqBJ to get an equation forW' [x]: In[306]:= eqW = eqRJ/ / .sRule kx 2 W' [x] 2 Out[306]= -p + - + - == 0 2 2m b. Solving eqW for W' [x] , you get 
6.5 Hamilton-Jacobi Problems 369 In[307J:= dWRule = Solve [eqW, W' [x]] [[2]] Out[307]= {W'[x] -->-{2,;m p- k;2 } where we have chosen the positive root here. Integrate dWRule to get an expression for W [x] : In[308J:= wRule = W[x] -+ -V2mP Integrate [ -Vl-X 2 ,A ,X]/. ,A-+ 2P Out[308J= W[x] -->-{2.y;;p [  x  1 _ k x 2 + ArcSin [ *] ] 2 2P Y2 In general, we are interested in the derivative of W with respect to P. The new canonical position coordinate Q (constant) follows from taking the derivative of S with respect to P, Q = B S[x,P,t] . BP . In[309J:= eql = Q == D[S[X, t]/.sRule/.wRule, p]//Simplify  ..jffiP ArcSin [ "1 X ] Out[309J= Q+t== ...[i k You can solve eql for x: In [310 J : = xSol = Solve [eql, x] / /Sill\Plify / /powerExpand/ /Sill\Plify / /Flatten Y2 ...fP Sin [ Yk (Q+t) ] Out[310J= {x--> ..jk...;m } The expression for the canonical momentum p follows from xpRule: In[311J:= eq2 = xpRule/ .Rule -+ Equal/ / Solve [I, p] Ii: / / Flatten Out[311J= {p-->mx'} and xsol In[312J:= eq2/.x'-+D[x/.xSol,t] { .r.:: [ ..jk(Q+t) ]} Out [312J = p --> '12 ,;m --IP Cos ...;m 
370 Chapter 6 Lagrangians and Hamiltonians . PROBLEM 2 Particle in a Constant Gravity Field. Consider the motion of a projectile in a constant gravitational field. Assume the motion is in the {x, z} plane. a. Express the Hamiltonian in canonical variables and derive the Hamilton-Jacobi equa- tion for W using the user-defined function Hamilton. b. Solve forWto obtain the solution {x,p}. Solution In[3131:= Clear[nGlobal' * n] a. The kinetic and potential energies and Lagrangian for a particle in the field are In[3141:= 'l' =  m (x' [t]2 + z' [t]2); v=gmz[t]; L='l'-V 1 Out[3141= -gmz[t] +_m(x'[t]2+ z '[t]2} . 2 The Hamilton-Jacobi equations follow from the user-defined function HamiltonJa- cobi In[3151:= {prule, S, Chareq} = Hamil tonJacobi [L, {x, z}, {px, pz}, {WX[x] ,Wz[z]},p]//ExpandAll Out[3151= {{x' [t] -7 pxt] ,z' [t] -7 pzt] }, -Pt+Wx[x[t]] +Wz[z[t]], Wx' [x[t]] 2 Wz' [z [t]] 2 == O } -p+gmz[t] + 2m + 2m where p is a constant and is identified with one of the new momentum variables. The last equation in the list is the equation for the characteristic function. This equation can be separated into an equation for x [1] and x [2] In[3161:= eq1a= Chareq[[l, {1,2,4}]] ==A/.z[t]..z eq1b = Chareq[ [1, 3]] == -A / .x[t] .. x Wz' [z]2 Out[3161= -p+gmz+==A Wx' [x]2 Out[3161=  ==-A where A is the separation constant and can be identified with the other constant momentum variables. 
6.5 Hamilton-Jacobi Problems 371 b. The solutions for Wx and Wz are In[31? J:= wxsol = DSolve[eqla, Wz [z], z] [[2]] Wzsol = DSolve[eqlb, WX[x], x] [[2]] Out[31?J= { wz[Z]....-12 ( _ 2 (A+P) +  ) 3gm 3 -J Am + m P - g m 2 z + C [ 1] } Out[31?J= {WX[X] ....i-l2v'Av'rnX+C[l]} Without loss of generality we can take the positive solutions for Wx and Wz. The ex- pression for S becomes In [318J : = Ssol = -p t + WX[x] + Wz [z] I. WXsoll .Wzsol Out[318J= -Pt+i-l2v'A-vrnx+-12 ( 2 (A + P) 2 Z ) I - + - \I A m + m P - g m 2 z + 2 C [ 1 ] 3gm 3 The expressions for the two new coordinates Q [i] follow from taking the derivatives of Ss01 relative to p and A, In[319J:= Qeq = {Qx, Qz} == (D[Ssol, #]6i:/@{A, p}lll!'latten) II Thread I I Simplify im 3 / 2 x 2ym(A+P-gmz) { - VA + g Out[319J= Qx+ -fim -fi y m(A+P-gmz) } Qz + t + == 0 gm == 0, The Qx and Qz are constants. We get the solution for the motion if we solve Qeq for {XIZ}, In [320J := Sol = Solve [Qeq, {x, z}] I. {x -+ x[t], z -+ Z [t]}/. Rule -+ Equal I I Flatten Out[320J= { 1 ( 2A 2P 2 2 ) z [t] = = - - + - - g Qz - 2 g Qz t - g t , 2 gm gm x[t] == i (-fi.,fA Qx - -fi .,fA Qz - -fi .,fA t) } v'rn The expression can be simplified if we replace {Qx , Qz I A, p} with the initial condi- tions {x [0] I Z [0] I x' [0] I Z I [0] }. Expressing {XI z} in terms of these initial condi- tions, we get the familiar expression 
372 Chapter 6 Lagrangians and Hamiltonians In[3211:= Solve[ {Sol, (Sol/.t -+ 0), (D [Sol, t] I.t -+ 0) }lll!'latten, {x[t], z[t]}, {A, P, Qx, Qz}]lll!'lattenll ExpandAll Out[3211= {X[t] ->x[O] +tx'[O], gt 2 } z[t] ->-T+z[O] +tz'[O] . PROBLEM 3 Kepler's Problem and Hamilton-Jacobi Equations. Consider a bound particle moving in a Keplerian potential. Use cylindrical coordinates {r ,0, z} and restrict the motion to the z=O plane. Denote the momentum variables conjugate to {r,O} with {pr ,pO}, respectively. Let S [t, r, 0] be Hamilton's principal function, and Wr [r] and Wo [0] be the Hamilton characteristic functions. a. Derive expressions for Hamilton's characteristic functions, Wr [r] and wO [0] . b. Solve for the elliptical orbits using Hamilton's principal function S [t, r, 0] . Show that the expression for r can be written as r = 1:1:] . Remarks and Outline Express the position vector in cylindrical coordinates using the command CoordinatesToCartesian found in the package Calculus 'Vector- Analysis'. Find the expression for the kinetic and potential energies. The Hamilton- Jacobi equation follows from the user-defined function HamiltonJacobi. Due to the lack of 0 dependence in the Hamilton-Jacobi equation, it follows that We'[O] can be set equal to a constant. Required Package In[3221:= Needs[nCalculus'VectorAnalysis,n] Solution In [3231 := Clear [nGlobal' * n] a. Use cylindrical coordinates and restrict the motion to the z=O plane. You need to load the package: In[3241:= Needs[nCalculus'VectorAnalysis,n] The position vector in cylindrical coordinates, called rvector, is In [3251 := rRule = rvector -+ (Evaluate [CoordinatesToCartesian [ {r [#], e [#], z [#]}, Cylindrical] ] 6i:) 
6.5 Hamilton-Jacobi Problems 373 Out [325] = rvector.... ({Cas [e [#1] ] r [#1], r [#1] Sin [e [#1] ] , z [#1] }&) The kinetic and potential energies for the particle moving in the z=O plane are In [326] : = T =  rvector' [t] .rvector' [t] / / .rRule / /. 2 {z' [t] -+ O} / /Sill\Plify; k V=- r[t] ; The Lagrangian is In [3271 := L = T-V k 1 Out[3271= - + - m (r' [t]2 + r[t]2 e' [t]2) r[t] 2 The Hamilton-Jacobi equation follows from the user-defined function Bami1tonJa- cobi. In[328]:= {momRule,hamPF,eqMOtion} = HamiltonJacobi [L, {r, e}, {pr, pe}, {wr [r] , we [e] }, En] ; {momRule,hamPF,eqMOtion}//ColumnForm { r'[t] .... pr[t] ,e'[t].... pelt] } m mr[t] 2 Out[328]= -En t +Wr[r[t]] + We[e[t]] k Wr' [r [ t] ] 2 we' [e [ t] ] 2 -En - - + + == 0 r[t] 2m 2mr[t]2 The first row are the relations between the conjugate momentum variables {pr, pB} and {r' , e'}. The second row is S [t, r, e], Hamilton's principal function, and Wr [r], and We[e] are the Hamilton characteristic functions. The last equation is the Hamilton-Jacobi equation. Due to the lack of e dependence in the Hamilton-Jacobi equation, it follows that we' [8] can be set equal to a constant. Set we' [8] =e1 and solve for we [8] : In [329] := wElrule = DSolve[{We'[e] == +el,We[O] == O}, {we},e] [[1]] Out [329] = {we.... Function [{e}, el e] } The equation forWr' [r] becomes In[330]:= eql = (eqMOtion//.wElrule// Solve [I, wr' [r [t]]] [[1]] &:) /. r[t] -+ r //powerExpand 
374 Chapter 6 Lagrangians and Hamiltonians { Y -e1 2 + 2 k m r + 2 En m r 2 } Out[330]= Wr' [r] ->- r The expression for the Q coordinate follows from taking the derivative of S relative to e1: _ as[r, el, t] _ e aWr[r, el, t] Q - Bel - + Bel where Wr [r, e1, t] follows from integrating eq1. However, it is more convenient to take the derivative first and then integrate. It follows that aWrtl,t] , In[331];= eq2=D[eq1[[1,2]],el] el Out[331]= r Y -e1 2 +2kmr+2Enmr 2 Integrating eq2 we get the desired relation In[332] ;= eq3 = Integrate [ 1 , r ] / . r '" -1 + a r + b r 2 { 2km 2Enm } a -+ el 2 ' b -+  Out[332]= ArcTan [ 2 _2+ 2kmr e1 2 -1 + 2 kmr + 2 Enrnr 2 e1 2 e1 2 The equation for Q is In[333];= Qeq = Q == e + eq3 Out[333]= Q == e + ArcTan [ 2 -2 + 2kmr e1 2 -1 + 2 kmr + 2 Enrnr 2 e1 2 e1 2 b. To get an expression for r we must invert Qeq. However, it is more convenient to work with the variable u=l/r, 1 In[334];= ueq = Qeq/.r -+- U 2 + 2 km Out[334]= Q==e+ArcTan [ -  ] 2 -) -1 + 2Enm + 2km e1 2 u 2 e1 2 u Inverting this equation for u, we find In [335] ;= usol = u/.Solve[ueq,u] [[2]] /.{Q-+7r/2 }// Si mplify//powe rExpand//Simplify km +.ym Y 2 e1 2 En + k 2 m Cas [e] Out[335]= e1 2 The solution for u can be expressed in the canonical form 
6.6 Exercises 375 u= 1 + ecos[lft] a(1 - e 2 ) Equate u to its canonical form: 1 + e Cos [8] In [336] := eq4 = usol == a (1_e 2 ) km+ .ymY2 e1 2 En + k 2 m Cas [e] Out[336]= e1 2 l+eCas[e] a (1 - e 2 ) You can obtain two independent equations from eq4 by choosing two values for COB [8 [t] ] : In [337]:= eq5 = eq4/ . {8 -+ {O, 1£/2 }} / /Thread { km+.ym Y 2e1 2 En+k 2 m__ l+e Out[337]= e1 2 -- a (1 - e 2 ) , km l } e1 2 == a (1_e 2 ) The values for e and a follow from In[338]:= Solve [eq5, a, e] {{ Y2e12En+k2m k }} Out[338]= e-> k-{m ,a->- 2En . 6.6 . EXERCISES The solutions to many of these exercises can be found on our web sites. 6.1 Atwood Machine In the problem section the Atwood machine was solved using Lagrange Multipliers. Solve this same problem using independent coordinates. The Atwood machine consists of two weights with masses ml and m2 connected by a light, inextensible cord of length Len. The cord passes over a frictionless pulley. Let xl be the coordinate of mass ml and let x2 be the coordinate of mass m2. The coordinates xl and x2 are the vertical distances from the pulley to the masses. Assume the masses move only in a vertical direction. Express the Lagrangian in tenns of only xl. Find the equations of motion and solve. 6.2 Double Atwood machine A string of length LI passes over a fixed light pulley supporting a mass m l on one end and a pulley of mass  on the other. Over this second pulley passes a string of length L 2 that supports a mass m, on one end and m 4 on the other. (a) Write the Lagrangian and derive the equations of motion. 
376 Chapter 6 Lagrangians and Hamiltonians (b) Solve for the motion. (c) Animate the solution. 6.3 Spherical Pendulum Consider a pendulum of mass m suspended by a rigid, weightless rod. The motion is not restricted to a plane. Use the spherical angular coordinates {O, tfI} to describe the motion. (a) Write the Lagrangian and find the equations of motion. (b) Find a numerical solution and plot the results. 6.4 Double Pendulum Consider a double pendulum consisting of a massless rigid rod. The first segment of the rod has one end fixed and the other supporting a particle of mass m1. The length of this segment is L1. Attached to ml is another segment of length L2. At the other end of the second segment is a another particle of mass m2. Do not assume the motion is confined to a plane. (a) Write the Lagrangian and find the equations of motion. (b) Find a numerical solution and plot the results. 6.5 Spring Pendulum A spring pendulum has a mass m suspended by an elastic spring of stiffness k and force-free length LO. Do not confine the motion to a plane. (a) Write the Lagrangian and find the equations of motion. (b) Find a numerical solution with initial conditions so the mass does not loop over the top. Plot the solution. (c) Find a second numerical solution where the pendulum is given sufficient initial angular mo- tion to rotate over the top. Plot the solution. 6.6 Hamilton-Jacobi in Parabolic Coordinates A particle of mass m is moving in a force whose potential is v=A/r-B z. This produces a force that is a combination of a unifonn force in the z-direction and an inverse square central force. (a) Derive the Hamilton-Jacobi equation in parabolic coordinates. (b) Solve the equations and discuss the solution. 6.7 How Hamilton Works Explain the details in the steps found in the user-defined function Hamilton. 6.8 How HamiltonJacobi Works Explain the details in the steps found in the user-defined function HamiltonJacobi. 6.9 How firstDiffSeries Works Explain the details in the steps found in the user-defined function firstDiffSeries. 6.10 How firstOrderPert Works Explain the details in the steps found in the user-defined function firstOrderPert. 
CHAPTER 7 Orbiting Bodies 7.1 . INTRODUCTION Two bodies interacting by their mutually atttactive force is a classical problem that dates back to Isaac Newton in 1687. Newton solved the problem for two spherical objects moving under their mutual gravitational atttaction. In 1710 Johann Bernoulli proved that the motion of one particle with respect to the other is described by a conic section: ellipse, parabola, or hyperbola. Euler in 1744 elaborated on the details of the two-body problem. The two-body problem can be reduced to a one-body potential problem. An obvious extension of two bodies is the three-body problem. The motion of three bodies due to their mutual gravitational atttaction was first studied by Euler in 1776 and shortly after by Lagrange in 1788. The problem can be simply stated: Consider three par- ticles that move under their mutual gravitational atttaction, then, given their initial condi- tions, determine their subsequent motion. The three-body problem is often referred to as the most celebrated of all dynamical problems. One of the reasons that it is so appealing is because of its deceiving simplicity. However, the system of differential equations cannot be reduced to quadratures, and hence the problem is not solvable. Numerical solutions are not sufficient to determine the long-time behavior of the motion. The three-body problem simplifies if the lightest of the bodies is assumed to have no effect on the motion of the other two bodies (called primaries). The (circular) restricted three-body problem tteats the motion of an infinitesimal particle due to the gravitational atttaction of two massive primaries moving in circular orbits about one another. The re- stricted three-body equations take on a very simple form in a frame centered on the center of mass but rotating at rate w. Applications of the restricted three-body problem include the motion of a spacecraft in the Earth-Moon system, an asteroid motion governed by the gravitational atttaction of the Sun and Jupiter, and the motion of the Earth in the field of the Sun and Jupiter. Another important application is the motion of small bodies about binary stars. At least half of all stars in the sky are multiple systems, consisting of two or more stars in orbit about their common center of mass. This chapter is divided into two problem sections: 7.2 the Two-Body Problem, and 7.3 the Restricted Three-Body Problem. Exercises are included in section 7.4. Before starting the problems you might find it convenient to turn off the spell checker: In[l]:= Off [General :: "spell n ]; off [General:: "spelll n ]; 377 
378 Chapter 7 Orbiting Bodies 7.2 . THE TWO-BODY PROBLEM 7.2.1 . Overview The two-body problem can be simplified if the center of mass position and relative coordi- nates are chosen to describe the motion. If -; j and -;2 are the position vectors to particle one and particle two then the center of mass vector R and the relative vector -; are R = r j m j + r 2 m 2 m j + m 2 r = r j - r 2' The motion of the center of mass point R moves as a force-free point and can be neglected. The solution for the relative vector -; reduces to a one-body potential problem. . PROBLEM 1 Equivalent One-Body Problem. Consider two mass points m j and m 2 , where the interaction is given by a centtal force expressible by a potential V. V is only a function of the relative separation -; = -; j - -;2' where -; j and -;  are the position vectors to particle one and particle two. Define the center of mass vector R and the relative vector -; by R = r j m j + r 2 m 2 m j + m 2 r = r j - r 2' r1 a. Express the relative position vector -; in terms of spherical coordinates {rO, B, 1ft} and derive the equations of motion. b. Place the orbit in the B=7r /2 plane and derive expressions for the conservation of angular momentum and energy. c. Let u=  and show the equation for u [1ft] is 
7.2 The Two-Body Problem 379 u"[Ift] = mf [ 1 ] u[tP] _ U[Ift] h 2 u[Ift]2 where h is the conserved angular momentum and v' [r] =-f [r]. Remarks and Outline Write the Lagrangian in terms of C;, R} and then express the vec- tor -; in terms of spherical coordinates. The equations of motion follow from applying the command EulerEquations to the Lagrangian, which is found in the add-on package Calculus 'VariationalMethods'. In the e = I plane, the equations simplify and the 1ft" [t] equation can be integrated to get the conserved angular momentum. Like- wise, the r' , [t] equation can be integrated to get the energy expression. The conserved quantities also follow from the add-on command FirstIntegrals. We also require a relation between Cartesian coordinates and spherical coordinates that is found in the add- on package, Calculus 'vectorAnalysis'. Solution In[2]:= Clear ["Global ' * "] a. It is convenient to express the equations in terms of the total mass MO= (m 1 +m 2 ) and the reduced mass J1= m] m 2 : m 1 +m 2 In[3]:= eql = {NO ==ml +m2, j.I == m= }; An expression for m 1 and  in terms of MO and J1 follows from eql: In [4] : = mBol = Solve [eql, {ml, m2}] [[1] ] Ou t [ 4] = {ml -7  (MO - VMO yMO - 4 f..l ) , m2 -7  (MO + VMO yMO - 4 f..l )} The next step is to express the position vectors, r 1 and -;2' in terms of the relative position vector -; and center of mass position vector R. The center of mass and relative vectors are defined by { m1 rl[t] +m2 r2[t] In[5]:= eq2 = R[t] == , NO r[t] == rl It] - r2 [t]}; where R, rl, r2, and r are vectors. The inverse relations follow from In [6] := Boll = «Solve [eq2, {rl [t], r2 It] }] [ [1]] / /. Rule -+ Equal/ /. {NO -+ ml + m2}) / / MapAll[Apart,#]&) 
380 Chapter 7 Orbiting Bodies Out[6]= { m2r[t] d[t] == - +R[t], ml+m2 mlr[t] } r2 [t] == -- + R[t] ml +m2 It is more convenient to express these equations as rules and in their pure form: { ( m2r[#1] ) In[7]:= rSol= rl-+ +R[#l]&: , ml + m2 ( mlr[#1] ) } r2-+ - +R[#l]&: ; ml + m2 The kinetic energy is 1 1 In[8]:= T = -mlrl' [t]2 + -m2r2' [t]2; 2 2 where rl and r2 are the position vectors for the two particles. The Lagrangian follows from In [9]:= La = T - v[rO [t]] / .rSol/ .mBol/ /Sill\Plify 1 Ou t [ 9 ] = - (- 2 V [rO [t] ] + 11 r' [t] 2 + MO R' [t] 2 ) 2 where rSol and DlSol have been used to express the results in terms of vectors -; and R and masses MO, and fl. The ttansformation of the position vector -; from Cartesian coordinates to spherical co- ordinates follows from the command CoordinatesToCartesian found in the pack- age In[lO]:= Needs[RCalculus'VectorADalysis' R ] Express the relative position vector -; ={ rO [t] ,8 [t] ,1ft [t]} in terms of spherical coordinates with rRule: In[ll]:= rRule = r-+ «CoordinatesToCartesian[ {rO [#],8[#],4> [I] }, Spherical] / / Evaluate)&:) Out[ll]= r.... ({Cas[<P[#1]] rO[#1] Sin[e[#1]], rO [#1] Sin[e[#1]] Sin[<p[#1]], Cas [e[#1]] rO [#1] }&) ->. Use Cartesian coordinates to express R in terms of its components {Rx, Ry, RZ}: In[12]:= RRule= {R-+ ({Rx[#],Ry[#],RZ[#]}&:)}; 
7.2 The Two-Body Problem 381 Identify r and R as vectors: In [13] := r/: VectorQ[r] = True; R/: VectorQ[R] = True; and replace the notation for the square of a vector with the dot product. A rule to ttansform the square of a vector to its vector product is In[14]:= vectorRule = {X-[t_]2:-+x[ t].x[ t]/;vectorQ[x], x.' [t.] 2 :-+ x' [t] .x' [t] /; vectorQ [x] }; where VectorQ ensures that vectorRule is applied only to vector objects. Illusttate vectorRule by ttansforming the Lagrangian: In[15]:= La//.vectorRule 1 Out[15]= "2 (tlr' [t] .r' [t] +MOR' [t] .R' [t] - 2V[rO [t]]) The Lagrangian in terms of its components is In[16]:= Lb = La//.vectorRule//.rRule//.RRule//Sill\Plify 1 Out[16]= -(-4V[rO[t]] +2/lrO'[t]2+ 4 2MO Rx' [t] 2 + 2MO Ry' [t] 2 + 2MO Rz' [t] 2 + 2 M rO [ t] 2 e' [t] 2 + M rO [t] 2 r// [t] 2 - M Cos [2 e [t] ] rO [t] 2 r// [t] 2 ) The equations for vector R are trivial. Apply EulerEquations found in the add-on package Calculus 'VariationalMethods': In[17]:= Needs[nCalculus'variationalMethods,n] to obtain the equations of motion for the center of mass: In[18]:= EulerEquations[Lb, {Rx[t], Ry[t], Rz [t]}, t] Out[18]= {-MORx" [t] == 0, -MORy"[t] ==O,-MORz"[t] ==O} These equations of motion are those of a free particle. Without loss of generality, set R =0. In[19]:= L=Lb/.{Rx-+ (O&:),Ry-+ (Or.),Rz-+ (or.)}// Siu\plify 1 Out[19]= -(-2V[rO[t]] +M(rO'[t]2+ 2 rO [ t ] 2 W [t] 2 + Sin [ e [ t] ] 2 r// [t] 2 ) ) ) 
382 Chapter 7 Orbiting Bodies Note how the components of R were replaced so that R and its derivatives vanish. The three equations of motion for the relative vector components -; ={rO [t] , B[t] , f/J [t]} follow from Eu1erEquatioDs: In[20];= eqMotion = (EulerEquations [Lb, {rO [t], a [t], .p [t]}, t]11 Solve [I, {rO" [t], a" [t], .p" [t]}] &: II Flatten I I SiDlPlify) I . Rule -+ Equal; eqMotion IIColumnForm rO" [t] = = _ V' [rO [t]] + rO [t] (e' [t] 2 + Sin [e [t] ] 2 (p' [t] 2 ) 2 rO' [  ] e' [ t ] Out[20]= e"[t] ==- +cos[e[t]] Sin[e[t]] (p'[t]2 rO [t] <//' [t] == 2 (rO' [t] + Cot [e[t]] rO [t] e' [t]) <// [t] rO[t] b. The orbit can be oriented in the B=7r /2 plane without loss of generality. Define a rule to reduce the equations of motion to the plane: In [21] ; = aRule = a -+ (7r/2&:) ; Eliminating the B variable in the equations of motion, you get In [22] ;= eqMotion = eqMotionll.aRule; eqMotionllcolumnForm v' [ rO [ t ] ] rO" [t] == + rO [t] <1>' [t] 2 f.1. Out[22]= True <1>" [t] = = 2 rO' [t] <1>' [t] rO[t] The B equation is automatically satisfied, as verified by True in the second part of eqMo- tiOD. The first and third equations in eqMotioD can be reduced to first integrals. The conservation of angular momentum follows from the third equation. Applying DSo1ve to the variable rO, you get In[23];= dSol = DSolve[{eqMotion[[3]], rO [0] == Sqrt [ell (J.I.p' [0]) ]}, {rO [t] }, t] IIPower:Expand II Flatten Out[23]= { -Jel } rO [ t] -> ..[II #ft] where the conserved angular momentum e1 is a constant. We used the initial condition, e1=jl r[0]2 f/J'[O], to eliminate the integration constant in DSo1ve. A rule to eliminate f/J'[t] from the radial equations follows from solving dSo1 for f/J'[t]: 
7.2 The Two-Body Problem 383 In[24J:= «pRule = Solve [dSol/. {Rule- > Equal}, «P' [t]] [[1]] Out[24J= { (t>' [t] -> el 2 } f..lrO [t] Substituting this relation into the first equation of motion given by eqMotion, you get Out[25J= rEq = eqMotion[ [1]] / . «pRule/ /EXpandAll e1 2 V' [rO [t]] rO" [t] == 2 3 f..l rO [t] f..l In[25J:= Notice that the r and f/J dependence in the equations of motion has been successfully un- coupled. The conserved energy is obtained by taking all terms in rEq to the left-hand side, mul- tiplying by rO' [t], and integrating: In [26J : = energy = :Integrate [ (rEq[ [1]] - rEq[ [2]]) rO' [t], t] e1 2 V[rO [t]] 1 Out[26J= 2 2 + +-rO'[t]2 2 f..l rO [ t] f..l 2 This is the expression for the conservation of energy. Notice that the conserved angular momentum and energy also follow directly from the command FirstJ:ntegrals: In[27J:= eq3 = First:Integrals[L/.eRule, {rO[t], «P[t]}, t] /. {First:Integral [«P] -+ -el, First:Integral [t] -+ En j.I} /. Rule -+ Equal/ /ExpandAll; eq3 / /ColumnForm -el == -f..lrO[t]2 cP '[t] au t [2 7 J = En f..l = = V [rO [t] ] + .!. f..l rO' [t] 2 + .!. f..l rO [t] 2 cP' [t] 2 2 2 or solving for {f/J' [t], En}, In [28J := Solve[eq3, {«P' [t], En}]//Flatten// ExpandAll//ColumnForm Out [28J = e1 2 V[rO [t]] En -> + 2 f..l2 rO [ t] 2 f..l , el cP [t] -> f..l rO [t] 2 1 + - rO' [t] 2 2 c. An equation for u=  is obtained with the rule In [29J := uRule = { ro -+ (  & ) } ; u[«P[ 1]] Rules to eliminate f/J' and f/J" follow from 
384 Chapter 7 Orbiting Bodies In [30] := «pRule1 = {«pRule, D[«pRule, t]} II.uRulell Flatten Out[30]= {cP'[t] -> elU[:[t]]2 , cP" [t] -> 2el u[cP[t]] u [cP[t]] cP' [t] } Applying uRule and o/Rulel to rEq, you get an equation for u' , [0/] In[31]:= eq3 = (Solve[rEQII.uRulell.«pRule1, u" [«P [t]]] [ [1]]) I .Rule -+ Equal I . «P [t] -+ «PI I Silify fJ.V' [ 1 ] AU t [ 31] = { u [ cP] + u" [cP] = = il[4Jf } e1 2 U[cP]2 Finally, replace V' [r] with the centtal force V' [r] =-f [r]: In[32]:= eQ4 = eq311.{V' [x_] -+ -f[x]} fJ. f [ 1 ] AU t [32] = { u [ cP] + u" [cP] = = - 2 il[4Jf 2 } el u[cP] . PROBLEM 2 Kepler Orbits. The orbit equation for a particle moving in a centtal po- tential can be expressed as mf [ 1 ] u"[o/] = - l#i - u[o/] eZ 2 u[0/]2 where u = . The orbit is assumed to be in the equatorial plane () =  and u is considered a function of the angular variable 0/. a. Solve for u [0/] when the gravitational potential is V=- . Assume the initial condi- tionu' [0]=0. b. Plot the elliptical and hyperbolic orbits. c. Use the user-defined function diffSeriesOne, defined next, to get a power series solution for the u [0/] equation. Sum the series to get the exact solution. Remarks and Outline To solve the problem you must find the expression for the force from the potential and substitute it into the u-equation. The solution follows from DSol ve. The command PolarPlot is used to graph the solutions. A previously defined series expansion solution is 
7.2 The Two-Body Problem 385 In[33J:= Clear[diffSeriesOne]; diffSeriesOne [eqin_, z_, t_, order., initList_-List] : = Module [{eq, zSer, eSer, eqs,vars, sol, zSol}, eq = eqin[ [1]] - eqin[ [2]] == 0; zSer = Series [z [t], {t, 0, order}]; eSer = eq/. (z [t] -+ zSer) IIExpandAll; eqs = Tbread[CoefficientList[eSer[[1]],t] == 0]; vars = (Table[D[z[t], {t, j}], {j, 2, order + 2}] I.t -+ 0); sol = Solve [eqs, vars] [ [1] ] ; zSol = zSer I. soli. initList; Return [zSol] ] ; Protect[diffSeriesOne]; Solution In [34J : = Clear [nGlobal' * n] a. Consider the orbit equation mf[ u[] ] In[35J:= eq1 = u" [cP] == - -u[cP]; e1 2 u[cP]2 The force is related to the potential by f [r] =-V' [r]. Consttuct a rule that expresses f in terms of u for the gravitational potential V=- : In[36J := forceRule = { V -+ ( - &: ) , f [  ] -+ -v [r], #1 u [cP] r-+  } . u[cP] , Substituting the gravitational potential into eql, you get In [37 J : = eq2 = eq11 I. forceRule km Out[37J= u"(<t» ==-u(<t» el Note that to complete the substitution, you must use n / / . " and not just" / . ". Without loss of generality, choose the initial condition u' [0] =0. Applying DSolve to eq2, it follows that 
386 Chapter 7 Orbiting Bodies In[38J:= eq3 = DSolve[{eq2, u' [0] == O}, {u[cP]}, cP] [[1]] II ExpandAllllSimplify Out[38J= {U(cP).... :l +ClCOS(cPd The general form for the orbit can be written u [4'] =uO (1+e Cos [4'] ) if you replace C [1] with e :r J ekm . i In [39 : = eq4 = eq3/. C [1] -+  I I S:uapl fy el Out [39J= { u (cP) .... k m(eCos (cP) + 1) } el 2 It is common to inttoduce the parameter a defined by ;1: = a(l-e 2 ) so that the canonical form ofu [4'] becomes In [ 40 J : = eqS = eq4 I I. { el -+ "' a (1 - e 2 ) k m} { eCOS(cP)+1 } Out[40J= u(cP).... a(1-e 2 ) The value of e determines the three kinds of conic sections: (1) e>1, hyperbolic; (2) e<1, elliptic; and (3) e=1, parabolic. b. To graph the orbits we use the command PolarPlot found in the add-on package Graphics 'Graphics': In[41J:= Needs["Graphics'Graphics'"] The definition of the command polarPlot is In[42J:= ?PolarPlot PolarPlot[r, {t, tmin, tmax}] generates a polar plot of r as a function of t. POlarPlot[{r1, r2, ...}, {t, tmin, tmax}] plots each of the ri as a func- tion of t on the same graph. More... Define a general graphic function for the orbit: In [43 J : = plotOrbit [a., e_, opts___] : = polarPlot [a (1 - e2) 1(1 + eCos [cP]), {cP, 0, 2 7\"}, opts, DisplayFunction -+ :Identity] ; Consider the list of elliptical orbits for e between 0.1 and 0.9: In [44J : = list = Table [plotOrbit [1, e:In, PlotStyle-+ {Thickness [0.008], Hue [e:In ] } ], {e:In, O. 1, O. g, 0.2} ] ; 
7.2 The Two-Body Problem 387 Displaying the results, it follows In[451 : = Show [list , DisplayFunction- > $DisplayFunction]; To plot a hyperbolic path, you use the same command but with e>l (e=l. 3): In[461:= plotOrbit [1,1.3, DisplayFunction- > $DisplayFunction]; .6 C. Use the user-defined function diffSeriesOne, defined at the beginning of this problem under Remarks and Outline, to derive a power series solution for eq2: In [ 471 : = eq2 km Out[47]= u"(<t» ==  -u(<t» el To agree with the initial conditions in part a let { (1 + e) k m } In[481:= initial = u' [0] -+ 0, u[O] -+ e1 2 ; Applying diffSeriesOne to eq2, you get In[491:= seriesSol = diffSeriesOne[eq2,u,,6,initial]// Normal / / ExpandAll Out[491= ek m<t>6 ek m<t>4 ek m<t>2 - + - 720e1 2 24e1 2 2e1 2 ek m k m +-+- e1 2 e1 2 
388 Chapter 7 Orbiting Bodies Notice that the general expression for terms with e in front follow from (-l)Dek mcP 2D In[50J:= cterm[n_] = 2 ; e1 (2 n) I Verify this general expansion for the first five terms: In [51J : = seriesSo1 == ( :1  + Sum[cterm[i], {i, 0, 3}] ) Out[51J= True Summing the series solution, you get the exact answer: k a> In [52 J : = answer = ---; + .L: cterm [n] / / PowerExpand / / e1 D=D Silify [ J k m(eCos (<1» + 1) Out 52 = 2 e1 This result agrees with the answer given in part a. In[53J:= (u[cP] /.eq4) == answer Out[53J= True . PROBLEM 3 Precessing Ellipse. The orbit equation for a particle moving in a centtal potential can be written as mf [ 1 ] u"[rp] == - l#J - u[rp] eZ2u[ rp]2 where u =  and e1 is the conserved angular momentum. The orbit is assumed to be in the equatorial plane () = , and u is considered a function of the angular variable rp. a. Solve for u [rp] when the potential is V = -  - . Express the solution in the form of a precessing ellipse [ ] 1 + ecos[(1 - )rp] u rp = a(1 - e 2 ) b. Graph the results. c. Use the user-defined function firstOrderPert to find the first-order perturbative solution in the parameter b. Show that the result agrees with the expansion of the solution derived in part a. The user-defined function firstOrderpert is defined below. Remarks and Outline Find the expression for the force in terms of u. Substituting the force relation into the equations of motion, DSo1 ve yields the solution. The command 
7.2 The Two-Body Problem 389 Parametric Plot is used to graph the solutions. The perturbative solution follows from firstOrderPert: In[54J:= firstOrderpert[eq1.,x., {xo.,vO.},eps_ :eps,t_ :t] .- Module[{xRule,eq2,eqs,initconO, initcon1, dso11, dso12}, xRule= {x-+ (x[O] [I] +epsx[1] [#]&:)}; eq2 = eq1 [[1]] - eq1 [[2]] l.xRule; eqEps = CoefficientList [eq2, eps] == O//Thread; initConO = {x[O] [0] == xO, (x[O])' [0] == vO}; initcon1 = {x[1] [0] == 0, (x[1])' [0] == O}; dsoll = (DSolve [Join [ {eqEps [[1]]}, initconO], {x[O] [t]}, t] II Flatten); dso12 = (DSolve [Join [ {eqEpS [[2]]}, initcon1] I I. dsoll, {x[1] [t]}, t] IIFlatten); Return[x[t]/.xRulell. Join[dso11,dso12]] ] ; Protect[firstOrderpert]; The command firstOrderPert returns the first order correction to the term with co- efficient eps. Solution In [55J : = Clear [RGlobal' * 0] a. Consider the orbit equation mf[ u[] ] In[56J:= eq1 = u" [cP] == - - u[cP]; e1 2 u [cP] 2 The force is related to the potential by f [r] =-V' [r]. The rule that finds f from the potential is In [571 := forceRule = { V -+ ( -  - &: ) , #1 #1 f [  ] -+-V'[r],r-+ } ; u[cP] u[cP] Substituting the forceRule into eql, you get In[58J:= eq2 = eq111.forceRulellExpandAll , km 2bu(cP)m Out[58J= u' (cP) ==  + 2 -u(cP) el el Applying DSol ve to eq2, it follows In [59J := eq3 = (DSolve[{eq2, u' [0] == O}, u[cP], cP]) II SiDwlify II Flatten 
390 Chapter 7 Orbiting Bodies k m+ (e1 2 - 2bm) C 1 Cos [  ) {U(cj»-> e1 2 -2bm } Out[59J= This expression can be written in the form uO (l+e Cos [ (i-A) 0/] ). Without loss of generality you can choose C [1] to be ek m In[60J:= CRule = C[l] -+ 2 ; el - 2 bm uSol = eq3/ .CRule/ /Silify k m [ e Cos [  ) +1] {U (cj» -> e12 _ 2 bm } Out[60J= The expression for A follows from the argument in Cos or (i-A) = VeP;/bm . If we define the rule { '" e1 2 - 2 bm } In[61J:= shiftRule= el -+1-1!. ; then it follows In[62J:= eq3/.CRule/.shiftRule//FullSilify [62J { ) km(eCOS(cj>-t:.cj»+l) } Out = u(cj> -> e12 _ 2bm You can also inttoduce the parameter a, defined by the rule In[63J:= elRule = Solve [{ 2k m == 1 2 } ,el ] [[ el -2bm a(l-e) 2]] //Silify out [63 J = {el ->  (2 b - a (e 2 - 1) k) m} The final form of the orbit is In[64J:= eq3/.CRule/.shiftRule/.elRule// Simplify { eCos(cj>-t:.cj» +1 } Out[64J= u(cj» -> - ( ) a e 2 - 1 b. A user-defined function to plot the orbit r = l+e:[(rI!.)4>] is 
7.2 The Two-Body Problem 391 In[65]:= plotorbit [start., finish_, {a_, e.,.IL}, opts__.] : = parametricPlot[ { a (1- e 2 ) Cos [cP] l+ecos[(l-to) cP]' a(l- e 2 ) Sin[cP] }// 1 Eva uate, 1 + ecos[ (1- to) cP] {cP, start, finish}, OPts] If you let the values {a,e,A} be In[66]:= values = {1, 0.5, 0.1 }; then the plot of the orbit is In[67]:= plotorbit[O,67\",values, PlotStyle -+ {Thickness [0.008], Hue [0.8]}]; The resulting curve is a precessing ellipse. C. Use the user-defined function firstOrderPert to solve eq2 In[68]:= eq2 " k m 2bu(q,} m Out[68]= u (q,) ==  + 2 -u(q,} el el to first order in the parameter b. Applying firstOrderPert to eq2 with the initial conditions u [0] = (1 +e) km and u' [0] = 0 it follows ez2-2 bm ' In [69] := eq4 = firstOrderPert [ e Q 2, u, { (1; e) k m , O } , el - 2 bm b, cP] + 0 [b] 2/ /Normal / / Silify / / Expand 2bkm 2 2bekCos (q,) m 2 Out[69]=  + e1 4 + bekq,Sin(q,}m 2 k m ekCos(q,}m e1 4 + e1 2 + e1 2 
392 Chapter 7 Orbiting Bodies where we have kept terms to first order in b. This is to be compared with the exact solution In[70] := u[cP]/.uSol Out[70]= k m [ecos [  ] +1] e1 2 -2bm expanded to first order in b, In[71]:= eq5 = (u [cP] / .uSol) + 0 [b] 2/ /Normal / / ExpandAll / / PowerExpand 2bkm 2 2bekCos(cj»m 2 Out[71]=  + e1 4 + bekcj> Sin(cj» m 2 k m e1 4 + e1 2 + ekCos (cj» m e1 2 which is in agreement with the perturbative solution given by eq4: In [72] := eq4 == eq5//Silify Out[72]= True . PROBLEM 4 Numerical Solution. Consider the numerical solution of the orbit equa- tion mf [ 1 ] u"[rp] == i#J - u[rp] h 2 u[rp]2 a. Assume the Keplerian potential V = -  and numerically solve the equation with initial conditions that correspond to an ellipse and to a hyperbola. Plot both solutions. b. Make a user-defined function that automatically solves and plots the orbit equation. Apply the plot procedure to the Kepler potential and to the two classes of potentials defined below: (a) V = --fr and r' (b) V = - -  and y - _..!. - rO. 9 , y-_5.+.!!... - r ,3' Remarks and Outline The numerical solution follows from NDSol ve. The choice of the initial conditions determines whether the orbit is an ellipse or hyperbola. Use the com- mand polarPlot, found in the add-on package Graphics' Graphics', to graph the results. Solution In [73] : = Clear [RGlobal' * R] 
7.2 The Two-Body Problem 393 a. Consider the orbit equation mf[ u(4)J ] In[74J:= eq1 = un [41] == - 2 2 - u[41]; el u[41] and find the numerical solution of eql for the Kepler potential V expressed in terms of u follows from the rule -. The force f r In[75J:= forceRule = {v... ( - .k 1 ,,), f[ ut4l] ]'" -V' [r], r... } . u [41] , Substituting the forceRule in eql, you get In [76J : = eq2 = eq1/ /. forceRule " k m Out[76J= u [<p] ==  - u[<P] el Choose the parameters. In [77 J : = values = {k... 1, el ... 1, m... 1}; You obtain an ellipse if the initial conditions are chosen to be In[78J:= initial1=u[0] ==1.6,u'[0] ==0; The numerical solution of eq2 is In [79J := ndsol1 = NDSolve[{eq2/.values,initial1}// Flatten, u [41], {41, 0,2 7r}] / /Flatten; For convenience, define the function ul [4>] to be the solution for the ellipse case In[80J:= u1[41.] =u[41]/.ndsol1; u1[1.1] Out[80J= 1.27216 where ul was evaluated at a sample point to verify that the solution was properly obtained. The plot of r as a function of 4> follows from applying polarPlot to u[] ' The command polarPlot is found in the add-on package In[81J:= Needs[DGraphics'Graphics'D] The plot of the orbit follows In [82J := polarPlot [ / /Evaluate, {41, 0, 2 7r} ] ; u1 [41] 
394 Chapter 7 Orbiting Bodies -1 In[83]:= initia12 = {ufO] ==3,u'[0] ==O}; Hyperbolic orbits follow from the initial conditions: Again applying NDSolve to eq2, you get In[84]:= ndso12 = NDSolve[{eQ2/.values,initia12}// Flatten, u [41], {41, 0, 2 :71"}] / /Flatten; Define the function u2 [4>] to be the solution for the hyperbolic case: In [85] := u2 [41-] = u[41] / / .nd.so12; u2 [1.1] Out[85]= 1.90719 The plot of r is In[86]:= polarPlot [ / /Evaluate, {41, 0, 2 7r} ] ; u2[41] .1 2 
7.2 The Two-Body Problem 395 b. The routine for plotting the numerical solution can be summarized in four steps: 1. Find the force from the potential and express it in terms of u. 2. Make a list of the orbit equations and initial conditions. 3. Numerically solve the orbit equation. 4. Use polarPlot to generate the graphics. These four steps are combined in the user-defined command numOrbit: In[87]:= numOrbit[V_, r_, {rO_ :1, drO_ :0, eL :l,DL :1}, angle_, opts___] .- Module [{u, t/J, uforce, eql, initial, eqs, ndsol}, uforce = -D[V, r] /.r "'l/u[t/J]; eql= (u"[t/J] ==-u[t/J] -muforce/(el-2u[t/J]-2)// ExpandAll) ; initial = {u[O] ==l/rO,u'[O] ==-drO/rO-2}; eqs = Join[{eql}, initial]; ndsol = NDSolve[eqs, u[t/J], {t/J, 0, angle}] / /Flatten; pOlarplot[l/u[t/J]/.ndsol//Evaluate, {t/J, 0, angle}, opts, DisplayFunction... Identity] where uforce represents the force as a function of V' [l/u] ; eql is the equation of motion for u; initial contains the initial conditions; eqs is the collection of equations for NDSolve whose solution is ndsol. The command polarPlot graphs r=l/u. Note that default values for rO, drO, el, 111, and angle are incorporated. It is assumed that the add-on package Graphics 'Graphics' has been activated. Applying numOrbi t to the Kepler potential, you get . [ 1 In[88]:= numOrb1t - r' r, {0.6, 0, 1, I}, 271", PlotStyle... {Thickness [0.008], Bue [0.6]}, DisplayFunction ... $DiSPlayFunction] ; 
396 Chapter 7 Orbiting Bodies Compare the orbits for V=- jr and V=- : In [89] := lista = numOrbit [#, r, {O .6,0, l,l}, 671", PlotStyle... {Thickness [0 .008], Hue[0.6]} ]&:/8-{ - r;.l ' - r;.9 }; In[90]:= Show[GraphicsArray[lista]]; The curve on the left precesses in a counterclockwise direction and the one on the right precesses in a clockwise direction. Similarly, the orbits forV=-- and V=-+ with b=O. 02 are In[91]:= listb = numOrbit[#, r, {0.6, o,l,l}, 671", PlotStyle... {Thickness [0 .008], HUe[0.6]} ]&:/8- { _ 0.02 _  0.02 _  } . r 3 r' r 3 r' In[92]:= Show[GraphicsArray[listb]]; . 7.3 . RESTRICTED THREE-BODY PROBLEM 7.3.1 . Overview of the Three-Body Problem and Initialization of PMotion and Mgraph The equations of motion for three bodies moving under their mutual gravitational atttaction are 
7.3 Restricted Three-Body Problem 397 2--> d r 1 m 2 G--> m 3 G-->  = r12 + r13' dt '12 '13 2--> d r 2 m l G--> m 3 G--> dt 2 = Y r 21 + Y r 23 12 23 2--> d r 3 m l G--> m 2 G--> =r31+r32 dt '13 '23 where the relative vectors are -;12 = -;2- -;1' -;13 = -;3- -;1' -;23 = -;3- -;2' -;ij = --;ji and G is the gravitational constant. The increase in complexity when the third body is inttoduced can be explained by the increase in the number of variables. The total number of equations is nine. This number is reduced if the position vectors are measured relative to the center of mass, located at ml-; 1 + m2 -; 2 + m3 -; 3 = O. This consttaint gives three equations and reduces the number of equations to six. Further simplicity is obtained for the special case of orbits lying in a fixed plane-the order is reduced to only 6 - 2 = 4 equations. Even for this special case the three-body problem is a complicated nonlinear problem. The system of differential equations cannot be reduced to quadratures, and hence the problem is not solvable. The three-body problem simplifies if the lightest of the bodies is assumed to have no affect on the motion of the other two bodies (called primaries). The (circular) restricted three-body problem tteats the motion of an infinitesimal particle due to the gravitational atttaction of two massive primaries moving on circular orbits about one another. We take m3 to be the infinitesimal mass so it does not influence the motion of ml and m2, but is affected by them in the usual way: 2--> d r 1 m 2 G--> dt2 = ri2 r 12 2--> d r 2 m l G --> ---r dt 2 -  21 12 2--> d r 3 m l G--> m 2 G--> =r31+r32 dt '13 '23 The description for the motion of the primaries follows from the two-body problem. We assume that ml and m2 undergo circular motion with a constant angular velocity w. The primaries rotate about their center of mass with an angular frequency w 2 = o/f, where L is the separation between the two massive bodies and M = ml + m2. We restrict the motion, without loss of generality, by requiring the motion of ml and m2 to be in the {x, y} plane. The restricted three-body equations take on a very simple form in a frame centered on the center of mass but rotating at rate w. If {X, Y} are coordinates in the nonrotating frame and {x, y} are coordinates in the rotating frame, then the coordinate systems are related by X = x Cos[wt] - y Sin [wt] Y = x Sin[wt] + y Cos[wt] 
398 Chapter 7 Orbiting Bodies The primaries will be at rest in the rotating frame with their mutual gravitational atttac- tion balanced by the outward "push" of centrifugal force. We place the primaries on the x-axis. Let ml be located at {xl, O} and m2 at {x2, O} and restrict the motion of m3 to be in the {x, y} plane. The equations of motion for the infinites- imal particle in the rotating frame centered on the center of mass of the two primaries are " [] 2 ' [] 2 _Gml(xl-x[t]) Gm2(x2-x[t]) x t - wy t - w x[t] - 3 + 3 rl r2 " [] 2 ' [] 2 [] Gml(yl-y[t]) Gm2(y2-y[t]) y t + wx t - w Y t = r13 + r2 3 where rl =  (x - x1)2 + i and r2 = .v (x - x2)2 + i. Without loss of generality we can pick units so that ml + m2 = 1, L = 1 (separation of the massive particles) and G = 1. With this choice of units the angular frequency of the primaries becomes w = 1. We also call the smaller primary mass m2 = J-l so the larger primary mass becomes ml = 1 - J-l, where J-l ;s; . In these dimensionless units the mass ml is located at {-J-l, O} and m2 at {1 - J-l, OJ. The equations of motion become x"[t] - 2 y'[t] - x[t] = (1 - J-l)(x + J-l) J-l(x - 1 + J-l) r1 3 r2 3 y"[t] + 2 x'[t] - y[t] = (1 - J-l)Y J-ly r1 3 - r2 3 where rl =  (x[t] + J-l)2 + y[t]2 and r2 =  (x[t] - 1 + J-l)2 + y[t]2. The equations of motion admit a first integral known as the Jacobian integral, which is analogous to the conservation of energy. This first integral is C = -(x'[t]2 + y'[tf) + 2U where U = (x[t]2 + y[t]2) +  + . The constant C is the Jacobian constant of inte- gration, which is constant throughout the motion. The effective potential U includes the gravitational potential  +  and a term representing the position-dependent centrifugal force (x[t]2 + y[t]2). The equations of motion, expressed in terms of the potential, are x"[t] - 2y'[t] = 0xU y"[t] + 2x'[t] = OyU The equilibrium positions follow from the solution of the two equations 0xU = 0 and OyU = O. These stationary points are called Lagrangian points. If the infinitesimal parti- cle is placed at one of these Lagrangian points with zero velocity, it will remain at rest in the rotating coordinates-the stationary points co-rotate with the primaries. There are five Lagrangian positions {L1, £1, L3, lA, LS}: three Lagrangian points (L1, £1, L3) are collinear with the primary masses and the other two points, lA and LS, form equilateral triangles with the primary masses. 
7.3 Restricted Three-Body Problem 399 In this section we consider several numerical examples of the restricted three-body prob- lem. There is no difficulty in numerically integrating the equations to find the ttajectories for finite time durations. There are problems, however, when the details of the ttajectories are needed for long time intervals. Computers cannot offer solutions for arbittarily long times of the gravitational three-body problem. It is useful to create user-defined procedures for the calculations that are used in more than one problem in this section. There are two user-defined procedures that are used re- peatedly for the restricted three-body problem. The user-defined procedures are PMotioD and Mgraph. The procedure PMotioD returns an interpolating function for the solution of the restricted three-body problem: In [93] : = PMotion [1_, {xO_, yO_, vxO_, vyO.}, tmax_, step_ : 1000] .- Module [{rrule, Urule, eqMotion, rl , r2,, U}, rrule = {r l -+" (+ x[t]) 2 + y[t] 2, r2 -+ " (-1 +  + x [t] ) 2 + y [t] 2}; Urule = { u -+ 1-  +  + ! ( X[t]2 + y[t]2 ) } ; rl r22 eqMotion= {x"[t] -2y'[t] ==D[U/.urule/.rrule,x[t]], y"[t] +2x'[t] ==D[U/.urule/.rrule,y[t]]}; NDSolve[ {eqMotion/. -+ 1, x[O] == xO, y[O] ==yO,x'[O] ==vxO,y'[O] ==vyO}// Flatten, {x, y}, {t, 0, tmax}, MaxSteps -+ step] / /Flatten ] The procedure Mgraph graphs the point {fx [t] , fy [t]}: In[94]:= Mgraph[fx_, fy., t_, tfinal., Opts___] : = ParametricPlot[{fx[t],fy[t]}//Evaluate, {t, 0, tfinal}, Opts, AspectRatio -+ Automatic, DisplayFunction -+ Identity] ; Finally, we apply Protect to the user-defined procedures to keep them from being deleted with Clear [ n Global' * n ] : In[95]:= Protect [pHotion, Mgraph]; 7.3.2 . Problems on the Equal Mass Primaries (p = 112) . PROBLEM 1 Lagrangian Points for Equal Mass Binaries (p = 112). Consider the restricted three-body problem when the binary system has equal masses (p =1/2). The motion with J.l =1/2 is generally known as the Copenhagen problem. The Jacobian integral is C= _(x'[t]2 + y'[t]2)+2U where U= t(x[t]2 + y[t]2) + !fz + . The Lagrangian points follow from the solution of the two equations axu =0 and ayu =0. 
400 Chapter 7 Orbiting Bodies a. Numerically solve for the five Lagrangian points when J-l =1/2. Observe that three Lagrangian points are collinear and two are triangular. Show that the triangular points and primaries form an equilateral triangle. Plot the Lagrangian positions. b. For an arbittary J-l, show the exact solutions for the two triangular positions, L [4] and L[5], are x=+1/2 (1-J-l) and y= :t {{ . To simplify the calculation use the observation from part a that the triangular points and primaries form an equilateral triangle. c. Make a contour plot in the {x,y} plane for the Jacobian first integral where the velocity has been set equal to zero. Include the Lagrangian points with the zero- velocity contours. Solution In [96J := Clear[RGlobal' * R] a. Let us solve for the five Lagrangian points when J-l =1/2. Since x and y are constant, the positions are determined by the two equations axu=o and ayu=o, where U is given by 1-j,I j,I 1 ( ) In[97J:= Urule=U...-+-+- X[t]2+ y [t]2 ; r1 r2 2 and r1 and r2 are In [98J : = rrule = {r 1 ...  (j,I + x[t]) 2 + y[t] 2, r2...  (-1 + j,I +X[t])2 +y[t]2}; Taking the x and y partial derivatives of U, it follows In [99J := (eq1 = D[U / .Urule/ .rrule, x[t]] == 0) / /TraditionalForm (eq2 = D[U / .Urule/ .rrule, y[t]] == 0) / /TraditionalForm Out[99J= x(t) _ /1UHX(t) -1) 3/2 - ((/1+X(t) _1)2+ Y (t)2) (1-/1) (/1 + x(t)) 3/2 == 0 ((/1+x(t))2 +Y(t)2) /1y(t) ((/1+x(t) _1)2 +Y(t)2)3/2 (l-/1)y(t) (t) -- 0 3/2 +y -- ((/1 +x(t))2 +y(t)2) Out[99J= - Setting J-l =  and using NSol ve to obtain a numerical solution, you get five positions 
7.3 Restricted Three-Body Problem 401 In[lOOl:= {L[2], L[3], L[4], L[5], L[l]} = I {eql, eq2} I.j.!'" "2 I I NSolve[#, {x[t],y[t]}]6i:; {L [2], L [3], L [4], L[5], L [I]} I I ColumnForm {y[t] ....O.,x[t] ....1.19841} {y[t] ....O.,x[t] ....-1.19841} Out[lOOl= {y[t] .... -0.866025, x[t] .... O.} {y[t] ....0.866025,x[t] ....O.} {y [t] .... 0", x [t] .... o. } The individual positions are labeled L [i]. The set of coordinates is called CLpt: In[lOll:= CLpt = L[#]6i: Ie. Range [5] ; These points correspond to the positions where the atttactive gravitational force from the primaries just balance the centrifugal force. The three Lagrangian points on the x-axis (y [t] =0), {L [1], L [2], L3}, called the collinear positions, are located at: In[1021:= {x[t], y[t]} I. {L[l], L[2], L[3]} I I TableForm[#, TableHeadings... {{nL[I]n, nL[2]n, nL[3]n}, {x[t],y[t]} }]6i: L[l] Out[1021= L[2] L[3] x[t] o. 1.19841 -1.19841 y[t] o. o. o. The two points L [2] and L [3] lie on the x-axis and are outside the two masses and the inner Lagrangian point, L [1] , lies between the two masses. Each of the points, L [1] , L [ 2] , and L [3 ] , is an unstable equilibrium point. For example, if a particle is displaced from L [2] (or L [3] ) further from the primary, then the inward gravitational atttaction is reduced and centrifugal term is increased; consequently, the test particle will accelerate outward. Moving a test particle from L [2] (or L [3] ) toward the primary will increase the atttactive force and reduce the centrifugal force and the test particle will accelerate toward the primary. A similar discussion holds for L [ 1] . The remaining two Lagrangian points are off the x-axis. In this particular example they are on the y-axis. In[1031:= {L[4],L[5]}llcolumnForm Out[1031= {y[t] .... -0.866025, x[t] .... O.} {y[t] .... 0.866025, x[t] .... O.} Notice the distance from the primaries to L [4] or L [5] are equal and of unit length 
402 Chapter 7 Orbiting Bodies In[104]:= rl == r2 == 1/ .rrule/ .L[4] /.j.! -+ 1/2 Out[104]= True The Lagrangian points L [4] and L [5] form equilateral triangles with the primaries. These two Lagrangian positions are known as the triangular points. The graphics for all five Lagrangian points follow from In[105]:= Lgraph = Graphics [ {{PointSize[0.02],Bue[0.9], Map [Point, {x[t],y[t]}/.CLpt]}, Text[L., {x[t] +O.l,y[t]}/. CLpt [[I]] ]&:/e- Range[5]} ]; Combine these graphic points with the graphics for an equilateral triangle and the posi- tions of the primaries: In[106]:= equilateral = Graphics [ {{PointSize [0.02], Point [{ -1/2, O} ], Point[{1/2,0} ]}, {Thickness[0.002],Hue[0.4], Line [ {{ -1/2, O} , {x[t], y[t]}/ .L[4], {1/2, O}, {-1/2, O}, {x[t],y[t]}/.L[5] ,{ 1/2, O}}] }, Text[L., {x[t] +O.l,y[t]}/. CLpt [ [I]] ] &:/e-Range [5]} ] ; Combining the graphics and displaying the results, it follows that In[107]:= Show[Lgraph,equilateral, AspectRatio -+ Automatic]; l5 /' " \ eL 3 ,( """,.Lr """ m. / eL 2 Ii \ \, .L b. Consider an arbittary J.l and solve for the triangular positions L [4] and L [5] . To simplify the derivation, take the suggestion from part a and assume rl and r2 are equal 
7.3 Restricted Three-Body Problem 403 and of unit length: In[10BJ : = e q3 = r1 == r2 == 1 I. rrule Out[10BJ= -) ( I1+X[t])2+ y [t]2== -) (-1 + 11 + x [t] ) 2 + y [t] 2 == 1 Solving eq3 for x [t] and y [t ] , you find In[109J:= eq4 = Solve [eq3, {x[t],y[t]}, :InverseFunctions -+ True] Out[109J= {{y[t] .... - V; , x[t] ....  (1- 211)}, {y[t] .... V; , x[t] ....  (1- 211)}} To verify that these are indeed Lagrangian points, substitute them into eq1 and eq2, In[110J:= {eq1,eq2}/.eq41ISimplify Out [110J = {{True, True}, {True, True}} c. The equations for the restricted three-body problem admit the following first integral In [lllJ : = jacobi = C == - (x' [t] 2 + y' [t] 2) + 2 U I. Urule ( 1-11 11 1 ) Out[lllJ= C==2 _+_+_(x[t]2+ y [t]2) - r1 r2 2 X'[t]2_ y '[t]2 This relation is known as the Jacobian integral and the constant C is called the Jacobian constant. Let us graph the zero-velocity contours. The zero velocity curves follow from setting x' [t] and y' [t] to zero in the Jacobian integral. The plot of the zero velocity contour lines for J-l =1/2 is In[112J:= jacGC = ContourPlot [ 2 U I. Urulel .rrule/. -+ 1/211 Evaluate, {x[t], -2, 2}, {y[t], -2,2}, ContourShading -+ False, Contours -+ Range [3,4.5, 0.1], Plotpoints -+ 66, DisplayFunction -+ :Identity] ; If we combine these zero velocity contours with the graphic for the Lagrangian points and equilateral triangle, then it follows that 
404 Chapter 7 Orbiting Bodies In[113J:= Show [jacGC, Lgraph, equilateral, DisplayFunction -+ $DisplayFunction ] ; 1.5 -1.5 -1.5 -1 .0.5 0 0.5 1 1.5 The motion for an infinitesimal particle can only exist in those regions of the {x, y} plane for which C-2 U<O or X'[t]2+ y '[t]2> O. George W. Hill (1878) inttoduced the idea of zero velocity curves and established the possible and forbidden regions of motion. Such a qualitative result is important because its validity is independent of the time duration. The two triangular points are located in the oval-shaped areas near the top and bottom of the figure. The figure-eight areas around the primaries represent equipotential surfaces for the binary stars. In a binary system, as one of the stars evolves, it will expand to fill successively larger equipotential surfaces. The appearance of a binary star system depends on which equipotential surfaces are filled by the stars. If one star expands enough to fill the figure-eight contour out to the inner Lagrangian point, then its atmospheric gases can escape through the point and be drawn toward its companion. The boundary of the figure- eight region is called the Roche lobe. . PROBLEM 2 Looping Motion in an Equal Mass Binary System (p = 1/2). Assume equal mass primaries and explore the different kinds of "looping" orbits around one of the primaries. a. Let the starting conditions bex[O] =0.3, x' [0] =0, andy[O] =0. Adjusty' [0] until you get a rettograde elliptical orbit (Hint: Try y' [0] =1.781). Plot the results in rotating and nonrotating coordinates. b. Start the motion at x [0] =1.35, x' [0] =0, y [0] =0 and adjust y' [0] until you achieve a double loop (Hint: Try y' [0] =-1. 568). Plot the results in rotating and nonrotating coordinates. c. Consider the multi-loop path that follows from x [0] =-0.0114, Y [0] =0, x' [0] =0, y' [0] =+1. 537. Plot the results in rotating coordinates. 
7.3 Restricted Three-Body Problem 405 Solution In[114J:= C1ear[nG10ba1' * n] a. After several trial and error attempts you find that the initial conditions for an ellip- tical orbit are x [0] =0.3, x' [0] =0, and y [0] =0, and y' [0] =1.781. The numerical solution for the path follows from the user-defined function PMotion given at the start of the chapter, where J-l is the mass, {xO, yO , vxO , vyO} are the initial conditions, tmax is the time interval, and step is the number of steps in the differential equation. It follows from the user-defined function PMotion that the path is In[115J:= sol = pHotion[1/2, {0.3, 0, 0, 1.781}, 67f, 1000]; where sol contains the interpolating functions for {x,y}. The time duration of t=67T corresponds to 3 orbits of the primary stars. The coordinates for the test body are In [116J : = fx[t_] : = x[t] / .sol; fy[t.] : = y[t] / .sol; The graphic for the path in the rotating frame follows from the user-defined function Mgraph, given at the start of the chapter: In[ll?J:= pt1 = Mgraph[fx, fy, t, 67f, P10tpoints -+ 100, P10tSty1e -+ Rue [0.9] , Aspec:tRatio -+ Automatic:, Epilog -+ {Abso1utePointSize [7] , Point [{112, O}]}, Disp1ayFunc:tion -+ $Disp1ayFunc:tion] ; 7 
406 Chapter 7 Orbiting Bodies The particle is ttapped in the potential well about one of the primaries. It makes a com- plete orbit in a time of tO .7, which corresponds to 1/9 of the primary's period or t . The orbit is an elliptical-like path but there is sITucture in the band as seen from magnifying a portion of the orbit In[118]:= Show[pt1, P10tRange -+ {{O. 692, O. 709}, {-O.Ol, 0.01 }}, Ticks -+ False]; What does the orbit look like in the nonrotating coordinates{x, Y}? The nonrotating and rotating coordinates are related by X[t] = x[t] Cos[t] - y[t] Sin[t] Y[t] = x[t] Sin[t] + y[t] Cos[t] Let us plot the path in the inertial frame over a time duration of one binary orbit, t=27T: In[119]:= parametricP1ot[ {{COS[t],  Sin[t]}, {fx[t]Cos[t] -fy[t] Sin[t], fx[t] Sin[t] + fy[t] Cos[t]} } II Evaluate, {t,O,27f}, P10tStyle -+ {GrayLevel [0.3] , Hue [0.6] } , AspectRatio -+ AutomatiC] ; 
7.3 Restricted Three-Body Problem 407 The path forms a rettograde epicycle around the primary and makes nine loops for every one orbit of the primary. The circle is the path of the primaries rotating around the center of mass located at the origin. b. Mter several trials it follows that the initial conditions for a double loop are x[0]=1.35, y[O]=O, x' [0]=0, and y' [0]=-1.568. The user-defined function PMotion returns the interpolating functions for the path, In[120J:= sol = PMotion[1/2, {1.35, 0,0, -1.568}, 10 7f, 1000] Out [120J = {x -. InterpolatingFunction [ {{O., 31.4159} L <>], y -. InterpolatingFunction [ {{O" 31.4159} L <>]} where the time duration of t=10 7r corresponds to five orbits of the primary stars. The coordinates for the test body are In[121J:= fx[t_] :=x[t]/.sol; fy[t.] :=y[t]/.sol; The graphics for the path in the rotating frame follow from Mgraph: In[122J:= Mgraph[fx, fy, t, 107f, P10tpoints -+ 100, P10tSty1e -+ Hue [0.8] , P10tRange -+ {{ -0.5,1.5}, {-1, 1}}, Epilog -+ {Abso1utePointSize [7], Point [{1/2, O}]}, Disp1ayFunction -+ $Disp1ayl'unction] ; 
408 Chapter 7 Orbiting Bodies 1 o. -0. -1 The particle forms a rettograde double loop that takes about t27T to make one complete double loop. What does the orbit look like in inertial coordinates {x, Y}? The path in nonrotating coordinates for one and five rotations of the binaries follow from In[123]:= ptl = parametricPlot[ {{COS[t],  Sin[t]}, 1.35{Cos[t], Sin[t]}, l.l{Cos[t], Sin[t]}, {fx[t] Cos[t] - fy[t] Sin[t], fx[t] Sin[t] + fy[t] COS[t]}}// Evaluate, {t,O,'7f}, PlotStyle -+ {GrayLevel [0.3], Hue [0.6], Eue[O .9]}, AspectRatio -+ Automatic, DisplayFunction -+ :Identity ]&:/@{2, 10}; Displaying the results, it follows In[124]:= Show[GraphicsArray[ptl]]; 
7.3 Restricted Three-Body Problem 409 These graphs show the double looping path in the inertial frame. The path on the left is for one binary rotation and the one on the right is for five rotations. The inner circle corresponds to the orbits of the primary rotating around the center of mass. The outer two circles are the envelopes for the small and large loops. c. Let the initial conditions be x [0] =-0.01112, Y [0] =0, x' [0] =0, andy' [0] = -1.538 and use the user-defined function PMotion to solve for the path's interpolating functions In[125J:= sol = PMotion[1/2, {-0.01112, 0, 0, +1.538}, 107f, 1000] Out [125J = {x -7 InterpolatingFunction [ {{O., 31.4159}}, <>], y --> InterpolatingFunction [ {{D., 31.4159}}, <>]} where the time duration of t=10n corresponds to five orbits of the primary stars. The coordinates for the test body are In[126J:= fx[t.] :=x[t]/.sol; fy[t.] :=y[t]/.sol; and the path in the rotating coordinates is In[127J:= Mgraph[fx, fy, t, 10 7f, Plotpoints -+ 100, PlotStyle -+ Hue [0.6] , Epilog -+ {AbsolutepointSize [7], Point [{1/2, O}]}, DisplayFunction -+ $DisplayFunction] ; The path takes about t::::: 2n to make one complete cycle. 
410 Chapter 7 Orbiting Bodies . PROBLEM 3 Symmetric Orbits about the y-Axis for J1 = 1/2. Assume J1 =1/2 and consider an orbit that is symmetric about the y-axis. Start the ttajectory at x (0) =0, y [0] =0.12067, x' [0] =-1. 0600745428 andy' [0] =0. Plotthe results in thero- tating frame. Solution In[1281:= Clear["Global' *"] Consider the path In[1291:= sol = PMotion[1/2, {O, 0.12067, -1.06007,0}, 67f, 1000] ; where the duration is for three orbits of the primaries. The coordinates for the test body are In[1301:= fx[t_] :=x[t]/.sol; fy[t_] :=y[t]/.sol; Recall from a previous problem that the Lagrange points were at In[1311:= CLpt = {{y[t] -+ 0., x[t] -+ O.}, {y[t] -+ 0., x[t] -+ -1.1984}, {y[t] -+ 0., x[t] -+ 1.1984}, {y[t] -+ 0.866,x[t] -+ O.}, {y[t] -+ -0.866, x[t] -+ O.}}; so the path follows from In[1321:= Mgraph[fx, fy, t, 67f, Plotpoints -+ 100, PlotStyle -+ Hue [0.8] , Epilog -+ {AbsolutepointSize [7], Point [{1/2, O} ], Point [{ -1/2, O} ], Point [{x[t] , y[t] }/. CLpt[ [#]] ]&: /@ Range [4] } , DisplayFunc:tion -+ $DisplayFunc:tion] ; 
7.3 Restricted Three-Body Problem 411 1.5 1 0.5 Notice that more fine-tuning needs to be done on the initial conditions to make them perfectly symmetric. The orbit is outside both of the primaries but encloses the Lagrangian points L [2], L [3], and L [4]. If you integrate the path for long enough times the numer- ical errors will accumulate and the particle will escape. . PROBLEM 4 Mass Exchange between Equal Mass Binaries. Consider two equal mass binary stars where the secondary binary has expanded and fills its Roche lobe. Its atmospheric gases can escape through the inner Lagrangian point and "fall" toward its companion. a. Solve for the path of a particular ttajectory that starts from rest just to the right of the inner Lagrangian point and plot its orbit. Determine the Jacobian constant and plot the path along with its zero-velocity contour. b. Increase the initial speed x' [0] until the orbit is exchanged from one primary to the other. Plot the orbit. Solution In[133]:= Clear ["Global ' *"] a. Let the initial conditions be x[0]=0.044, y[O]=O, x' [0]=0, y' [0]=0 and use the user-defined function PMotion to solve for the path: In[134]:= sol=pHotion[1/2, {o.o",", ,O,O,O}, 8, 1000] ; The coordinates for the test body are In[135]:= fx[t_] :=x[t]/.sol; fy[t_] : = y[t] / .sol; and the graphics for the path in the rotating frame follow from Mgraph 
412 Chapter 7 Orbiting Bodies In[136]:= pt1 = Mgraph[fx, fy, t, 8, P1otPoints -+ 100, Plot Style -+ Hue [0.8] , Epilog -+ {AbsolutePointSize [7], Point [ {O, O}] , Point [ {1/2, O}] }, Disp1ayFunction -+ $Disp1ayFunction] ; 0.2 0.3 0.1 -0.1 -0.2 -0.3 where the dot at the origin is the inner Lagrangian point and the other dot is the primary. The "falling" test particle approaches the primary from behind and then orbits the primary in a co-rotating path. The value of the Jacobian constant follows from In[13?] : = jacobi = C == - (x' [t] 2 + y' [t] 2) + 2 U; where U, rl, and r2 are given by 1-  1 ( ) In[138]:= Uru1e=U-+-+-+- X[t]2+ y [t]2 ; r1 r2 2 In[139]:= rrule = {r 1-+ ..j (+ x[t]) 2 + y[t] 2, r2 -+ ..j (-1 +  + x [t] ) 2 + y [t] 2} ; Evaluating the parameters, it follows that [ 4 ] ( . . 1 In 1 0:= Jacob1/.Uru1e/.rru1e/.- > 2/. y[t] -+ 01 .x' [t] -+ 01 .x[t] -+ 0.044 I.y' [t] -+ 0 ) [[2]] Out[140]= 4.03315 The plot of several zero-velocity contours near this value and the path for the test particle follow from 
7.3 Restricted Three-Body Problem 413 In[141]:= pt2 = ContourPlot [2 U 1 .Urulel .rrule/. -+ 1/211 Evaluate, {x [t] , -1, 1} , {y [t] , -0.5, 0.5 }, ContourShading -+ False, AspectRatio -+ Automatic, Contours -+ { 4.033, 3.9,3.5}, Plotpoints -+ 66, Epilog -+ ptl [ [1]]]; 0.4 -0.4 -1 -0.5 o 0.5 1 The inner contour is for C=4. 033. The matter spills through the inner Lagrangian point and spirals around the primary star if the star is sufficiently small so the orbit misses striking the primary's surface. The stteaming mass forms an accretion disk of hot gas in the orbital plane. However, around a "real" binary system the viscosity causes the orbiting gases to lose energy and slowly spiral toward the primary. The gas is heated throughout its descent as the lost orbital energy is converted into thermal energy. Finally, the plunging gas ends its journey at the star's surface. b. If the initial kinetic energy is sufficiently large the particle can escape from the pri- mary. If you set x [0] =0.044 and y' [0] =0.6, then the path follows from In[142]:= sOl=PMotion[1/2, {0.044 ,O,O.6,O}, 35,4000] ; The coordinates for the test body are In[143]:= fx[t_] :=x[t]/.sol; fy[t.] :=y[t]/.sol; The graphics for the path in the rotating frame follow from Mgraph, In[144]:= ptl = Mgraph[fx, fy, t, 35, Plotpoints -+ 100, Plot Style -+ Rue [0 .8] ]; The plot of the orbit, along with the enveloping zero-velocity contours, is 
414 Chapter 7 Orbiting Bodies In[145]:= pt2 = ContourPlot[ 2 U 1 .Urulel .rrule/. -+ 1/211 Evaluate, {x [t] , -1.1, 1.1} , {y [t] , -0.6, 0.6 }, ContourShading -+ False, AspectRatio -+ Automatic, Contours -+ {4, 3.6105, 3.5, 3.4,3.3}, Plotpoints -+ 66, Epilog -+ ptl [[1] ] ] ; The initial kinetic energy is sufficiently large so that the particle jumps in a "chaotic" fashion between the Roche lobes surrounding the two primaries. 7.3.2.1 . Problems on the Sun-]upiter System (j.l = .000954) . PROBLEM 5 Lagrangian Points for the Sun-Jupiter System. We seek the Lagrangian points and zero-velocity surface for the Sun-Jupiter System (j.l =0.000954). a. Make a contour plot of the zero velocity surface. b. The Lagrangian points follow from the solution of the two equations 0xU=O and OyU =0. Find the Lagrangian points and plot the results with the zero velocity surface. Solution In[146]:= Clear[nGlobal' * n] a. The potential and Jacobian integral are In[147]:= Urule=U-+ 1- ++(X[t]2+y[t]2); rl r2 2 jacobi = C == - (x' [t] 2 + y' [t] 2) + 2 U I.urule; The zero velocity curves follow from setting x' [t] and y' [t] to zero. Plotting the zero velocity contour lines for J1 =0.000954, you get In[148]:= rrule = {r l-+;/ ( + x[t]) 2 + y[t] 2 I r2 -+ ;/ (-1 +  + x [t] ) 2 + y [t] 2} ; 
7.3 Restricted Three-Body Problem 415 In[149]:= jacGJ = ContourPlot [ 20 I. Orulel .rrule/./J .... 0.00095411 Evaluate, {x[t], -1.2, 1.2}, {y[t], -1.2,1.2}, ContourShading .... False, Contours.... Range [3,3.05,0.01], Plotpoints .... 150 ] ; o .1 -0.5 o 0.5 1 1 0.5 .0.5 .1 The large white area represents the gravitational well around the Sun and the smaller circular area represents the gravitational well around Jupiter. b. The triangular Lagrangian points follow from the exact analytic expressions In[150]:= {L[5], L[4]} = {{X[t].... (1-2/J),y[t]....-  }, {X[t] ....(1-2/J),y[t]....  }}/. {/J .... 0.000954 } Out[150]= {{x[t] ....,0.499046,y[t]....,- V; }, {x[t] ...., 0.499046, y[t] ...., V; }} L [4] and L [5] are located 60 degrees ahead of and behind Jupiter. The collinear points, on the other hand, follow from setting y=O in the two equations 0xU=O and OyU=O: 
416 Chapter 7 Orbiting Bodies In[151]:= eq1 = D[U 1 .Urulel .rrule, x[t]] == 0/.  -+ 0.0009541 .y[t] -+ 0 eq2 = D[U I.urule/.rrule,y[t]] == 0/. -+0.000954/.y[t] -+0 0.000954(-0.999046 +x[t]) Out[151]= - + ((-0.999046 +x[t] )2)3/2 X[t] _ 0.999046(0.000954+x[t]) ==0 ((0.000954 +x[t] )2)3/2 Out[151]= True The only relevant equation is eql. Solving for x, it follows In[152]:= eq3 = FindRoot [eq1 [[1]] I.  -+ 0.000954/. Y [t] -+ 0, {x [t], #}] & I@ {1, 0 .9, -1 } Out[152]= {{x[t] .>1.06883}, {x[t] -> 0.932363}, {x[t] -> -1.0004}} The coordinates for L [ 1], L [2], and L [ 3] are In[153]:= {L[3],L[1],L[2]} = OUter[List,eq3, {y[t] -+O}]II FlattenIIPartition[#,2]& Out[153]= {{x[t] ->1.06883,y[t] ->o}, {x[t] -> 0.932363, y[t] -> O}, {x[t] -> -1.0004, y[t] -> O}} The coordinates for the complete set of Lagrangian points are In[154]:= JLpt=L[#]&I@Range[5]; JLpt IIColumnForm {x[t] -> 0.932363, y[t] -> O} {x[t] -> -1.0004, y[t] -> O} {x[t] ->1.06883,y[t] ->O} {X[t] -> 0.499046, y[t] -> } {x[t] -> 0.499046, y[t] -> - V; } Out[154]= The graphics for these points and the positions of the primary bodies follow from 
7.3 Restricted Three-Body Problem 417 In[155]:= Lgraph = Graphics [ {pointSize[0.02], {point [{/.I, O}], point[{ 1- /.I, O}]}, {pointSize[0.02],Bue[0.9], Map [Point, {x[t],y[t]}/.JLpt]}, Text[L., {x[t] ,y[t] +0.1}/. JLpt [[I]] ] & /@ Range [5] } ] /./.1 -+ 0.000954 ; Combining the Lagrangian points, primary positions, and zero velocity contours, you get In[156]:= Show [jacGJ, Lgraph]; 1 0.5 o -0.5 -1 The Trojan asteroids occupy the L [4] and L [5] equilibrium points. They are on the same orbit as Jupiter and either lead or ttail the planet by 60 degrees. These asteroids are located in the potential wells that are established by the combined influence of the Sun and Jupiter. . PROBLEM 6 Numerical Solution for the Trojan Asteroids. In the Sun-Jupiter system the Lagrangian points L [4] and L [5] are called Trojan points because the Trojan asteroid group are near these points. Consider those orbits that revolve around L [4] . Start the orbits with zero velocity and pick the initial {x, y} positions along the arc x=R Cos [0] and y=R Sin[O] whereR=   3+(1-2J1i. a. Pick 0 so the orbit encloses just L [4] . Plot the tadpole-shaped orbit and superimpose the zero-velocity contours on the graph. 
418 Chapter 7 Orbiting Bodies b. Pick 0 so that the orbit encloses L [4], L [ 2], and L [5]. Plot the horseshoe- shaped orbit. Solution In[ 157] : = Clear [ nGlobal' * n] a. Consider the bound motion near L [4]. Start the orbits with zero velocity and pick th e initial {x, y } positions along the arc x=R Cos [0] and y=R Sin [0] , where R=!  3 + (1 - 2J1)2 and 0 is arbittary. The initial conditions {x [0], y [0], x' [0] , Y' [On are: In[158]:= initial = {RCos [8], R Sin[8], 0, O}/. R- >  .y 3 + (1- 2jJ)2/ .jJ- > 0.000954 2 Out[158]= {0.999523Cos[e], 0.999523 Sin[e], 0, O} If you let 0 be 35 degrees, then the orbit follows from In[159]:= sol = PMotion[ 0.000953875, initial/.8 -+ 35 0 / /Flatten, 200,1000] ; Define the coordinates for the test body In[160]:= fx[t_] :=x[t]/.sol; fy[t_] :=y[t]/.sol; so the path about L [ 4] follows from In[161]:= ptl = Mgraph[fx, fy, t, 200, Plotpoints -+ 100, PlotStyle -+ Rue [0.8]] ; Let us combine the graphics for the orbit with the zero velocity contours and Lagrangian points. The rule for the potential and primary positions are l-jJ jJ 1 ( ) In[162]:= Urule=U-+-+-+- X[t]2+ y [t]2 ; rl r2 2 In[163]:= rrule = {r l-+.y (jJ +X[t])2 +y[t] 2, r2 -+ .y (-1 + jJ + X [t] ) 2 + y [t] 2 } ; and the graphics for the zero velocity contours follow from 
7.3 Restricted Three-Body Problem 419 In [164] : = j acGJ = ContourPlot [ 2 U 1 .Urulel .rrule/. -+ 0.00095411 Evaluate, {x[t], -1.2, 1.2}, {y[t], -1.2,1.2}, ContourShading -+ False, Contours -+ Range [3,3.05,0.01], Plotpoints -+ 150 , DisplayFunction -+ Identity]; The Lagrangian points are at In[165]:= JLpt = {{X[t] -+ 0.9324, y[t] -+ O}, {x[t] -+ -1.0004, y[t] -+ O}, {x[t] -+ 1.0688, y[t] -+ O}, {X[t] -+0.499,y[t] -+  }, {X[t] -+0.499,y[t] -+-  }}; so the graphics and text for these points become In [166] := Lgraph = Graphics [ {pointSize[0.02], {point [ {, O} ] , Point [ { 1 - , O}] }, {pointSize[0.02],Hue[0.9], Map[point, {x[t],y[t]}/.JLpt]}, Text[L., {x[t] ,y[t] +0.1}/. JLpt[[#]] ]&I@Range[5] } I. -+ 0.000954; Combining all the graphics and displaying the results, we get In[167]:= Show [jacGJ , pt1, Lgraph, PlotRange -+ {{ -0 .3, 1.2}, {O, 1.2}} , DisplayFunction -+ $DisplayP'unction] ; 
420 Chapter 7 Orbiting Bodies A close look at the tadpole path shows that it has short and long period terms. In[168]:= Show[ptl, PlotRange- > {{0.5, 0.85}, {0.55, 0.9}}, Ticks -+ False, DisplayFunction -+ $DisplayFunction] ; b. Consider orbits that enclose L [5], L [2] , and L [4] by decreasing the value of e. If you let e be 20 degrees then the orbit is In[169]:= sol = PMotion[ 0.000953875, initial/.8 -+ 20 0 / /Flatten, 200,1000] ; where the coordinates follow from 
7.3 Restricted Three-Body Problem 421 In[170]:= fx[t.] :=x[t]/.sol; fy[t.] :=y[t]/.sol; Combining the graphics for the path with the Lagrangian points, it follows from the user-defined function Mgraph that In[171]:= Mgraph[fx,fy,t,160, Plotpoints -+ 100, PlotStyle -+ Rue [ 0 . 8] , Epilog -+ Lgraph[ [1]], DisplayFunction -+ $DisplayFunctioD] ; 1 Dl : 0.5 -1 By changing the initial displacement, the path in the co-rotating frame goes from a tadpole-shaped curve to a horseshoe-shaped path. . PROBLEM 7 Perturbative Solution for the Trojan Asteroids. Consider a small dis- placement yyO+17Y[t] and xxO+17x[t], where {xO, yO} is the position of L [4] and 17Y[t] and 17x[t] are assumed to be small displacements. a. Show the restricted three-body equations reduce to the linear equations 3 3.y3 3.y3 -217Y'[t] + 17 x "[t] = 417X[t] + 417y[t] - TJ117Y[t] 3.y3 3.y3 9 +217 X '[t] + 17y"[t] = -17 x [t] - _ 2 J117x[t] + -17Y[t] 4 4 b. Solve the linearized equations and show for the Sun-Jupiter system that the L [4] point is stable. 
422 Chapter 7 Orbiting Bodies c. Show the Trojan orbits consist of two harmonics, one with a long period and the other with a short period. d. Consider a small displacement and plot the perturbative orbit. Compare the pertur- bative orbit with an equivalent numerical calculation. Solution In[172]:= Clear[nGlobal' * n] a. The distances from the primaries to the test body are In[173]:= rrule = {r l.....y (j,I +X[t])2 +y[t] 2, r2.... .y (-1+j,I+x[t])2 +y[t]2}; If you define the restricted three-body potential In[174]:= urule=U.... 1 -j,I ++ ( X[t]2+ y [t]2 ) ; rl r2 2 then the equations of motion become In[175]:= eqMotion= {x" [t] - 2 y" [t] == D[U/ .Urule/ .rrule, x[t]], y" [t] + 2 x' [t] == D[U/ .Urule/ .rrule, y[t]]}; etion// ColumnForm//TraditionalForm x" (t) - 2y' (t) == x(t) - /1(/1+x(t) -1) 2 2 3/2 ((/1+x(t) -1) +y(t) ) ( 1 -/1) (/1 + x(t) ) - ((/1 +x(t))2 +y(t)2)3/2 2 ' ( ) y" ( ) /1y(t) x t + t == - 3/2 ((/1+x(t) _1)2+ y (t)2) _ (l-/1 ) y(t) ( t ) 3/2 + y ((/1 +x(t))2 +y(t)2) Out[175]= Consider a small displacement about the L [ 4] point. Let In[176]:= pert = {y.... (yO + 17Y[#]&), x.... (xO + I7x[#]&)} ; where 17x[t] and 1JY[t] are assumed to be small displacements. The values of {xO,yO} are the coordinates for L [ 4] and are given by { 1 V3 } In[177]:= zeropt= xO.... 2 (1-2j,1),yO....T ; Expressing the equations of motion in terms of 17X[t] and 1JY[t], you find 
7.3 Restricted Three-Body Problem 423 In[178]:= eql = eqMotion/.pert; If you expand eql around 1]x[t] and 17Y[t] and keep only first order terms, you get In [179] := eqper = «MapAt[Series[#, {17X[t], 0, l}, {7JY[t] ,0, l} ] &:, eql [[#]] / .zeropt, 2] / /Normal / / ExpandAll) / . 17 X [t] 7JY[t] ... 0 )&:/@.{1,2}; eqper//ColumnForm , " 3 Tlx [t] 3. r::; 3 . r::; -2 TlY [t] + Tlx [t] == - + - -v3 Tly[t] - - -v3 J.1 Tly[t] Out[179]= 3 4 4 3 2 9T1y[t] 2 TlX' [t] + TlY" [t] == - Y3T1X[t] - - Y3J.1T1x[t] +- 424 These are the linearized equations for small displacements about the L [4] point. b. These linearized equations can be solved exactly. To simplify the results, assume initial conditions with zero initial velocity. The solution is In[180]:= perSol = {17 X [t], 7JY[t]}/. DSolve[ {eqPer,17X[O] == xi, 7JY[0] == yi, 17X' [0] == 0, 7JY' [0] == O}/ /Flatten, {17x[t], 7JY[t]}, t] / /Flatten; The output has been suppressed because it is too long. Inspecting the previous output, it is clear that the linearized equations contain two ex- ponential terms of the form Exp [,0,1 t] and Exp [,0,2 t], where ,0,1 and ,0,2 are given by In[181]:= {Ql, Q 2} = {- -  .yl- 27 /J + 27 /J2,  - +  .y l- 27 /J + 27 /J2}; For oscillatory or stable motion ,0,1 and ,0,2 must be purely imaginary. This is the case for Jupiter. In[182]:= {Ql, Q2}/./J'" 0.000954 Out[182]= {0.996757 i, 0.0804692 i} In fact, the motion is stable for J1 < 0.03852. c. The Trojan orbits are certainly stable and consist of a long and short period. The two frequencies are 
424 Chapter 7 Orbiting Bodies In[183]:= Abs[{Q1, Q2}/./l'" 0.000954] Out[183]= {0.996757, 0.0804692} If Jupiter's period is taken to be 11.86 years then these frequencies correspond to a short and long period. { 1 1 } In[184]:= 11.86 0.997 ' 0.0805 yrs Out[184]= {11.8957yrs, 147.329yrs} The oscillation with the long period is called a libration. d. Consider a small displacement about L [4], yyO+1])'[t] and xxO+1]x[t], where the value of {xO , yO} is In[185]:= zeropt/./l...0.000954 Out[185]= {XO...0.499046,YO...  } Assume the initial conditions for 1]x[O], 1].x'[0], 1])'[0], 1])"[0] are 0 . 0001, 0, 0.0001, 0, respectively. It follows that the perturbative solution x [ t] ,y [ t] is In[186]:= trojanpert = {0.499 +perSol[[l]], -..f3 } 2 +perSol[[2]] /. {xi... 0.0001, yi... 0 .0001}/. /l ... 0.000954/ /ExpandAll / / ExpToTrig / / Chop; trojanpert//Short[#,6]& Out[186]= {0.499 + 0.000307997Cos[0.0804692 t]- 0.000207997 Cos [0.996757 t] + 0.00893036 Sin[0.0804692 t]- 0.000720956 Sin [0.996757 t] , y'3 . ]} """2 + «5» + 0.000416031 Sl.n [0.996757 t where we displayed only a few of the terms. The plot of the path is In [ 187] : = pt 1 = parametricPlot [ trojanpert / /Evaluate, {t, 0, 80} ]; 
7.3 Restricted Three-Body Problem 425 This agrees fairly well with the numerical calculation. The equivalent numerical solu- tion follows from In[188]:= nSol=PMotion[0.000954, {0.499 +0.0001, v: +0.0001,0,0 }// Flatten, 80, 1000] ; The coordinates for the test body are In[189]:= fx[t_] :=x[t]/.nSol; fy [t_] : = y [t] / .nSol ; and the path about L [4] is In[190]:= Mgraph[fx, fy, t, 80, plotpoints ... 100, PlotStyle... {Hue [0 .8], Thickness [0.01], Dashing[{0.03}]}, Epilog... ptl [[1]], DisplayFunction ... $DisplayFunction ] ; 0.50250.505 0.862 where the dashed curve is the numerical solution and the continuous curve is the perturba- tion solution. 
426 Chapter 7 Orbiting Bodies 7.3.3 . Problems on the Earth-Moon System (p = .01215) . PROBLEM 8 Lagrangian Points for the Earth-Moon System. Consider the La- grangian positions for the Earth-Moon system (p =0.01215). The Lagrangian points, { L [ 1], L [2], L [3], L [ 4], L [ 5 J} follow from the solution of the two equations 0xU=O and OyU=O. a. Make a plot of the zero velocity surface. b. Use NDSolve to solve for the five Lagrangian positions: three collinear and two triangular. Superimpose the points on the zero velocity surface and plot the results. Solution In[191]:= Clear[nGlobal' * n] a. The zero velocity surface follows from the Jacobian integral 1-j.! j.! 1 ( ) In[192]:= Urule=U...-+-+- X[t]2+ y [t]2 ; r1 r2 2 In [193] := jacobi = C == -( x' [t]2 +y'[t]2) + 2 U /.Urule Out[193]= C==2 ( 1-11 +J::..+(X[t]2+y[t]2) ) _ r1 r2 2 x'[t]2 _y'[t]2 where C is the Jacobian constant. The values for r1 and r2 are given by the rule rrule, In[194]:= rrule = {r 1'" '" (j.! + x[t]) 2 + y[t] 2, r2 ... '" (-1 + j.! + x [t]) 2 + y [t] 2} ; The zero velocity curves follow from setting x' [t] and y' [t] to zero in jacobi. The plot of the zero velocity contour lines withp =0.01215 is In[195]:= jacGI!: = ContourPlot [ 2 U / .Urule/ .rrule/.j.! ... 0.01215// Evaluate, {x[t], -1.2, 1.2}, {y[t], -1.2,1.2}, ContourShading... False, Contours... Range [3, 3.55, 0.05], Plotpoints ... 150] ; 
7.3 Restricted Three-Body Problem 427 o -1 .0.5 o 0.5 1 The large white area represents the gravitational well around the Earth and the smaller oval-shaped area represents the gravitational well around the Moon. b. Let us solve for the five Lagrangian points withp = 0.01215. The positions follow from solving the two equations 0xU=O and OyU=O for x [t] and y [t]: In[196]:= eq1 = D[U / .Urule/ .rrule, x[t]] == 0 eq2 = D[U / .Urule/ .rrule, y[t]] == 0 Out[196]= x[t] _ J.1 (-1 + J.1 + x[t]) 3/2 ((-1+J.1+X[t])2+ y [t]2) (1-J.1) (J.1+x[t]) 3/2 == 0 ((J.1+X[t])2+ y [t]2) J.1y[t] Out[196]= y[t] - 3/2 - ((-1 +J.1 +X[t])2 +y[t]2) (l-J.1)y[t] --0 ( (J.1 + X [t]) 2 + y [t] 2) 3/2 -- The collinear Lagrangian points, {L [ 1] , L [2] , L [3] }, follow from setting y= 0 in eq1 and eq2. The only relevant equation is eq1. Setting y=O in eq1 and using Find- Root to get a solution for x, you get In[197]:= eq3 = FindRoot [eq1 [[1]] /.j.!'" 0 .01215 /. y[t]... 0, {x[t], I}]&: /@{1, 0.9, -1} Out[197]= {{x[t] .>I.15568}, {x[t] -7 0.836918}, {x[t] -7 -1.00506}} If you include the y=O values for these three x values, the coordinates for L[l], L [2], and L [3] are 
428 Chapter 7 Orbiting Bodies In[198J:= {L[l] I L[2] I L[3]} = OUter [List , eq3 , {y[t] -+ O} ]// Flatten//partition[#,2]& Out[198J= {{x[t] ..1.15568, y[t] -+ A}, {x[t] -+ 0.836918, y[t] -+ A}, {x[t] -+-1.00506,y[t] -+O}} The triangular Lagrangian points, L [4] and L [5] , were solved for the general case in a previous problem and are In[199J:= eq4 = {{X[t] -+ (1-2j,1)IY[t] -+-  }, {X[t] -+  (1- 2j,1) I y[t] -+  H; Evaluating L [4] andL [5] for J1 =0.01215, you get In[200J:= {L[4],L[5]) = eq4/.j,I-+ 0.01215 Out[200J= {{X[t] -+0.48785,y[t] -+- -; }, {X[t] -+0.48785,y[t] -+ -; }} L [4] and L [5] are stable points. An object placed at these points, 60 degrees ahead of and behind the moon at the radius of its orbit, will remain at the same point with respect to the moon. The complete set of Lagrangian points are summarized with LptE: In [201J : = Lptl!: = L [I] & /@ Range [5] ; Let us graph the Lagrangian points. The graphics follow from In[202J:= Lgraph = Graphics [ {pointSize[0.02] I {Point [{j,I, O}] I Point [{ 1 - j,I, O}] } I {PointSize[0.02]IEue[0.9], Map [point , {x[t],y[t]}/.Lptl!:]} } ] / .j,I-+ 0.01215; Combining the Lagrangian points with the Jacobian contours and displaying the results, you get In[203J:= Show [jacGl!:, Lgraph]; 
7.3 Restricted Three-Body Problem 429 o . -1 -0.5 o 0.5 1 . PROBLEM 9 Motion about L[4] in the Earth-Moon System. Consider a small dis- placement about the L [4] point, y  yO+1])'[t] and x  xO+ 1]x[t], where {xO ,yO} is the position of L [4] and 1])'[t] and 1]x[t] are assumed to be small. The linear three-body equations are 3 3Y3 3Y3 -21]y'[t] + 1]X"[t] = - 4 1]x[t] + -1]y[t] - -J11])'[t] 4 2 3Y3 3Y3 9 +21]x'[t] + 1]y"[t] = 41]x[t] - TJ11]x[t] + 41])'[t] The L [ 4 ] point is at xO = 0 . 48785 and yO = -V; . Consider an initial displacement 1])'[0]=0.0001 and 1]X[O] =0 . 0001 and plot the motion. Compare the perturbative orbit with the equivalent numerical calculation. Solution In[204]:= Clear ["Global , *"] The linear equations of motion expressed in terms of 1]x[t] and 1])'[t] follow from In[205]:= eqper = { - 2 TfY' [t] + 17X" [t] == 317 X [t] 3_1- - + -'v3(1-2j.1) TfY[t], 4 4 217X' [t] + TfY" [t] == 3_1- 9 TfY [t] } -v3(1-2j.1)17 X [t] +- ; 4 4 The solution of the linearized equations can be solved exactly (this takes a few minutes): 
430 Chapter 7 Orbiting Bodies In [2061 := perSol = {17x[t], 7JY[t]}/. DSolve[{eqPer, 17x[O] == 0.0001, 7JY[0] == 0.0001, TJX' [0] == 0, W [0] == O}/ /Platten, {17x[t], 7JY[t]}, t ] /./l ... 0.01215/ /Platten / / ExpandAll/ /ExpToTrig / / lifY / / Chop; We've suppressed the output as it is rather lengthy. The L [4] position {xO , yO} follows from In[2071:= zeropt = {xo...  (1- 2/l), yO...  }/. /l...0.01215 Out[2071= {XO...O.4878S,YO...  } so the perturbative solution is In[2081:= position = {xO, yO} + perSol/ .zeropt; We've suppressed the output as it is rather lengthy. The perturbative solution consists of a long and short period. The plot of the solution follows from In[2091:= pt1 = parametricplot[position//Evaluate, {t, 0, 80}]; Let us compare the perturbative solution with the equivalent numerical solution. The numerical solution follows from In[2101:= nsol=pMotion[0.01215, {0.U785+0.0001, ": +0.0001,0,0}// Platten, 80, 1000 ] 
7.3 Restricted Three-Body Problem 431 Out[210]= {x  InterpolatingFunction[ {{D., 80.}}, <>], y InterpolatingFunction[{{O., 80.}}, <>]} The coordinates for the test body are In[211]:= fx[t_] :=x[t]/.nSol; fy [t_] : = y [t] / .nSol ; so the path about L [ 4] is In[212]:= Mgraph[fx,fy,t,80, Plotpoints ... 100, PlotStyle... {Thickness [0.008], Dashing [{O .05}], Hue [0.8] }, Displayl!'Unction ... $DisplayFunction, Epilog... ptl [[1]] ]; The heavy dashed curve is the numerical calculation and the continuous curve is the perturbative solution. The two solutions are in good agreement. . PROBLEM 10 Orbit around the Earth and Moon. Consider a periodic orbit that ro- tates around both the Earth and the Moon. Choose the initial conditions to be xO=O. 8, vxO' =0, yO=O, and vyO=-1.14. Plot the orbit in the rotating and nonrotating frames. Solution In[213]:= Clear[8Global' *8] The Earth-Moon orbit with initial conditions xO=O. 8, vxO' =0, yO=O, and vyO= -1.14 is In[214]:= sol=PMotion[0.01215, {1.2,0,0,-1.5 }, 27\",3000] ; and the coordinates for the test body are 
432 Chapter 7 Orbiting Bodies In[215]:= fx[t_] :=x[t]/.sol; fy[t_] :=y[t]/.sol; The orbit for the test particle in the rotating frame is In[216] := ptl = Mgraph[fx, fy, t, 271", Plotpoints... 100, PlotStyle ... Hue [0 . 8] , DisplayFunction ... $Display1!'Unction ] ; and the curve in the inertial frame is -0.5 0.5 In[217]:= parametricplot[ {{ Cos[t], Sin[t] }, {fx [t] Cos [t] - fy[t] Sin [t], fx [t] Sin [t] + fy [t] Cos [t] }} / / Evaluate, {t,O, 271"}, PlotStyle... {GrayLevel [0.3], Hue [0 .6], Hue[0.9]}, AspectRatio ... Automatic] ; . 
7.4 Exercises 433 7.4 . EXERCISES The solutions to many of these exercises can be found at our web sites. 7.1 Central Force Problems A particle is acted on by a central force with a potential v=- ae;b' , where a and b are positive constants. (a) Use potential and phase diagrams to discuss the nature of the motion. (b) Find the solution for circular orbits. (c) Find the period for small radial oscillations about the circular motion. 7.2 Central Force Procedure Consider a particle acted on by a central force with potential V [r] . Write a procedure that: (a) Plots the potential. (b) Finds the extremum points. (c) Returns the solution for the circular orbits. (d) Finds the perturbative orbit for a small displacement around the circular motion. 7.3 Central Forces and Elliptical Solutions A particle is acted on by a central force where the potential is of the form v=ar 1 + n andn= {+5, +3, 0, -4, -5, -7}. (a) Plot the effective potential and discuss the motion. (b) Show that the solutions can be reduced to elliptical functions. (c) Expand the solution in a power series and compare the results with the power series that follows from the elliptical solutions. 7.4 Attractive Inverse Fifth Power Force Consider the motion of a particle described by a circular orbit under the influence of an attractive central force directed toward a point on the circle. (a) Show that the force varies as the inverse fifth power of the distance. (b) Show that for the orbit described the total energy of the particle is zero. (c) Find the period of the motion. (d) Find x' and y' as a function of angle around the circle and show that the quantities are infinite as the particle goes through the center of force. 7.5 Eccentric Anomaly Consider the expression for elliptical orbit r = 1I;::r that follows from a radial force f [r] =-. The eccentric anomaly rft is defined by r=a(l- e Cos [rft] ). (a) If w = '\ then show w t=rft- e Sin [rft] . -y;;;;;S (b) Showthattan[] =  tan[] (c) Expand rft in a series about e. (d) Show that rft = w t + 1:;:'=1 2Jn[neSin[wt] , where In is a Bessel function of order n. 7.6 Eccentric Anomaly Show that for elliptical motion in a gravitation al field the rad ial speed can be written as r' = wa..J a 2 e 2 -<r-af r 
434 Chapter 7 Orbiting Bodies Introduce the eccentric anomaly variable rft and show that the resulting differential equation in rft can be integrated immediately to give Kepler's equation. 7.7 Kepler Problem with Drag A uniform distribution of dust in the solar system adds to the Sun's gravitational attraction on a planet an additional radial force of the form - mer, where m is the mass of the planet, C is a constant, and r is the radius vector from the sun to the planet. This additional force is small compared to the direct Sun-planet gravitational force. (a) Calculate the period for a circular orbit of radius rO for a planet in this combined field. (b) Calculate the period of radial oscillations for slight disturbances from a circular orbit. (c) Show that nearly circular orbits can be approximated by precessing ellipses and find the precessional frequency. 7.8 Lagrange Points Show the points L [4] and L [ 5] are stable equilibrium points if Jl < o. 03852. 7.9 Orbit around the Sun and Jupiter Consider a periodic orbit that rotates around both Jupiter and the Sun. Set the initial conditions xO=1. 22, vxO '=O,yO=O, and vyO=-l. 012 and plot the orbit in rotating and nonrotating frames. 7.10 Exact Solution for the Three-Body Problem An example of a known exact three-body solution is that of three equal-mass objects orbiting in an equilateral triangular configuration with sides L under the attraction of their mutual gravita- tional field. Show that it is a solution if the rate of rotation is w 2 = 33 m . 
CHAPTER 8 Electrostatics 8.1 . INTRODUCTION Electtostatics is the basis of electtodynamics and is the study of time-independent distri- butions of charges and fields. Chapter 8 is divided into three problem sections: 8.2, Point Charges, Multipoles, and Image Charges, 8.3, Laplace's Equation in Cartesian and Cylin- drical Coordinates, and 8.4, Laplace's Equation in Spherical Coordinates. At the beginning of each section is an overview of the physics and a list of user-defined Mathematica proce- dures that are used in the section. Before you start the problems, the user-defined function found at the beginning of this chapter under Mathematica Commands for All Sections, and user-defined procedures listed at beginning of the individual sections, should be activated. Exercises are included in section 8.5. The problems in this chapter were chosen to illus- ttate Mathematica's analytic and graphic abilities when applied to vector and scalar field problems. The level of the problems is appropriate for the typical advanced undergraduate or beginning graduate student. The methods used to solve these problems are not unique. You are encouraged to find procedures that will illuminate the physics or to find other commands that speed up the calculations. When an infinitesimal electric charge experiences a force, we sayan electric field exists. The electric field is a vector equal to the force per unit charge acting  a positive charge placed  that point. !f an ar.!littary charge q is placed in an electric field E, it will experience a for F given by F = qE. The electric field is described by an irrotational vector field, V x E = O. A fundamental property of the electric field is described by Gauss's equation. If the charges lie interior to a closed surface S, then the total charge Q enclosed by S is relad to the electric field by {E . is = 41TQ. The differential form of Gauss's law is V . E = 41Tp, where p is the charge density. The electric field can also be expressed as an integral over the charge density: E = f dr'p(-;') q -!) . I r - r'I 3 It is often simpler to deal with scalar fields than with vector fields. The vector electric field -->. is related to a scalar potential by the equation E = - VU, where V is the gradient operator. In terms of a charge density, the scalar potential is !::..U = -41Tp. This equation is known as Poisson's equation. It follows that!::..U = 0 in a region in which the charge density is zero. This equation is called Laplace's equation. The problem of finding the potential 435 
436 Chapter 8 Electrostatics corresponds to that of finding the solution to either Laplace's or Poisson's equation that satisfy the boundary conditions for the problem. You may wish to turn off the spell checker before starting this chapter: In [1] : = Off [General: : spell]; Off [General:: spelll]; 8.1.0.1 . Mathematica Commands for All Sections VEPlot It is useful to create a user-defined procedure for those calculations that are used repeatedly in all three sections. You will find it useful to view the equipotentiallines (V) and the electric field lines (E) on the same plot. This procedure uses the command Plot- GradientField found in the package Graphics' plotGradientField'. Load the package In[2]:= Needs[nGraphics'plotField,n] and define the procedure VEPlot: In [3] : = VEPlot [potentiaL, xliDL, yliDL, opts__.] .- Module[{plotl,plot2}, plotl = PlotGradientField [-potential, xlim, ylim, ScaleFunction -+ (1&:), DisplayFunction -+ Identity] ; plot2 = ContourPlot [potential, xlim, ylim, Contour Shading -+ False, ContourSmoothing -+ True, DisplayFunction -+ Identity, Plot Points -+ 50] ; Show [ {plotl, plot2}, opts, DisplayFunction -+ $DisplayFunction ] ] ; VEPlot [potentiaL, opts__] : = VEPlot[potential, {x,-l.l,l.l}, {y, -1.1, 1.1}, opts] VEPlot graphs the electric field and equipotential surfaces. The range follows from xlim={x,a,b} and ylim={y,a,b}. The default for the range is {x, -1.1, 1.1} and {y, -1.1, 1.1}. Note that we plot the negative of the potential in plotGradi- entField so that the vector lines point in the direction that a positive test charge would move. VEPlot simply combines the plot of the equipotentiallines obtained from Con- tourPlot with the electric field obtained from PlotGradientField. It is not nec- essary to understand the details of this user-defined procedure until you have done all the problems; then you can go back and examine the procedure. To understand it in detail, go through the steps one at a time. Try to make the procedure more time-efficient, add default conditions, and add options to the procedure. Finally we apply Protect to the user-defined procedure to keep it from being deleted with Clear [ n Global' * n ] : In[4]:= Protect[VEPlot]; 
8.2 Point Charges, Multipoles, and Image Charges 437 . EXAMPLE 1 Equipotential Surface and Electric Field of Two-Point Charges. Con- sider the equipotential surfaces and electric field of a dipole: . 1 1 In [5] := d1pole = - ;  x2 + (_y_ )2  x2 + (_y)2 In[6]:= VEPlot[dipole, Epilog -+ {{Bue [0 .3], Disk [{O, 1/2}, 0 .1D, {Bue[0.95], Disk[{O, -112}, 0.1]}}]; / I . The top disk is the negative charge and the bottom disk is the positive charge. 8.2 . POINT CHARGES, MULTI POLES, AND IMAGE CHARGES 8.2.1 . Overview The specific formula for the potential created by a point charge is v= q , -V L:Z:! (xo(i) - xU»)2 where xo(i) are the Cartesian coordinates for the location of the charge and x(i) are the Cartesian coordinates for the field position. Arbittary charge distributions can always be represented by a sum of point charges. This superposition principle is used repeatedly in this section. A common method used to solve boundary value problems is to find an equivalent set of image charges. The method of images removes the boundaries and finds the positions and magnitudes of image charges that will match the value of the potential on the boundaries. 
438 Chapter 8 Electrostatics The solution for the potential is then the superposition of the potentials from the charges and image charges. A common problem in electrostatics is to determine the electric field due to a given surface distribution of charges. If a surface S has a surface-charge density of CT then ac- cording to Gauss's law, the normal component of the electric field is discontinuous. The discontinuity is related to the surface charge by the relation ( -) . ""it = 41TCT, where ""it is a unit normal ""it and where  and  are the electric fields on either side of the surface. 8.2.1.1 . Mathematica Commands for Section 8.1 It is useful to create user-defined procedures for those calculations that are used repeat- edly in this section. This section makes use of three user-defined functions: Monopole, TrigToY and TrigToP. Monopole A function to compute the potential of a charge is called Monopole: In[7]:= Monopo1e[q.: 1, rO.: {O, 0, O}, r_: {x,y, z}] := q/Sqrt [Sum [ (rO [[i]] - r [ [i]]) 2, {i, 1, Length[rO] }]] ; Monopole computes the potential at the field point {x, y, z} due to a point charge q located at position {xO, yO , z O}. This procedure works in two or three dimensions. The charge is defaulted at 1, the default position for the particle is at the origin, and the default position for the field point is {x, y, z }. . EXAMPLE 2 Consider a simple two-dimensional example with specified coordinates: In[B]:= Monopo1e[q, {xO,yO},{x,y}] Out[B]= q -V (xO - x) 2 + (yO _ y) 2 This is the potential at {x, y} due to a charge q located at {xO, yO}. We can repeat this ex- ample, taking advantage of the default coordinates {x, y}: In[9]:= Monopo1e[q, {xO,yO}] Out[9]= q -V (xO - x) 2 + (yO _ y) 2 A dipole is easily formed from two monopoles: In [10] : = dipole = (Monopole [+1, {O, 0, -a/2}] + Monopole [-1, {O, 0, +a/2}]) 1 1 Out [10] = 2 x2+y2+(_-zJ 2 x2+y2+(-zJ which is the superposition of the potentials from two point charges, one positive and one negative. 
8.2 Point Charges, Multipoles, and Image Charges 439 TrigToY In some cases it is insttuctive to represent a function £[0,4>] as an expansion in spherical harmonics. The following user-defined procedure TrigToY will expand £[0,4>] to order D in spherical harmonics: In[ll]:= TrigToY[expression_, terms_ : 2] := Module [ {e1, m, result}, result = Sum [Integrate [ (-1) - (m) * Spherica1HarmonicY[e1, -m, 9, ] * expression Sin [9], {9, 0, 1f}, {, 0, 21f}] * Y [e1, m, 9, ] , {e1, 0, terms}, {m, -e1, e1}]; Return [result] ] ; The user-defined operator TrigToY expands an expression of 0 and 4> to order D in spherical harmonics. Note that the orthogonality relation has been used: (2" (" Jo d4> Jo dB sin[O]Y* [t', m', 0, 4>]Y[t, m, 0, 4>] = of,f'0m.m' and the conjugate of the spherical harmonic is explicitly replaced using Y*[t, m, 0, 4>] = (-l) m Y[t, -m, 0, 4>] The default for the number of terms is set equal to 2. Specifically, f[O, 4>] = L a(t, m)Y[t, m, 0, 4>], where a(t, m) = l'br d4> l" dO sin [0] ( -1)mY[t, -m, 0, 4>]f[O, 4>], . EXAMPLE 3 Convert a simple trigonometric function cos[Of to spherical harmonics: In [12] := eq1 = Cos[9r2//TrigToY 2 4  Out[12]= - YTrY(O, 0, e, 1» + - - Y(2, 0, e, 1» 335 where Y denotes the spherical harmonic. You can verify that this conversion is correct by reproducing the original expression: In [13] : = eq1/ / . Y -+ Spherica1HarmonicY / / Simplify . Out[13]= Cos 2 (8) TrigToP It is often insttuctive to represent a function f(O) as an expansion in Legendre polynomials. The following user-defined procedure TrigToP expands f(e) to order n in Legendre polynomials: 
440 Chapter 8 Electrostatics In[14]:= Trig'l'op[expression_, terms_ : 2] .- Modu1e[{e1, result}, result = Sum [Integrate [Legendrep [e1, Cos [9]] * expression Sin[9], {9, O,]f}] * (2e1+l)/2 p[e1,Cos[9]], {e1,0,terms}]; Return [result] ] ; The user-defined operator TrigTOP expands an expression of 8 to order n in Legendre functions. The default value of the number of terms is 2. P denotes the Legendre polyno- mials. Specifically, f(8) = L: a(f)P[f, 8] where (2f + 1) l 1l: . a(f) = d8sm[8]P[f, cos[8]]f[8] 2 0 . Convert the simple trigonometric function sin[8]2 to Legendre polynomials: EXAMPLE 4 In [15] : = eql = Sin [9] 2 / /TrigTOP 2 2 Out[15]= 3P(O,COS(S)) -3P(2,COS(S)) Converting back to trigonometric functions, you get In[16]:= eql/ /.P -+ LegendreP/ /Sill\P1ify Out[16]= Sin 2 (S) Finally we apply Protect to the user-defined procedures to keep them from being deleted with Clear [nGlobal '* n]: In[17]:= Protect [Monopole, TrigToY, TrigToP]; . PROBLEM 1 Superposition of Point Charges. Consider the following charge distribu- tions: Linear Quadrapo1e +dl2 Square Quadrapole Triangle -d/2 +dl2 D +2q 0 -q +q l  V, l -dI2+dl2 
8.2 Point Charges, Multipoles, and Image Charges 441 1. A linear quadrupole: three charges on the z-axis with charge -q at Z = +dl2, charge -q at Z = -dl2, and charge 2q at Z = O. 2. A square quadrupole: two particles with charge -q at {dl2, 0, -dl2} and {-dl2, 0, dl2} and two particles with charge q at {dl2, 0, dl2} and {-dl2, 0, -dl2}. 3. Charges located on the corners of a triangle: charge -q at {+dl2, -0, -dl2}, charge -q at {-dl2, 0, -dl2}, and charge 2q at {O, 0, OJ. a. Compute the potentials for these charge distributions. Plot the square quadrupole potential in the y = 0 plane. b. Graph the linear quadrupole equipotentiallines and electric field lines in two di- mensions. Use ContourPlot to graph the equipotentiallines and PlotGradi- entField for the electric field. Verify the graph by using the user-defined function VEPlot. Use VEPlot to graph the remaining two charge distributions. c. Convert the potential from Cartesian to spherical coordinates and expand the poten- tial in powers . Express the results in terms of Legendre polynomials or spheri- cal harmonics using the user-defined rules TrigToP and TrigToY defined in the Overview of this section. d. As a final part of this problem, use PlotGradientField3D to make a three- dimensional vector plot of the linear quadrupole electric field. Remarks and Outline This problem inttoduces you to Mathematica's various graph- ics tools for visualizing electric and magnetic fields. The packages used in this prob- lem are: Graphics'plotField', Calculus 'VectorADalysis " and Graph- ics 'plotField3D'. Try using different functions for the ScaleFunction in the PlotField command. Experiment with different charge distributions and compare their potentials. Which ones falls off faster with increasing distance? Required Packages In[18]:= Needs[nCalculus'vectorAnalysis,n) Needs [nGraphics'plotField,n) Needs [nGraphics'plotField3D,n) Solution In[19]:= Clear [nGlobal ' * n); a. Consider the potential of a linear quadrupole due to the superposition of three-point charges located on a line. Assume that one particle has charge -q and is located at z=d/2 and the second particle has charge -q and is located at z=-d/2. The third particle is located at the origin and has charge 2q. The potential at r from a single charge located at rO is given by Monopole so the potential from the linear quadrupole is the superposition of three monopoles: 
442 Chapter 8 Electrostatics In[20]:= quad = (Monopo1e[2q, {O,O,O}]+ Monopo1e[-q, {O, 0, d/2}] + Monopo1e[-q, {0,0,-d/2}]) Out[20]= - q q 2q X2++ [--zr 2 x 2 + y2 + [  - z J +  X2 + y2 + Z2 Consider the potential due to the superposition of three-point charges located on the ver- tices of a triangle. Assume that one particle has charge -q located at { d/ 2, 0, -d/ 2} and the second particle has charge -q and is located at { -d/ 2, 0, -d/ 2}. The third particle is located at the origin and has charge 2q. The potential from the superposition of the three monopoles is In[21]:= triangle = (Monopo1e[+2q, {O, 0, O}]+ Monopole [-q, {+d/2, 0, -d/2}] + Monopole [-q, {-d/2, 0, -d/2}] ) ; Consider the potential due to the superposition of four-point charges located on the vertices of a square. Assume two particles each have charge -q and are located at {d/2, 0, -d/ 2} and { -d/ 2, 0, d/ 2}. Assume the final two particles each have charge q and are located at {d/ 2, 0, d/ 2} and { -d/ 2, 0, -d/ 2 }. The potential from the superposition of the four monopoles is In [22] : = square = (Monopole [+q, {+d/2, 0, d/2}] + Monopole [-q, {+d/2, 0, -d/2}] + Monopole [+q, {-d/2, 0, -d/2}] + Monopole [-q, {-d/2, 0, d/2} ] ) ; You can get a visual sense of these distributions by plotting the potential. Consider the square distribution and plot the potential in the y=O plane. In [23] : = P1ot3D[square /. {y -+ 0, q -+ 1, d -+ 1} , {x, -1, 1}, {z, -1, 1} ,AxesLabe1-+ {nx n , nzn, nn}]; 
8.2 Point Charges, Multipoles, and Image Charges 443 b. Consider the linear quadrupole potential and plot the electric field and the equipo- tentiallines. The electric field is obtained from PlotGradientField, found in the package Graphics \ PlotField \ already loaded at the beginning of the problem. Plot -quad in the {x, z} plane. Define the location of the charges In[24]:= charges = {{Hue [0 .3], Disk [ {O, 112}, O.l]}, {Hue[0.95], Disk[{O, O}, 0.2]}, {Hue[0.3], Disk[{O, -1/2}, 0.1]}}; and combine them with the plot of the electric field In [25] := pl = plotGradientField[ -quad/ / . {q -+ 1, d -+ 1, y -+ O} , {x, -1.1,1.1}, {z, -1.1,1.1} , ScaleFuDction -+ (lS:), Epilog -+ charges] ; / --.... ---........ /' / -:- "'... \, \  II / :_- _ '- I ". .---..- ", ' \ / / #"/-- '" ,- , / ./ / , -" '-. --  l / /' :;""- \. I /:- '" \ \ 1 \ \ I j I -- -- \ \ t j I ,,'- < \ \ (! I \,1/ '; 1/> ,, " --- -.  .. .-// - - ....--.... ---- . / #"/ / / ,/ I , \,', --.... --... /... -.... -- / I I / I I,  }1 \ \, , / I I ; \  #_ I I I 1 \ ;\ '" _/ / \:.: / / , i \ .,,--..--__/Ii\,,.-./II "'" ' ---.---/ ,, / ' / i \' '" " -...------ .#</ //  ------_.-¥'/ ' \" --------/ There is a charge -q at z=1/2, another charge -q at z=-1/2, and a third charge 2q located at the origin. Note that we plot the negative of the potential so that the electric vector points away from the positive change. The equipotentiallines (V) follow from ContourPlot, In[26] := p2 = ContourPlot [ quad/ / . {q -+ 1, d -+ 1, y -+ O}, {x, -1.1, 1.1}, {z, -1.1,1.1}, ContourShading -+ False, PlotPoints -+ 50, Displayl"unction -+ Identity ] ; We now overlay PlotGradientField and ContourPlot: 
444 Chapter 8 Electrostatics In[27]:= Show[pl,p2]; VEPlot simply does this same procedure in a single step: In [28] := VEPlot [quad/ /. {q -+ 1, d -+ 1, y -+ O}, {x, -1.1, l.l}, {z, -1.1, 1.1}, Epilog -+ charges]; For the triangle, you get: In[29]:= charges = {{Hue[0.3], Disk[{-1/2, -1/2}, D.l]}, {Hue[0.95], Disk[{O, O}, 0.2]}, {Hue[0.3], Disk[{1/2, -1/2}, O.l]}}; 
8.2 Point Charges, Multipoles, and Image Charges 445 In [30J : = VEPlot [triangle/. {q -+ 1, d -+ 1, y -+ O}, {x, -1.1, 1.1}, {z, -1.1, 1.1}, Epilog -+ charges]; Finally, the square quadrupole is In[31J:= charges = {{Hue[0.95], Disk[{-1/2, -1/2}, 0.1]}, {Hue[0.95], Disk[{1/2, 1/2}, 0.1]}, {Hue[0.3], Disk[{-1/2, 1/2}, 0.1]}, {Hue[0.3], Disk[{ 1/2, -1/2}, 0.1]}}; In [32J : = VEPlot [square/. {q -+ 1, d -+ 1, y -+ O}, {x, -1.1, 1.1}, {z, -1.1, 1.1}, Epilog -+ charges]; \. .... 
446 Chapter 8 Electrostatics c. Expand the potentials in the limit of large r. First, we define the rule for converting Cartesian coordinates to spherical coordinates. The relation between Cartesian and spher- ical coordinates is given by the command CoordinatesToCartesian found in the add-on package already loaded at the beginning of the problem. The rule for converting Cartesian coordinates to spherical coordinates is In[33]:= x2rRule = Thread [ {x, y, z} -+ CoordinatesToCartesian [ {r, EI, r/I}, Spherical]] Out[33]= {x-7rCos(<I» Sin(e),Y-7rSin(e) Sin(<I>Lz-7rCos(e)} Now we apply this rule to quad, and expand for large r to second order: In[34]:= seriesQuad = series [quad I I .x2rRule , {r, 00, 2}] I I Simpl ifyll Normal d 2 q (3 Cos(2e) +1) Out[34]= - 8 r 3 Alternatively, you can rewrite this as a Legendre polynomial using the user-defined function TrigToP defined in the Mathematica Commands at the beginning of this section: In[35]:= seriesQuad//TrigToPIISimplify d 2 qP(2, Cas (e)) Out[35]= - 2 r 3 Likewise for the square configuration: In [36] : = seriesSquare = series [square I I .x2rRule , {r, 00, 2}] I I Simplify II Normal 3 d 2 q Cas (e) Cas (<1» Sin (e) Out[36]= r 3 In[37]:= seriesSquarellTrigToYllSimplify d 2 N q (Y(2, -1, e, <1» -Y(2, 1, e, <1») Out[37]= r 3 Finally, for the triangle configuration you get: In [38] : = seriesTriangle = series[trianglell.x2rRule, {r,00,2}] II FullSimplifyllNormal d 2 q (6 Cas (2 <1» Sin 2 (e) + 3 Cas (2 e) + 1) 16 r 3 dqCos(e) Out[38]= r 2 
8.2 Point Charges, Multipoles, and Image Charges 447 In[39]:= seriesTriangle//TrigToY//Simplify Out[39]= 1 - 60 r 3 (dy'JTq (3 Y5 d (-16 Y(2, -2,9, cf» + 2 Y(2, 0,9, cf» + -I6Y(2, 2, 9, cf») - 40 Y3 rY(l, 0,9, cf»)) Note the triangle begins at order  because, unlike the two quadrupoles, it contains a dipole component. d. As a final example, use PlotGradientField3D to show the three-dimensional vector plot of the linear quadrupole electric field. This command is found in the add-on package Graphics' PlotField3D', already loaded at the beginning of the problem. To learn about the properties of PlotGradientField3D enter ?PlotGradient- Field3D. The graph is In [4 0] : = pI = PlotGradientField3D [ quad//. {q -+ 1, d -+ I}, {x, -1, I}, {y, -1, I}, {z, -1, I}, ScaleFunction -+ (1&), VectorHeads -+ True, Plotpoints -+ 6, BoxRatios -+ {I, 1, 2} , ViewPoint -+ {1.3, -2.4, I}]; . PROBLEM 2 Point Charges and Grounded Plane. Consider a point charge q at a dis- tance d from an infinite conducting plane that is grounded. The potential on the grounded conductor is zero. 
448 Chapter 8 Electrostatics L 8 1 d ."".. "" ........ a. Use the method of images to find the potential. The method of images removes the conductor and finds the position and magnitude of an image charge that makes the potential zero on the plane of the conductor. The potential is just the superposition of the potentials from the charge and image charge. b. Expand the potential in powers of  and find the leading-order term. Express the results in terms of Legendre polynomials using the user-defined rule TrigToP de- fined in the Overview. Find the electric field that follows from applying Grad to the potential. c. Find the induced charge density on the plane and verify that the total induced charge is -q. Make use of the fact that the induced charge is proportional to the normal derivative of the potential on the surface of the conductor. Plot the induced charge using ContourPlot. Remarks and Outline This is a basic boundary-value problem. It serves as a warm-up for the following problems that have more complex boundary conditions. Mathematica's ability to handle three-vectors as well as to compute gradients in different coordinate sys- tems enables you to solve this problem in a trivial manner. Using the symbolic integration, you can integrate the answer for the charge density to verify the total charge. Plot the charge density on the plane using ContourPlot. Viewing this plot, you can see that you obtained an answer that makes physical sense. This is always a powerful check of any cal- culation. Plot the potential field arising from the point charge and its image charge. Do the boundary conditions appear to be satisfied in the region of the conducting plane? Try the same problem for multiple charges. Apply ContourPlot to the charge density to see if the answer is plausible. Required Packages In[41]:= Needs["Calculus'VectorAnalysis'"] Needs ["Graphics'plotField'"] Solution In[42]:= Clear ["Global ' *"]; a. The potential on the grounded conductor is zero. Using the method of images, remove the plane conductor and find the position and magnitude of an image charge that makes the 
8.2 Point Charges, Multipoles, and Image Charges 449 potential zero at the conductor's position. On the basis of the problem's symmetty, the image charge must have magnitude -q and must be located at a distance d behind the plane. The total potential for the charge and image charge is the superposition of their individual potentials: In [43]:= dipole = (Monopole [+q, {O, 0, +d}] + Monopole [-q, {O, 0, -d}]) Out[43]= q - q ,j x 2 + y2 + (d _ z) 2 ,j x 2 +:? + (-d _ z) 2 The z=O plane has zero potential, since every point on the plane is equidistant from q and -q. To verify this conclusion, evaluate the potential at z=O: In[44]:= dipole/ .z- > 0 Out[44]= 0 b. Change from Cartesian to spherical coordinates and expand the potential in the limit of large r. The relation between the coordinates is given by the command Coordi- natesToCartesian found in the add-on package Calculus 'VectorAnalysis' and already loaded at the beginning of the problem. The rule for converting from Cartesian to spherical coordinates is In[45]:= x2rRule = Thread [ {x, y, z} -+ CoordinatesToCartesian [ {r, EI, I{>}, Spherical]] Out[45]= {x-+rCos(<t» Sin(9),y-+rSin(<t» Sin(9),z-+rCos(9)} Now apply this rule to dipole and expand for large r to second order: In[46]:= dipoleR = series [dipole/ / .x2rRule, {r, 00, 2}] / / Normal//Simplify Out[46]= 2 dq s (9) TrigToP is used to express the answer in Legendre polynomials: In[47]:= dipoleR//TrigTop 2dqP(1,Cos(9)) Out[47]= r 2 The electric field follows from applying Grad to dipoleR. In[48]:= efieldR = -Grad[dipoleR, spherical [r, EI, I{>]] ] { 4dqCOS(9) 2dqSin(9) } Out[48 = r 3 ' r 3 ,0 
450 Chapter 8 Electrostatics C. The induced charge density on the conductor is -1/ (411") times the normal derivative of the potential evaluated on the z=O plane: In[ 49J:= charge = -1/(4 7f) D[dipole, z] II.z -+ 0 dq ( ) 3/2 2 7T d 2 + x 2 + y'2 Out[49J= - It follows from Gauss's theorem that the total induced charge on the conductor must be -q. Integrating the charge density over the plane, you can verify this result: In[50J:= Integrate [charge, {y,-oo,+oo}, {x,-oo,+oo}] IIPowerExpand Out[50J= -q A ContourPlot of the induced charge on the conductor is In[51J:= ContourPlot [charge/. {d-+ 1, q-+ I}, {y, -1, I}, {x, -1, I}]; . PROBLEM 3 Point Charges and Grounded Sphere. Consider a point charge q located a distance d from the center of a grounded conducting sphere of radius a. q d ' . 
8.2 Point Charges, Multipoles, and Image Charges 451 a. Find the potential outside the sphere by removing the conductor and finding the position and magnitude of an image charge that makes the potential zero on the spherical surface. b. Expand the potential in a  series and find the electric field to this same order. Use the user-defined function VEPlot to graph the electric field and equipotentiallines in the y=O plane. c. Note that the induced charge is proportional to the normal derivative of the poten- tial on the surface of the conductor, so derive an expression for the induced charge density. Integrate the induced charge density over the surface of the sphere and show that the total induced charge is equal to the image charge. d. Plot the induced charge on a sphere's surface. Remarks and Outline This problem inttoduces the next level of complication for bound- ary value problems. However, the solution is again simple. By symmetty, the image charge must lie on a line connecting q and the center of the sphere. To get two equations for the unknowns, consider one point to be on the equator of the sphere nearest the charge and the second point on the equator farthest from the charge. The potential must be zero at these two points. You can use ParametricPlot3D to show the charge density induced on the sphere. From this, you can see that you obtained an answer that makes physical sense-a powerful check of the calculation. Required Packages In[521:= Needs[nCalculus'vectorAnalysis'"] Needs ["Graphics'plotField'"] Solution In[531:= Clear ["Global , *n]; a. To solve the problem using the method of images, remove the conductor and find the position dl and charge ql of an image that makes the potential zero on a sphere of radius a. You will need two equations to solve for {ql, dl}. The two equations follow from picking two points on the sphere: the point nearest the particle and the point farthest from the particle. Requiring the potential to be zero at these two points, you get { q ql In[541:= eql = - +  == 0, a+d a+dl -ad + al == o}; Solving these two equations for ql and dl, it follows that In[551: = imageRule = Solve [eql, {dl, ql}] / /EXpandAll/ /Flatten { a2 a q } Out[551= dl.... d' ql""-(1 
452 Chapter 8 Electrostatics The image charge has a value of (7) and is located at a distance  from the origin. The potential is the superposition of the potentials from the charge and image charge. The potential for a single charge is given by Monopole, so the superposition of the two charges is In[56]:= potential = (Monopole [q, {O, 0, d}] + Monopole [ql, {O,O,dl}])II.imageRule Out[56]= q ,j x2 +y2 + (d- Z)2 aq 2 d x2+y2+(_z) b. To expand the potential in powers of  you must first convert to spherical coordinates. You can relate Cartesian and spherical coordinates by using the command CoordinatesTo- Cartesian found in the add-on package Calculus 'VectorAnalysis'. The rule for changing to spherical coordinates is In[57]:= x2rRule = Thread[{x, y, z}- > CoordinatesToCartesian [ {r, 9, "'}, Spherical] ] Out[57]= {x->rCos(<t» Sin(e),y->rsin(e) Sin(<t»,z->rcos(e)} The potential in spherical coordinates is In[58]:= potentialR = potentialll .x2rRulellsilifY//EXpand Out[58]= q _ aq ,j d 2 - 2r Cas (e) d+r 2 d a 4 _ 2rCos(B ) a 2 +r2 d2 d Note that the potential on the sphere (r=a) is zero, as it should be: In[59] := potentialRI I.r -+ al Isiu\plify I I PowerExpand Out[59]= 0 You can expand the potential in powers of  by using the command Series: In[60]:= series [potentialR, {r,oo,2}] II Normal II Collect[#, {Cos[9],r, a}]6i: q_¥ + (d q -9) Cas (e) r r 2 Out[60]= The plot ofthe electric field and equipotentiallines in the y=O plane follow from VEPlot: 
8.2 Point Charges, Multipoles, and Image Charges 453 In[61]:= VEPlot[ potential/. {a -+ 0.2, d -+ 0.4, q -+ 1, y -+ O}, {x, -1, l}, {z, -1, l}, Epilog -+ {{Bue[0.3],Disk[{0, O.l}, O.OS]}, {Thickness [0.01], Circle [ { 0, O}, 0.2]} , {Bue[0.9S], Disk[{O, 0.4}, 0.1] }}]; "''-.' ", '. " \ t t ... \ \ -,..- --, -- '" " --- ----- ;//j: '. , \ , " " I i " \ " I i \ / " \ , \ ---- ---- \ / \ I  I " # I i \ , \ ! / \ i I i I , \ , I t ,  \ I i i \ , t ; I 1 , , \ / I i I j j I , t i , , \ \ \ , , The top disk is the positive charge and the bottom disk is the image charge. A circle has been placed at the position of the sphere. c. The induced charge density is -1/ (4JT) times the radial derivative of the potential evaluated at r=a. Taking the radial derivative of the potential, i.e., the electric field normal to the surface of the sphere, you get In [62] := chargedensity = ( -  D[potentialR, r] /. {r -+ a}/ / 4:11" Simplify/ /PowerExpand / /Simplify ) (a 2 _d 2 ) q 4alT (a 2 -2d coste) a+d 2 )3/2 Out[62]= To get the total induced charge, integrate the charge density over the surface of the sphere. In [ 63] : = totalcharge = :Integrate [chargedensity 2 :I1"a-2 Sin[a], {a, O,:I1"}] //Simplify 
454 Chapter 8 Electrostatics (a 2 _d 2 ) ( -J {a-d)2- -J {a+d)2)q Out[63]= - 2 -J (a - d) 2 d -J (a + d) 2 Caution: Using PowerExpand will give incorrect results because of the sign of the square roots. Note that d>a, so { 1 1 In [64] := rule = -+-, Y (a _ d) 2 -a + d '" (a - d) 2 -+ -a + d}; and the total induced charge is In [65] : = tota1charge / / . ru1e/ / PowerExpand / / Simplify aq d d. To plot the induced charge on a sphere, normalize the charge density so that it ranges from {O , 1} as e ranges over { 0, 27r}. Call this function gray and define it by Out[65]= In [66] := eMin = + (FindMinimum[+chargedensity/. {a -+ 1, q-+ 1, d-+ 2), {9, 1}]// First); BMax = -(FindMinimum[-chargedensity/. {a -+ 1, q -+ 1, d-+ 2}, {9, 1}]// First); gray[9_] = «chargedensity - eMin) / (BMax - eMin) /. {a -+ 1, q -+ 1, d -+ 2}) ; {eMin,BMax} Out[66]= {-O.238732, -O.00884194} Note how FindMinimum is used to determine the limits of the function so that you can map it onto the interval {O, 1}. Indicating the induced charge by the gray scale, the graph of the induced charge plotted on a spherical surface is In[67]:= radius = 1; parametricp1ot3D[ {radius Sin[9]Cos[] , radius Sin[9]Sin[] , radius Cos [9] , GrayLeve1 [gray [9] ]} , {9, 0, :If}, {, 0, 2:1f} , Lighting- > False , Axes- > False , Boxed- > False] ; 
8.2 Point Charges, Multipoles, and Image Charges 455 . PROBLEM 4 Line Charge and Grounded Plane. Consider a line with charge q per unit length located along the z-axis, in front of an infinite plane conductor that is located in the {XI z} plane and kept at zero potential. The potential from a single charged line parallel to the z-axis and located at x=x o and y=Yo is V [x, y] = -q Log [(x - xO)2 + (y - Yo)2 ] , where q is the charge per unit length. q L yO a. Use the method of images to find the potential and plot the equipotential surfaces in the plane of symmetty. Show that the Laplacian of the potential is zero. b. Find the induced charge. Plot the induced charge density on the plane. Show that integrating over the charge density gives a charge per unit length that equals the image charge per unit length. c. Find the electric field and use PlotVectorField to plot the electric field lines. Remarks and Outline Use the method of images to find the image line charge and reduce the problem to a superposition of two line charges. By symmetty, the image line is located behind the plane and has a charge per unit length that is the negative of the line charge. The equipotential surfaces follow from the user-defined function VEPlot. The plot of the induced charge follows from ContourPlot. The induced charge is proportional to the normal derivative of the potential evaluated on the conductor's surface. The electric field follows from the gradient of the potential. 
456 Chapter 8 Electrostatics Required Packages In[68]:= Needs[RCalculus'VectorAnalysis'R] Needs [RGraphics'PlotField'R] Solution In[69]:= Clear[RGlobal' *R]; a. The solution for the line charge and plane is equal to the superposition of a line charge at {x=O , y=yO} and a negative image line charge at {x=O , y= -yO}. The sum of the two line potentials is In [70] : = potential = -q Log [X2 + (y _ yO) 2] + qLog [X2+ (Y+YO)2]; The potential is zero on the plane (y=O), as it should be: In[71]:= potential//.y->O Out[71]= 0 Use VEPlot to graph the equipotential surfaces and the electric field lines in the plane of symmetty: In [72] : = VEPlot [potential/ /. (q -+ 1, yO -+ l), (x, -1.1, l.l), (y, -2, 2), Epilog -+ ( (Thickness [0.03] , Line[«-l.l, O), (1.1, O)}] }, (Hue[0.35],Disk[{O, -1), O.l]}, {Hue[O .95], Disk [ {O, 1}, 0.1]}}]; .......,'-\\ \! 111//// 
8.2 Point Charges, Multipoles, and Image Charges 457 The dark line is the infinite plane conductor. The disk at the top is the positively charged line and the image line is the bottom disk. The physical region is to the top of the plane conductor. Show that the Laplacian, found in the add-on package Calcu- lus 'VectorAnalysis " of the potential is zero. Out[73]= 0 In[73]:= Lap1acian[potentia1,Cartesian[x,y,z]]//Together b. The induced charge is proportional to the normal derivative at z = 0: 1 . In[74]:= charge = - 4 7f D[potent1a1, y] /.{y-+ O} qyO Out[74]= - 7T (x2 + y02 ) Plotting the induced charge on the plane, you get In[75]:= ContourP1ot [charge/. {q -+ 1, yO -+ 1}, {x, -2, 2}, {y, -2, 2}]; 2 2 1 o -1 -2 -2 The charge density is greatest just below the charged line. Integrate charge along the x-direction to get the induced charge per unit length: Out[76]= -q In[76]:= Xntegrate[charge, {x,-oo,+oo}] //PowerExpand C. Take the gradient of the potential to find the electric field, E = - VV: In[77]:= eFie1d = -Grad [potential, Cartesian [x, y, z]] / /Simp1ify 
458 Chapter 8 Electrostatics Out[77]= { 8 qxyyO (X2 + (Y_YO)2) (X2 + (Y+YO)2) , 2q (y-yO) 2q (y+yO) } - 0 x 2 + (y_yO)2 x 2 + (y+yO)2' The Grad operator is found in the add-on package Calculus 'VectorAnalysis'. The electric field lines in the z=O plane are In[78]:= PlotVectorField[ eField[ [{l, 2}]] 11.{c;[-+ 1, yO -+ l}, {x, -5, 5}, {y, 0, 3}, Plotpoints -+ 10, Scalel!'uI1ction -+ (1&) , AspectRatio -+ 8/10 , Prolog -+ { {Thickness [0.03], Line[{{-5, O}, {5, O}}] }, {Hue[O .95], Disk [ {O, 1}, 0 .2]}}]; , i , t / / , \ I x \ '. I / I , \ j " \ , / x I / \ I \ \ I I , \ I " \ \ I I I \ \ \ '. / , / I I , ,'x " \ \ \ , ! I \ \ \ , \ I , I ! I \ \ \ \ \ I I . PROBLEM 5 Multipole Expansion of a Charge Distribution. Consider the charge densities (a - r) ( . 7r ) PI = qo Sm(O) - 4 (a - r) P2 = qoe(a-rYaCos(O) a (a - r)2 . 2 . P3 = qoSm (O)Sm(24» a for r < a and Pi = 0 for r  a. 
8.2 Point Charges, Multipoles, and Image Charges 459 a. Use ContourPlot to make a two-dimensional plot of the charge densities. b. Find the multipole expansion for the potentials. The first two charge densities can be expanded in terms of Legendre polynomials, and the third in terms of spherical har- monics. To make the expansions, use the user-defined procedures MultipoleSH and Mul tipoleP given below in Remarks and Outline. c. Find the electric fields for the multipole expansions of the potentials. d. Plot potential contours and electric field lines of the multipole expansions using VE- Plot. In[79J:= Clear ["Global' *"]; Remarks and Outline This problem inttoduces the multipole expansion. Again, because it is simple for Mathematica to expand complex charge distributions into multipoles, you can experiment with more complex and realistic charge distributions than you could analyt- ically. Experiment with different charge distributions. Take a complex charge distribution of net charge + 1 and compare it with a point charge of + 1 as you increase the scale of the plot. Are the potential fields comparable in the limit r  oo? Repeat the exercise using a single dipole and then a collection of dipoles with random orientation. Compare the poten- tial field between a monopole, a dipole, and a quadrupole. Which one falls off faster with increasing radius? Is this consistent with the expansion in powers of r? Further, the ability to plot the vector field associated with the charge distribution will enable you to explicitly see why the leading terms in the multipole expansion yield the dominant characteristics of the charge distribution. Try using different functions for the ScaleFunction in the PlotField command, including the default function. Given a continuous charge distri- bution, you will find it useful to expand this in spherical harmonics. The two additional user-defined procedures needed for this problem are MultipoleSH and MultipoleP. (Note, these functions share similar elements with TrigToY and TrigToP). MultipoleSH The multipole expansion of a potential is   4JT q(f, m) ( rlimit ) ( V =   (2f + 1) r -;:- Y[f, m, 0, 4>]q[r, 0, 4>], (=0 m=-( where q(f, m) = Lrlimit ? dr L" dO sin [0] L2.Jr d4>( -1)mY[f, -m, 0, 4>]q[r, 0, 4>] The procedure MultipoleSH takes a charge distribution and returns a potential ex- panded to n terms in spherical harmonics denoted by Y [ 1 , m, 0, 4>] 
460 Chapter 8 Electrostatics In[80J:= MultipoleSH[distributioJL, rlimit_,JL] .- Module [ {q, V} , q : = :Integrate [ ( :Integrate [distribution r 2 , {r, 0, rlimit} ]) * (_1)10. Sin(9) Y;(9, 1/1), {9, 0, :If}, {I/I,O,2:1f}]; 4:1fq ( r1t ) 81 Y(el, m, 9, 1/1) v=sum [ , (2 el + 1) r {el, 0, n}, {m, -el, el} ]; Return[V]]; The radial extension of the charge density is given by rlimit. To covert to trigono- metric functions let YSphericalHarmoDicY. The number of terms in the Multi- poleSH increases dramatically with larger values of I-terms, so the calculation time be- comes prohibitively large. To see how it works consider the charge distribution [ ] Q (r - a) Sin 2 (9) sin 2 (1/1) In 81 : = density = a 4 ; for r<a and zero for r>a. With the number of terms equal to 2, the potential expanded in spherical harmonics is In[82J:= MultipoleSH[density,a,2]//Simplify//Apart Out[82J=  3 ( a 2 7T3/2 Q ( ..[6 Y(2, -2, e, ct» + 2 Y(2, 0, e, ct» + 45 5 r )) 27T3/2 Q Y ( 0 ° e "' ) ..[6Y(2,2,e,ct» - 9; , , '" This procedure is slow because of the number of integration variables and the number of terms in the sum. MultipoleP If the charge distribution is axially symmetric, then you can expand the po- tential over Legendre polynomials. The specific formula is v =   q(f, m) ( rlimit ) f P[f, 0], ft  (2i+1) r r where q(f) = 27r LTlimit ? dr L" dB sin[O]Y[f, -m, 0, tfJ]q[r, 0]. 
8.2 Point Charges, Multipoles, and Image Charges 461 The procedure mu1tipo1eP takes a charge distribution that is expressed in spherical coordinates {r, e, o} (symmetric in l/J) and returns a potential. The result is expanded to D terms in Legendre polynomials denoted by P [e1, Cos [0] ] . In[83]:= MultipoleP [distribution_I rlimit_ 1 n_] .- Module [ {q, pot} I q : = :Integrate [ 2:1f * (:Integrate [distribution r-2 ,  {r , 0 , rlimit}]) * _I- 2-V:lf LegendreP[el , Cos[9]] * Sin[9] I {9 I 0 I :If} ] ; pot = SUm[ ( 2  2 e: + 1 .y7t q ( rli:t r 1 P (el, Cos (9) ) ) I {el, 0 In} ] ; Return[pot]]; The radial extension of the charge density is given by r1imit. To convert to trigono- metric functions let PLegendreP. To see how it works, consider the charge distribution given by Q (r - aCos 2 (9» In[84]:= density = 4 a for r<a and zero for r>a. The potential expanded in Legendre polynomials is In [85] := eql = MultipoleP[density, a , 2] 5lTQP(0, Cos (e)) 8a 2 lTQP(2, cos(e)) Out[85]= - 3 9 r 45 r The same calculation using Mu1tipo1eSH takes longer: In[86]:= eq2 = MultipoleSH[density, a , 2] 10 lT 3 / 2 Q Y ( O 0 e "' ) 16 a 2 lT 3 / 2 Q Y ( 2 0 e "' ) Out[86]= ' , , ." - ' , , ." 9 r 45 -f5 r 3 They both agree with each other, as can be verified by reducing the expressions to trigono- metric functions. In [87] : = eql == eq2/ /. {P -+ LegendreP I Y -+ SphericalHarmonicY} / / Simplify Out[87]= True 
462 Chapter 8 Electrostatics Required Packages In[88J:= Needs[nCalculus'VectorAnalysis,n] Needs [nGraphics'plotField'D] Solution a. The Ihree charge distributions are qO (a-r) (Sin(9) - i) In [89J := chargeDensityl = 4 ; a e¥ qO (a-r) Cos(9) chargeDensity2 = a 4 ; qO (a - r) 2 Sin 2 (9) Sin (21/1) chargeDensity3 = a 5 To change from spherical coordinates to Cartesian coordinates (so you can use Contour- Plot), define In[90J:= r2xRule = Thread[{r, 9, I/I}- > CoordinatesFromCartesian [ {x, y, z}, Spherical] ] Out [90J = {r -7 --J x 2 + y2 + z2, e -7 Cos. 1 [ Z ] , ct> -7 Tan. 1 (x, y) } --J x2 + y2 + z2 Choose the values In[91J:= values = {qO-+l,a-+l}; and plot chargeDensityl in the yO plane: In[92J:= ContourPlot[ chargeDensityl/.r2xRule//.values/. {y-+ O}, {x, -1,1}, {z, -1,1}, Plotpoints -+ 40]; 
8.2 Point Charges, Multipoles, and Image Charges 463 -0.5 o 0.5 1 Likewise for chargeDensity2, choose the yO plane: In[93]:= ContourPlot[ chargeDensity2/.r2xRule//.values/. {y-+ O}, {x, -1,1}, {z, -1,1}, Plotpoints -+ 40]; For chargeDensity3, choose the zo plane: In[94]:= ContourPlot[ chargeDensity3/.r2xRule//.values/. {z -+ O}, {x, -1, 1}, {y, -1, 1}, Plotpoints -+ 40]; 
464 Chapter 8 Electrostatics b. Applying Multipolep to chargeDensityl, you get the leading-order term of the multipole expansion: In [95] := multi1 = MultipoleP[chargeDensity1, a, 2] a 2 Jr2 qO P(2, Cas (B)) Out[95]= - 96 r3 Applying MultipoleP to chargeDensity2, you get In [96] := multi2 = MultipoleP [chargeDensity2, a, 2] / /Slify 4 a (-11 + 4 e) Jr qO P (1, Cas (B) ) Out[96]= - 2 3r For chargeDensity3, you must use MultipoleSB, since this charge density is not symmetric in ifJ. In [97] := multi3 = MultipoleSH[chargeDensity3, a, 2] //Simplify 4 i {l; a 2 Jr 3 / 2 qO (Y(2, -2, B, c/J) - Y(2, 2, B, c/J)) Out[97]= 75 r 3 C. The electric fields follow from E = -VV. In spherical coordinates, In[98] : = el"ield1 = - Grad [multi1, Spherical [r, 9, 1/1]] Out[98]= { _ a2qOP(2,Cas(B)) 32 r 4 ' a 2 Jr2 qO Sin (B) p(O,l) (2, Cas (B)) O } 96 r 4 ' Or, evaluating the Legendre polynomials explicitly, 
8.2 Point Charges, Multipoles, and Image Charges 465 In[99]:= eFieldl/ / . P -+ LegendreP / / SiJllplify { _ a2Jr2qO (3 Cos(2e) +1) a 2 Jr2qO Sin(2e) } 4 ' 4 ' 0 128 r 64 r Out[99]= Similarly, you compute the electric field for the second distribution as follows: In[lOO]:= eField2 = - Grad [multi2, Spherical [r, e, 1/1]] / /. P -+ LegendreP / / Simplify { _ 8a (-11+4e) JrqO coste) 3 r 3 ' 4a(-11+4e)JrqOSin(e) } 3 ' 0 3r Out[lOO]= and for the third distribution: In[lOl]:= eField3 = -Grad[multi3, Spherical [r, e, 1/1]]; eField3 / . {Y -+ SphericalHarmonicY} / / ExpTOTrig//Simplify { 2a 2 Jr q OSin 2 (e) Sin(2ct» 25 r 4 ' 8a 2 JrqOcos(e) Cos(ct» Sin(e) Sin(ct» 75 r 4 _ 4 a 2 JrqO Cos (2 ct» Sin (e) } 75 r 4 Out[lOl]= d. Next, use VEPlot to display the potential contours and electric field lines of the multipole expansions. For the first potential, convert to Cartesian coordinates, make Leg- endrep and SphericalBarmonicY explicit, and substitute the values. Finally, set yO to project to the plane and replace z by y, since VEPlot uses the variables {x,y}. In[102]:= potl = multil/.r2xRule/. {P -+ LegendreP, Y -+ SphericalHarmonicY} / .values/. {y -+ O} / / Simplify Out[102]= Jr2 (x2 - 2 z2 ) ( ) 5/2 192 x 2 + Z2 The plot of the potential contours and electric field lines is In[103]:= VEPlot[potl, {x, -1.1, 1.1}, {z, -1.1, 1.1}]; 
466 Chapter 8 Electrostatics '0...,",- / .1'/ / ....... ...... Likewise for the second distribution. In[104] := pot2 = multi2/.r2xRule/. {P -+ LegendreP, Y -+ SphericalHarmonicY} / .values/. {y -+ O} 4 (-11+4e)7rz Ou t [104] = - ( ) 3/2 3 x 2 + Z2 In[105] : = VEPlot [pot2, {x, -1.1, 1.1}, {z, -1.1, 1.1}] ; ---- ........ --.... For the third distribution, we plot in the {x, y} plane. 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 467 In[106]:= pot3 = multi3/.r2xRule//. {P -+ LegendreP, Y -+ SphericalHarmonicY} / / . values / . {z -+ O} //l'ullSimplify Out[106]= 47rxy ( ) 5/2 75 x2 +y2 In[107]:= VEPlot[pot3]; 8.3 . LAPLACE'S EQUATION IN CARTESIAN AND CYLINDRICAL COORDINATES 8.3.1 . Overview of Cartesian and Cylindrical Coordinates Many electtostatic problems involve boundary surfaces on which either the potential or a surface-charge density is specified. These problems reduce to a solution of Laplace's equation. In many coordinate systems the solution of Laplace's equation can be expressed as a product of three terms, each of which is a function of only one coordinate. The solution becomes a superposition of these products. The coefficients in the expansion follow from the boundary conditions and the orthogonality properties of the separation functions. In this section we consider Laplace's equation in Cartesian and cylindrical coordinates. The solution of Laplace's equation in Cartesian coordinates can be represented as a product of three functions: X[x], Y[y], and Z[z]. The functions are of the form X[x] = {Sin[ax], Cos[ax]} Y[y] = {Sinfj3y], Cosfj3y]} Z[z] = {e+ YZ , e- YZ } 
468 Chapter 8 Electrostatics where a 2 +/p = r. Note that these equations only appear to be nonsymmetric. Substituting y  iy makes the equation for Z[z] a trigonometric equation. Likewise, substituting a  ia makes the equation for X[x] an exponential equation. In cylindrical coordinates, the solution of Laplace's equation can be expressed as a product of R[r], <1>[<,&], and Z[z]. These functions are of the form: { ae+kz + be- kz for k * 0 Z[z] - - a + bz for k = 0 { aJ[n, kr] + bnN[n, kr] for k * 0 R[r] = (an"" + bnr- n ) + (a o log[r] + b o ) for k = 0 <1>[<,&] = (c n cos[n <,&] + d n sin[n <,&J) + (c o <'& + do) . PROBLEM 1 Separation of Variables in Cartesian and Cylindrical Coordinates. Consider the separation of variables for Laplace's equation in Cartesian and cylindrical coordinates. a. Assume the potential in Cartesian coordinates can be expressed in the form V x [x] V y [y]  [z] . Apply the Laplacian to this product and set it to zero to get Laplace's equation. Separate the functions by grouping terms with the same variable. Set these terms equal to separation constants and get ordinary differential equations. Solve the equations for each separation function. b. In cylindrical coordinates, assume the solution of Laplace's equation can be ex- pressed in the form R [r] P [<,&] Z [z]. Apply the Laplacian to this product and set it to zero. Separate the variables and solve the ordinary differential equation for each function. Required Packages In[10Bl:= Needs["Calculus'vectorADalysis'"] Solution In[109 l:= Clear [nGlobal' * "]; a. Assume the potential is of the form Vx [x] Vy [y] Vz [z] , In [110l := potential = VX[x]Vy[y]vz [z]; Set the coordinates to Cartesian (found in the package Calculus 'VectorAnalysis'), In[iiil:= SetCoordinates[Cartesian[x,y,z]]; and apply the Laplacian to this product 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 469 In[112]:= lapEq = Laplacian [potential] Out[112]= Vy(y) Vz(z) Vx"(x)+ Vx(x) Vz(z) Vy"(y) +Vx(x) Vy(y) Vz"(z) The equation for the potential follows from setting the Laplacian of the potential (lapEq) equal to zero. Note that we do not actually set the Laplacian equal to zero at this point as it is simpler to deal with the expression without putting them into equation form. If you divide lapEq by Vx [x] Vy [y] Vz [z] , then you get lapEq In[113]:= eq1 = [ ] [ ] II Expand VX x Vy y Vz[z] Vx" (x) Vy" (y) Vz" (z) Out[113]= - + - + - vx(x) Vy(y) Vz(z) The Laplacian separated into terms that depended on only one variable. The terms are In[114]:= eq2 = eq11 .plus -+ List { VX" (x) Vy" (y) Vz" (z) } Out[114]= Vx(x) , Vy(y) , Vz (z) You get three differential equations by equating each group of terms with the same variable equal to a separation constant, fieldEQ: = eq2 == { - ex 2 , -ey2, Cz 2 }IIThread { VX"(X) __ 2 vy"(y) __ Vz"(z) __ 2 } - -- -Cx , -- -cy2, - --Cz Vx(x) Vy(y) Vz (z) In[115] := Out[115]= To satisfy Laplace's equation, the constants must add to zero, i.e., Cz 2 = cx2 + Cr. The solutions are of the form In[116]:= MapThread[DSolve, {fieldEq, {VX[x],Vy[y],Vz[z]}, {x, y, z}}, 1] II Flatten IIColumnl'o:rm Out[116]= Vx(x) ....c 1 Cas (Cxx) +c 2 Sin(Cxx) Vy (y) -7 c 1 Cas (Cyy) + c 2 Sin (Cyy) Vz (z) -7 e Cz Z c 1 + e. cz Z c 2 Laplace's equation is a superposition of products of these terms. The unknown constants follow from the boundary conditions. b. Consider the solution of Laplace's equation in cylindrical coordinates. Assume the potential is oftheform R[r] P [4>] z [z], In[ll7] : = potential = R [r] P [1/1] Z [z]; Set the coordinates In[118]:= SetCoordinates[Cylindrical[r,l/I,z]]; 
470 Chapter 8 Electrostatics and apply the Laplacian to this product, In[119]:= lapZq = Laplacian [potential] / /Zxpand P(cjJ) Z(z) R'(r) R(r) Z(z) P"(cjJ) r + r 2 + P(cjJ) Z(z) R"(r) +P(cjJ) R(r) Z"(z) Out[119]= The equation for the potential follows from setting the Laplacian of the potential (lapEq) equal to zero, which we do at a later time. The z-variable separates if you divide lapEq by R[r] P [(,b] Z [z]: lapzq In[120]:= eql = //Expand// R[r] P [1/1] Z [z] Collect [I, r] &: R' (r) P" (cjJ) R" (r) Z" (z) Out[120]= rR(r) + r2 P(cjJ) +  +  An equation for z [ z] follows from selecting terms that are not Free of z and setting them equal to a separation constant Cz 2 : In[121]:= zZq = Select [eql, (ll"reeQ[#, z])&:] == +Cz-2 Out[121]= Z" (z) == Cz2 Z (z) For Cz 2 *0 the solution is of the form In[122]:= DSolve [zZq, Z [z], z] / /l"latten Out[122]= {Z(Z) ->eczzcl+e.czzc2} and for Cz 2 =0 it is In[123]:= DSolve [zzq/ .Cz -+ 0, Z [z], z] / /l"latten Out[123]= {Z(Z) ->C 1 +ZC 2 } You now must separate the (,b and r variables. You first reduce the Laplacian to only two variables {(,b, r} by replacing the z-terms in eql with the separation constant Cz 2 : In[124]:= eq2 = eql/.{zzq/.zqual-+Rule} 2 R' (r) P" (cjJ) R" (r) Out[124]= Cz + - +  +- rR(r) r P(cjJ) R(r) The separation of the (,b variable follows from multiplying eq2 with ,2: In[125]:= eq3 = r 2 eq2//Expand R" (r) r 2 R' (r) r P" (cjJ) Out[125]= Cz 2 r 2 + + - +- R(r) R(r) P(cjJ) r Set the (,b-terms equal to another separation constant -C(,b2: 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 471 In[126]:= I/IEq=Select[eq3, (!FreeQ[#,I/I])fc] ==_CI/I2 Out[126]= P" (cjJ) == _CcjJ2 P(cjJ) For Op2*O the solution for P [<,b] is of the form, In[127]:= DSolve[I/IEq, p[l/I] ,I/I]//Flatten Out[127]= {P(cjJ) ->C 1 Cos(CcjJcjJ) +C 2 Sin(ccjJcjJ)} and for C<,b2=O, it is In[128]:= Dsolve[l/Izq/.cI/I2-+ 0 , P[I/I] ,1/1] //Flatten Out[128]= {P(cjJ) ->C 1 +cjJC 2 } Finally, replace the <,b-term in eq3 with the separation constant C<,b2 and reduce the Laplacian to only one variable In[129]:= eq4 = eq3/. (I/IZq/ .Zqual-+ Rule) r R' (r) r 2 R" (r) Out[129]= _CcjJ2 + Cz 2 r 2 + - + R(r) R(r) We are now ready to set the Laplacian to zero to get Laplace's equation. Setting eq4 to zero and solving for R [r] , it follows for Cz 2 *O that, In[130]:= DSolve[eq4 == 0, R[r], r] / /Flatten Out[130]= {R(r) ->Jc<p(Czr) c1+YC<p(Czr) c 2 } and for Cz 2 =O the solution is, In[131]:= (DSolve[eq4 == O/.Cz-+O,R[r],r]// Flatten)/.C[l] -+A+B/. C [2] -+ I (A - B) / / FullSiJllplify Out[131]= {R(r) ->Ar.C<P+BrC<P} . PROBLEM 2 Potential in a Rectangular Groove. Consider a rectangular groove that runs from z = -00 to +00 and is open in the positive y-direction. The groove is bounded by two parallel walls at x = 0, x = a, and at the y = 0 end. The walls at x = 0 and x = a are at zero potential and the end is at a specified potential V[x] that is independent of the z- coordinate. The boundary conditions suggest that the potential is independent of z. Express the potential as a superposition of products X[x]Y[y], where X[x] = {Sin[ax], Cos[ax]} and Y[y] = {e+ YY , e- YY }. The relation between the separation constants is a 2 = y2. a. Express the expansion coefficients as integrals over the potential X[x] given on the y = 0 end. 
472 Chapter 8 Electrostatics V(O,y,z)=O V(a,y,z)=O 00 I, 0 y 0 .. . a x x V(x,O,z)= V(x) b. Let X[x] = Sin[x] and write the first few terms of the potential. Plot the potential using the command Plot3D. Use the user-defined command VEPlot to plot the equipotential and electric field lines. c. Let X[x] = VO and sum the series to get an exact solution. Plot the potential using Plot3D. Solution In [132] : = Clear [DGlobal' * D] ; a. The potential can be expressed as a product of two functions X [x] and Y [y] where X [x] ={Sin[ax], Cos [ax]} and y[y] ={e+YY, e- YJ } and a 2 = y.. In orderfor the potential to vanish on the parallel sides at x= 0 and x=a the X [x] term must be of the form X [x] =Sin [1T m xl a], where m takes on integer values {1, 2, . . . }. The Y [y] term must vanish as yoo so Y [y] = e- 1f myla. The potential is a superposition of these terms. n IA[m] sin [ 1T :X J e-1fmyla m=l The coefficients A [m] are determined from the potential V [x] on the y= 0 end. At y= 0 the potential reduces to n V[x] = IA[m] sin [ 1T :X J m=l This is just a Fourier sine series and the orthogonality properties of Sin allows you to invert this equation and get an expression for A [m] . 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 473 2 fa [ mnx ] A [m] =  Jo V[x] sin ---;;- dx The coefficients A [V, m] follow from In[133]:= A[V_,DL].- (2/a) :Integrate[V Sin[7f m x/a], {x,O,a}]; where V is the potential on the y=O end. It follows that the user-defined function for the potential is In [134] : = pot [V_, n_] : = [  ( m7fx ) ] Sum A[V, m] e- a Sin -a ' {m, 1, n} ; The function pot [V, n] ensures that the potential vanishes at x={ 0, a} and reduces to V on the y=O end. The operator pot works only for those cases when the integral for A can be done analytically; otherwise, Integrate must be replaced by NIntegrate. b. Consider the case where the potential on the end of the groove is V [x] =Sin [x] . Substitute Sin [x] into Pot [V, n] . The first few terms of the potential (n=3) are In[135]:= pot [Sin[x],3] 2 e -!If ( a 2 S(':.) + a 2 S() ) sin ( lTa X ) Out[135]= + a .1.= 2 e. a ( - a Sin (a) _ a Sin (a) ) Sin ( 2lT a X ) 2 (2 IT.a) 2 (a+2 IT) + a .1.= 2 e. a ( aSin(a) + aSin(a) ) Sin ( 3lT a X ) 2 (3 IT.a) 2 (a+3 IT) a To see this visually, let a=l and n=30. If you apply Plot3D to pot then the potential graph in the {x, y} plane is In[136]:= Plot3D[pot [Sin[x], 30] /.a -+ 1/ /Evaluate, {x, 0, 1}, {y, 0, 0.5}, AxesLabel -+ { X , Y , v } ] ; 
474 Chapter 8 Electrostatics The potential vanishes at x={ 0, a} and on the y=O end the value of the potential rises as SiD [x] . Next, to save time set D=15 and graph the equipotentiallines and electric field lines using VEPlot. In[137]:= pot15 = pot[Sin[x],15]/.a-+ 1; In [138] := VEP1ot[pot15, {x, 0, 1}, {y, 0, 0.5} ]; , The solution at y=O and near x=l comes closer to the prescribed boundary condition as you increase the number of terms in the series. c. The example in which V [x] =VO can be summed exactly. Set V=VO and let the num- ber of terms be 00, In [139] := eq1 = pot [VO, 00] Out[139]= - [i va [Log [1- e. iX .¥) - Log [1 + e. iX -¥]_ Log [1- e ix _¥ ] + Log [1 + e ix .¥ ])] This potential can be reduced to a simpler form: 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 475 In[140]:= potVO = eq1//. {LOg(l-a_} -+LOg( : ) +Log(a+1}}// FullSillQ;llify Out [140] = i va ( Log ( Tanh ( n (. x) J J - Log ( Tanh (  J J J IT To visualize the result, use Plot3D to plot the potential in the {x,y} plane: In[141]:= Plot3D[potVO/.a -+ 1/ .VO -+ 1, {x, 0.0001, 0.9999}, {y, 0, 0.5}, AxesLabel -+ { X , Y , v } ] ; The potential vanishes at x={ 0, a}, as it should. The value of the potential is one on the end. The limits for the x-variable have been kept away from x=O and x=l to avoid the discontinuity at y=O. . PROBLEM 3 Rectangular Conduit. Consider a rectangular conduit that is bounded by walls on four sides located atx=O, x=a, y=O, andy=b. The conduit has infinite length along the z-axis. The potential is zero on the sides y=O and y=b. On the side x=a, the potential is V[a, y] = Va and on the side x=O, the potential satisfies the equation v' [x] =0. a. Express the potential as an expansion in Cartesian coordinates. Determine the ex- pansion coefficients. b. Plot the potential on the wall x=a and compare the results with the boundary condi- tion potential. Experiment by keeping more terms in the expression for the potential. Make a three-dimensional plot of the potential. c. Plot the equipotentiallines and electric field in the {x, y} plane. 
476 Chapter 8 Electrostatics V(x,b,y,z)=O V(O,y,z)=O b l' V(a,y,z)=V o 0 0 ..  a y x x V(X,O,z)=O Remarks and Outline The symmetty in z implies that the solution is independent of the z-variable. Use Cartesian coordinates and express the answer as a product X [x] y [y] . The boundary conditions on the walls require the product to be of the form Cosh [m 7r x/b] Sin[m 7r y/bJ,wherem={1,2,3, ...}.TheorthogonalityofSin[m 7r y/b] enables you to express the expansion coefficients as integrals over the boundary at x=a. Required Packages In[142]:= Needs[RCalculus'vectorAnalysis'D] Needs [DGraphics'PlotField'R] Solution In[143]:= Clear [RGlobal' * D]; a. Start by defining the potential (pot) as a sum over the orthogonal functions: ( m7\"X ) . ( m7\"Y ) In[144]:= term[DL] = A(m) Cosh  S1n  ; pot [11..] = Sum [term [m] / /Evaluate, {m, 1, n}]; pot [n] Out[144]= A(m) Cosh ( mx ) sin ( my ) Verify the boundary condition V' [x] =0 at x=O: 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 477 In[145]:= check = D[pot[n] IX] II l[Evaluate,#]& n mlTA(m) Out[145]= I m:::l Sin [) Sinh [ mx ) b In[146]: = check I. {x- > O} Out[146]= a At the boundary x=a, the form of the potential is In[147]:= pot[n]/.{x-+a} Out[147]= A(m) Cosh ( ma ) . ( mlT Y ) SJ.n  You can determine the coefficients A [m] using the orthogonality properties of the sine function. At the x=a boundary, the potential will be given by a sum of terms of the form In[148]:= eq1=VO==term[m]/.{x-+a} ( a mlT ) ( mlTY ) Out[148]= va ==A(m) Cosh  Sin  (Note: there is an implied sum on the right-hand side (rhs), that is, Va = LmAm Cosh (m 7r a/b) Sin (m 7r y /b) .) You can determine A [m] by multiplying both sides of eql by Sin [n 7r y/b] and then integrating. Do this first to the rhs. Because the sine functions are orthogonal, the only surviving term will be when n=m, so you can spare Mathematica the effort of integrating all terms except this one. (That is, J Sin (n 7r y /b) Sin (m 7r y /b) =0 except for n=m.) The rhs is then In[149]:= rhs = ( (J:ntegrate [eq1 [ [2]] Sin [m 7\"Y Ib] I {yIO,b}]IISimplify}ll. {Sin[2m7\"] -+ O}} Out[149]=  bA(m) Cosh ( a:lT ) Likewise, for the left-hand side (lhs), you have In[150]:= lhs = «J:ntegrate [eq1 [[1]] Sin [m7\"YIb] I {yIO,b}]}II.{Cos[m7\"] -+ (-l)-m}}11 SillQ;llify ( -1 + (_l)m) bva Out[150]= - mlT 
478 Chapter 8 Electrostatics Setting the lhs equal to the rhs, you find A [m] In[151] : = a801 = 801ve[rhs == 1hs, A[m]] [[1]] / /8 iDQ;Ilify; A[DL] = A[m] / .a801 2 ( - 1 + (_l)m) va sech ( alT ) Out[151]= - mlT and thus, the potential. In[152]:= pot[n] Out[152]= A(m) Cosh ( mx ) sin ( my ) b. You can see the effect of using different numbers of terms in the expansion of the potential. Here, make a table of potentials with {2,4,6,8} terms at the boundary x=a and plot the results: In[153]:= P10t[ '1'ab1e[pot[n], {n, 2, 8, 2}]//. {b -+ 1, VO -+ 1, a -+ 1, x -+ a} / /Eva1uate, {y, 0, 1}, P10tRange -+ {O, 2}]; 2 1. 75 1.5 The curves with more inflection points contain more terms in the expansion and more closely represent the correct potential at the boundary. Taking n=4, the potential in the {x,y} plane is In[154]:= P10t3D[pot [4] / /. {b -+ 1, VO -+ 1, a -+ 1}, {y, 0, 1}, {x, 0, 1}, viewPoint -+ {2, 2, 1}] ; 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 479 1 It is clear from this plot that the boundary conditions are satisfied except at the x=a boundary. c. You can plot the electric field and the equipotentiallines with VEPlot: In[155]: = VEPlot [pot [4] / /. {b -+ 1, VO -+ 1, a -+ 1}, {x, 0, 1}, {y, 0, 1}]; · I ! t \ \ \ \ . \ . ! ! , i, I ,  " ' , , ii, , , j j , I , , . PROBLEM 4 Potential Inside a Rectangular Box with Five Sides at Zero Potential. Consider a rectangular enclosure with sides at x= { 0 , a}, y= { 0 , b}, and z = { 0 , c} . The side at z=c has a specified potential VO; the other five sides have zero potential. The solution is a function of all three variables, {x,y, z}. In Cartesian coordinates, the solution can be represented by a product of three functions X [x], Y [y], and Z [z] . These functions are of the form X[x] = {Sin[a x], Cos [a xJ}, Y[y] = {Sin [,8 y], Cos [,8 y]}, 
480 Chapter 8 Electrostatics and Z[z] = {Cosh[y z], Sinh[y zJ} where a 2 + f32 = yl. V(x,y,O)=V o b I, y 0 0 . . a x x a. Express the potential in a series and find the expansion coefficients. b. Let x=1/2 and use Plot3D to graph the potential in the {y, z} plane. Plot the equipotentiallines and the electric field using VEPlot. Solution In[156]:= Clear [nGlobal ' * n]; a. In Cartesian coordinates, the solution can be represented by a product of three func- tions X [x], Y [y], and Z [z]. The vanishing of the potential at x={ 0, a} requires X [x] =Sin [mx 7r x/a], wheremx={l, 2, 3, . . .}. Likewise, the vanishing of the po- tential at y={ 0, b} requires Y [y] = Sin [my 7r Y /b], where my={ 1,2,3, . . . }. For the potential to vanish on the wall at z=O, the function Z [z] must be Sinh [mz 7r z/c], where mz = c "'1 + 2 . The potential reduces to nx ny . [ 7rmxX ] . [ 7rmyy ] . [ 7rm ZZ ] I IA[mx,my]sm ----;- sm  smh  mx=] my=] At the z=c boundary, the potential reduces to VO so 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 481 nx ny VO = I I A[mx, my] sin [ n ";;X ] sin [ nm; Y ] sinh[nmz] mx=1 my=1 This is just a two-dimensional Fourier sine series. The orthogonality properties of Sin allows you to invert this equation and get an expression for A[mx, my] sinh[nmz]: . 4 (a (b . [ nmxx ] . [ nm yy ] A[mx, my] sinh[nmz] = ab Jo J o VO SIll  SIll  dydx It follows that the expansion coefficients are In[157]:= mzRu1e = {mz -+ C mx2 + 1IIY2 } . a 2 b 2 ' ( 4. VO csch (mz 7\") In[158]:= A[mx_,II1Y_] = ab [ ( mx7\"x ) S1 " n ( lI1Y b 7\"Y ) , :Integrate Sin ----a- {x,O,a}, {Y,O,b}] II SillQ;llify[#,El_nt[{IIIY, mx}, :Integers] ] & ) l.mzRu1e Out[158]= mxy [4 (-1+ (_l)mx) ( - 1 + (-1) my) va csch [ c mx 2 + my2 IT ] ] a 2 b 2 The user-defined function for the potential becomes In[159]:= pot[me.,DY.] = Sum [A[mx,lI1Y] sin ( mx:x ) Sin ( IIIY;Y ) Sinh ( mz: z ) , {mx, 1, me} , (IIIY,l,DY}]/.mzRu1e Out[159]= lmlA(mx,mY) I Sin ( mx;x ) Sin( :Y ) Sinh ( Ie :]"" ]: 
482 Chapter 8 Electrostatics Thus, the first term of the potential is In[160]:= pot [1, 1] Out[160]=  [16VO CSCh[ :2 + :2 ClT] sin ( lTa X ) sin ( lT h Y ) sinh [ M IT Z) ] b. To graph the potential, let In[161] := values = {a -+ 1, b -+ 1, c -+ 1, VO -+ 1, x -+ 1/2}; and use Plot 3D to view the potential in the {y, z} plane at x= 1 /2. Set nx=20 and ny=20 and apply Plot 3D. It follows that In[162]:= Plot3D[pot[20,20]II.valuesIIEvaluate, {y, O,l}, {z, O,l}]; You also can view the equipotentiallines and the electric field. To save time set nx=10 and ny=10 and apply VEPlot: In[163]:= VEPlot[ pot[10,10]II.valuesll.{x-+ 1/2} II Evaluate, {y, 0, 1}, {z, 0, 1}]; 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 483 # // /  ---.../ # / ,/ I,' :.  '""" --..... - , \, . //1/ , 1 \1'\' -- .../ ;: / ,/ f , , , ,. , " \, "', -..... ---..../,/ /, t t,  1,1. \. \,''''-  / / , , i I ! ; \ ,1 \ " - I , , , j j i , I j j j , . PROBLEM 5 Conducting Cylinder with a Potential on the Surface. Consider a long cylinder of radius a that is separated by a small lengthwise gap on each side. Use cylindri- cal coordinates {r, <jJ, z} and let the length of the cylinder be along the z-axis. One half of the cylinder (0< <jJ < 7T) is kept at a potential VO; the other half has a potential -vo. The symmetty of the problem suggests you should use cylindrical coordinates and that the solution is independent of z. The solution of Laplace's equation can be represented by a product of two functions R [r] <I>[<jJ], where R [r] and <I>[<jJ] are of the form, R [r] = a[n]r" + b[n]r- n and <I>[<jJ] = C [n] Cos [n <jJ] + D [n] Sin [n <jJ]. -v o a. Express the potential inside and outside the sphere as a power series in r and l/r, respectively. Sum the series to get an exact result. b. Plot the value of the potential using Plot3D and CylindericalPlot3D. 
484 Chapter 8 Electrostatics Required Packages In[164]:= Needs[nGraphics'parametricPlot3D,n] Solution In [165] : = Clear [nGlobal' * n]; a. First, consttuct the potential inside the cylinder. The symmetty of the problem sug- gests you should use cylindrical coordinates and that the solution is independent of z. The solution of Laplace's equation can be represented by a product oftwo functions R [r] <1>[ <,b]. Inside the cylinder the potential must be finite at r=O so that R[r] is of the form 7"'. Since the symmetty of the problem is an odd function in the variable <,b, the potential is a super- position of Sin terms ni L<A[n] sin[n <,b])r" n=1 The solution for <,b has 27T periodicity so the values of n are {1, 2,3, . . . }. You can determine the coefficients A [n] using the orthogonality properties of the sine function. On the r=a boundary, the potential is a sum of terms of the form ni V = L<A[n] sin[n <,b])a n n=1 This is just a Fourier sine series and the orthogonality properties of Sin allows you to invert this equation. The expression for A [m] is 1 1 2n A[n]a n = - V sin[n <,b]d<,b 7T 0 The coefficients A [n] are In[166]:= A[n_] = a- n - (Integrate [VO Sin [n tf>], {tf>, 0, 7T}] - 7T Integrate[VO Sin[ntf>], {tf>,7T,27T}] )// Simplify[#,Element[n,Integers]]& 2 (-1 + (_l)n) a-nVO Out[166]= - nlT Note that we used the fact that the potential was Vo for 0 < <,b < 7T and -VO for 7T < <,b <27T. The user-defined function for the potential is In[167]:= potIn[nf_] := SUm [A[n] Sin[ntf>] r", {n, 1, nf}] ; 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 485 The first few terms of the potential are In[168]:= 'potIn[6] 4VO Sin(5</)) r 5 4VO Sin(3</)) r 3 4VO Sin(</)) r Out[168]= 5 + 3 + 5a IT 3a IT alT You get the exact solution for the potential by summing to infinity In[169]:= eq1 = potIn[oo] Out[169]= -[iVO [LOg[l- e.<Pr ) _LOg[ e-<Pr +1)- [ ei <P r ) [ ei <P r ) ) ) Log 1 - ---a- + Log ---a- + 1 This can be simplified to give In[170]:= vin=eq1//. {LOg(1-aa_)-+ ( 1-aa ) } .. Log aa + 1 + Log (aa + 1) / /FUllS11D,Pl1fy i VO [ Log [ 1 -  ) - Log [  - 1 ) ) e a+r a+e 'f.' r Out[170]= IT Finding the potential outside is similar to finding the potential inside. For the potential to vanish at infinity the expansion must be expressed in powers of : nf I<B[n] sin[n (,b])r- n n=! On the boundary r=a, you get nf V = I<B[n] sin[n (,b])a- n n=! If you invert this equation then you get an expression for B [n] , I l a B[n]a- n = - V sin[n (,b]d(,b 7T 0 The coefficients for B [n] follow from In[l71]:= B[n_] = an - (Integrate [va Sin[ntf>], {tf>, a, 7I"}] 71" - Integrate [va Sin [n tf>], {tf>, 71", 271"}] ) / / Simplify[#,Element[n,Integers]]& 
486 Chapter 8 Electrostatics Out[171J= 4 (-a) n VO Sin 2 ( ¥ ) nlT The user-defined function for the potential is In [172J : = potOut [nf_] : = SUm[B [n] Sin [n tf>] r- n , {n, 1, nf}] ; The first few terms are In[173J:= potOut[3] 4VO Sin(3<t» a 3 4VO Sin(<t» a Out[173J= 3 + 3lTr lTr You get the exact solution for the potential by summing to infinity, In[174J:= Vout = (potOut[]IISimplifY)II. { ( l-aa ) } .. Log(l- aa_) -+ Log aa + 1 + Log(aa + 1) II S1mp11fy Out[174J= iVO ( Log (  ) -Log (  )) e 1 t/! a+r a+e 1tjJ r IT b. Let us plot the potential using Plot3D. Turn off the warning messages In [175 J : = Off [Plot3D : : plnc, Plot3D : : gval] and set a=l and VO=l. The graphic for the plot inside the cylinder is In[176J:= pt1 = Plot3D[vin/.a-+ 1/.VO -+ 1 II Evaluate, {tf>, 0, 27T}, {r, 0, 1}, Plotpoints -+ 40, DisplayFunction -+ Identity]; and the graphic outside follows from In [177 J : = pt2 = Plot3D [ Voutl . a -+ 11. VO -+ 1 IIEvaluate, {tf>, 0, 27T}, {r, 1,2 }, PlotPoints -+ 40, DisplayFunction -+ Identity] ; Joining the two graphs, it follows that In [178 J : = Off [Graphics3D : : nlist3] In[179J:= Show[{pt1, pt2}, DisplayFunction -+ $DisplayFunction] ; 
8.3 Laplace's Equation in Cartesian and Cylindrical Coordinates 487 You can view the potential more directly using CylindricalPlot3D and graphing just the region from 0 to Jr. If you restrict the <p to the {O, Jr} interval, then the graphics for the inside and outside potentials are In[180J:= Off[parametricPlot3D :: pplr] In [181J:= pt3 = Cylindricalplot3D [Vin/.a -+ 1/. VO -+ 1, {r,O,l},{t[>,O.Ol, 0.997T}, Plotpoints -+ 20, DisplayFunction -+ Identity] ; In [182 J : = pt4 = CylindricalPlot3D [ Vout/.a -+ 1/ .VO -+ 1, {r, 1, 1. 75}, {t[>, 0.01, 0.99 7T}, Plotpoints -+ 20, DisplayFunction -+ Identity]; Displaying the results, it follows that In[183J:= Show [ {pt3 , pt4}, DisplayFunction -+ $DisplayFunction]; The range <p from Jr to 2Jr is just the negative of this picture. . 
488 Chapter 8 Electrostatics 8.4 . LAPLACE'S EQUATION IN SPHERICAL COORDINATES 8.4.1 . Overview of Spherical Coordinates The solution of Laplace's equation in spherical coordinates can be expressed as products of R[r]8[0]<I>[€,b]. Laplace's equation is satisfied if the functions are of the form R[r] = an r" + b n r-(n+l) <I>[€,b] = (am sin[m €,b] + b m cos[m €,b] + (a o €,b + b o ) 8[0] = c n P[n, m, cos(O)] + d n Q[n, m, cos(O)]. The coefficients follow from boundary conditions. . PROBLEM 1 A Charged Ring. Consider a uniformly charged ring with radius a and total charge q. z q a. Find the potential along the z-axis. Make use of the simplification that all points on the ring are equidistant from the z-axis. Expand the potential in the limits of rO and r  00. b. Because the solution is axially symmetric, the general potential can be represented by a product of two functions R [r] 8[0], where R [r] = B [n] r" + A [n] r-(n+l) and 8[0] = C [n] P [n, Cos [0]] +. D [n] Q [n, Cos [0] ]. Find the potential for r<a and for r>a. Determine the expansion coefficients by evaluating the general potential at 0 = 0 and comparing it with the exact solution 
8.4 Laplace's Equation in Spherical Coordinates 489 evaluated on the axis of symmetty in part a. Find the electric field by taking the gradient of the potential. c. Use Plot3D and ContourPlot to graph the potential in the plane of the ring and normal to the ring plane. Also plot the equipotentiallines and the electric field lines using VEPlot. Required Packages In[184]:= Needs["Calculus'VectorAnalysis'"] Solution In [ 18 5] : = Clear [ "Global' * "] ; a. Choose the origin of the coordinates at the center of the ring and let the z-axis be normal to the ring. The distance to the z-axis from the ring is va 2 + Z2 . In spherical coordi- nates, where z is along the 0=0 direction, the distance from the ring to the axis is Va 2 + ? with 0=0. The potential along the z-axis as expressed in spherical coordinates is given by In[186]:= potz = q ; "I/a 2 + r 2 where q is the charge on the ring and a is its radius. To expand the potential in a power series you must separately consider the cases r>a and r<a. For r>a you expand about r = 00 and for r<a you expand about r=O. The interior and exterior potentials are In[187]:= potZin[n_]:= series [potz, {r, 0, n} ] / / powerExpand / / Normal; potzout [11...] : = Series [potz, {r, 00, n}] / /PowerExpand / / Normal; PowerExpand was used to clean up the results. The first nine terms for the potential for r<a and r>a are In[188]:= potzin[9] 35 q r 8 5 q r 6 3 q r 4 q r 2 q Out[188]= ---+---+- 128a 9 16a 7 8a s 2a 3 a In[189]:= potzout[9] 35 qa 8 5 qa 6 3 qa 4 qa 2 q Out[189]= ---+---+- 128r 9 16r 7 8r s 2r 3 r b. The symmetty of the ring suggests that the general potential depends only on r and 0 and not <p. The axially symmetric solution of Laplace's equation in {r, O} coordinates can be expressed in the form, 
490 Chapter 8 Electrostatics s I (B[n] (r + A[n] (rl) (C[n]P[n, cos[O]] + D[n]Q[n, cos[O]]) n=O Since the potential is finite at 0=0 you must set the D [n] coefficients to zero. The form of the potential reduces to s  (B[n] (r +A[n] (rl)p[n, cos[O]] The user-defined function for the potential is In[190]:= pot [B_] := SUm[B(n) (;r + (r.l A(n) Legendrep [n, COB [9]], {n, 0, B} ] To continue further we must separately consider the series expression for r>a and r<a. For r>a, the potential must vanish at infinity so B [n] =0 and you are left with s I (A[n] (rl) P[n, cos[O]] n=O The user-defined-function for the potential is In [191] : = Vout [B_] = ( ) n.l SUm [ A(n) LegendreP [n, COB [9]], {n, 0, B} ] ; The coefficients in the expansion are determined by comparing Vout evaluated on the axis of symmetty (0=0) to the exactly solvable example given by potZout. Subttact potZout from Vout and set the difference to zero. Use CoefficientList to exttact powers of  and solve for A [n] . These steps are automatically performed by the function coeffOUt. In[192]:= coeffOut [B_] .- Solve [ o == CoefficientLiBt [ (vout [B] - potZout [B]) /.9 -+ 0, l/r] , A /@ Range [0, B]] / /Flatten The user-defined function coeffOUt solves for A [i] when r>a, e.g., In[193]:= coeffOut[3] Out[193]= { A(O) -+,A(l) -+O,A(2) -+-,A(3) -+O } a 2a 
8.4 Laplace's Equation in Spherical Coordinates 491 You get the potential for r>a to order s by substituting these coefficients into Vout: In[194]:= potOut[s.] :=Vout[s]/.coeffOut[s] The first three terms of the potential for r>a are In[195]:= potOut[6] 3 q ( 35 Co4 (e) _ 15 co: 2 (e) +  J a 4 Out[195]= 8 r 5 q (-J a 2 2 r 3 q +- r Consider the second case where r<a. For r<a, the potential must be finite at the origin so A [n] =0 and the potential reduces to t B[n] (r P[n, cos[O]] n=O The potential follows as above with a few obvious changes: In[196]:= vin[s_] := Sum [ ( ;: ) n B (n) Legendrep [n, Cos [9] ] , {n, 0, s} ] In[19?]:= coeff:In[s_] := Solve [ 0== CoefficientList [ (Vin[s] -potZin[s])/.9-+0, r], B/@Range[O,s]]//Flatten and In[198]:= pot:In[s_] := Vin[s] /. coefUn[s] The first four terms of the potential for r<a follow from In[199]:= pot:In[6] 
492 Chapter 8 Electrostatics Out[199]= 5 q ( 231 C6 (6) _ 315 C4 (6) + 105 C2 (6) - rt J r 6 + 16 a 7 3 q ( 3 5 CO4 (6) - 15 Cos 2 (6) + 1 J r4 4 8 8 as q(-!Jr2 2 a 3 q +- a The electric fields for r>a and r<a follow from E Spherical - VV. Set the coordinates to In [200]:= SetCoordinates [Spherical [r, 9, 4>]]; and then the series expansions for the electric field with r>a and r<a follow from In [201] : = electout [s_] : = -Grad [potOut [s]]; In[202]:= electin[s_] := -Grad [potIn[s] ]; For example, the first few terms are In[203]:= electout[3] 3a 2 q (-!J 2 r 4 Out[203]= {  - 3a 2 qcos(e) Sin (e) } 2 r4 ,0 In[204]:= electin[3] q r ( 3 co2 (6) - ! J { _ 3qrcos(e) a 3 ' 2 a 3 Sin(e) ,o} Out[204]= c. To plot the potential you switch to Cartesian coordinates and use Plot3D and Con- tourPlot. Define r2xRule to convert from spherical to Cartesian coordinates: In[205]:= r2xRule = {r, 9, 4>} -+ CoordinatesFromCartesian [ {x, y, z} , Spherical] / /'l'hread Out [205]= {r -+ ,J x 2 +  + z2, e -+ Cos- 1 [ z ] , <P -+ Tan. 1 (x, y) } ,J x2 +y2 + z2 Choose the specific values 
8.4 Laplace's Equation in Spherical Coordinates 493 In [206] := values = {a ...1, q... 1}; and evaluate the potential inside and outside the ring coordinates. Setting 8=12, it follows that In [207] := potOUtXYZ [X-, y_, z_] = potOUt [12] / / .r2xRule/ / . values ; pot:InXYZ [x_, y_, z_] = pot:In[12] / / .r2xRule/ / .values ; With the help of an if statement, defin e a function ff that yields the potential at all values of {x, y, z}. If the radius, given by  :2- + 1 + Z2, is greater than or equal to a=l, then use the result of potOUtXYZ; otherwise, use potinXYZ: In[208]:= ff[x-,y., z_] := :If [ N [ .y x 2 + -:?' + Z2]  1, potOUtXYZ [x, y, z], pot:InXYZ[X,y,Z]] Plot the potential in the {x, z} plane using both Plot3D and ContourPlot. The graphics for the plots are In[209]:= ptl = Plot3D[ff[x, 0, z], {x, -2, 2}, {z, -2, 2}, plotPoints... 30, DisplayFunction... :Identity]; and In [210] : = pt2 = ContourPlot [ff [x, 0, z], {x, -2, 2}, {z, -2, 2}, PlotPoints... 30, contourSmoothing ... True, DisplayFunction... :Identity] ; Displaying the graphics side-by-side, it follows that In[211]:= Show[GraphicsArray[{ptl,pt2}]]; The irregularities can be smoothed by taking more terms in the potential expansion. The corresponding VEPlot for the equipotentiallines and the electric field in the {x, z} plane is 
494 Chapter 8 Electrostatics In[212]:= VEPlot[ff[x,O,z]//Evaluate, {x, -2.1, 2.1}, {z, -1.6,1.6}, Epilog... {{Hue [0 .3], Disk [{1, O}, 0.2] }, {Hue[0.3], Disk[{-1, O}, 0.2]}}]; Next, consider the potential in a space slice containing the plane of the ring, {x, y}. The Plot3D and ContourPlot graphics are In[213]:= pt3 = Plot3D[ff[x,y, 0], {x, -2, 2}, {y, -2, 2}, P1otPoints... 30, DisplayFunction ... :Identity] ; and In[214]:= pt4 = ContourPlot [ff [x, y, 0], {x, -2,2}, {y, -2, 2}, Plotpoints ... 30, ContourSmoothing ... True, Epilog... {Hue[O .07], Thickness [0.03], Circle [{O, O}, 1]}, DisplayFunction ... :Identity] ; Displaying the graphs side-by-side, it follows that In[215]:= Show[GraphicSArray[{pt3,pt4}]]; 1 2 
8.4 Laplace's Equation in Spherical Coordinates 495 where a ring image has been inserted into the graph on the right. The correspond- ingVEPlot for the equipotentiallines and the electric field in the ring's plane is In[216]:= VEP1ot[ff[x,y, 0], {x, -2.1, 2.1}, {y, -2.1, 2.1}, Epilog... {Hue [0 .05], Thickness [0.008], circ1e[{0, O}, 1]}]; I t ., ....... -- .#// The roughness of the potential at the position of the ring is due to the small number of terms that were kept in the potential expansion. . PROBLEM 2 Grounded Sphere in an Electric Field. A conducting sphere of radius a, which is held at zero potential, is placed in a uniform electric field EO. Use spherical coordinates and choose the z-axis along the direction of the applied field EO. The solution is symmetric about the z-axis so the potential can be written as an expansion in Legendre L 111111 Eo 
496 Chapter 8 Electrostatics polynomials:  (A[i] (r + B[i] (tl)P[i, COS[O]] a. Solve for the expansion coefficients by requiring the potential to vanish on the sur- face of the sphere. Also use the condition that as r goes to infinity the potential must reduce to the potential due to the applied electric field. Take the gradient of the potential to find the electric field. b. Use the user-defined function VEPlot to graph the equipotentiallines and electric field. Required Packages In[217]:= Needs["Calculus'VectorAnalysis,n] Needs ["Graphics'plotField'"] Solution In[218]:= Clear ["Global ' *"]; a. Use spherical coordinates and choose the z-axis along the direction of the applied field EO. The solution is symmetric about the z-axis so the potential can be written as an expansion in Legendre polynomials. The coefficients {A [i] , B [i] } follow from bound- ary conditions. Consider the boundary condition as r -+ 00. The potential must go as -EO r Cos [0] , so this requires that all A [i] vanish except for A [1] = -EO a. This asymp- totic boundary condition is described by Asol: In[219]:= Asol = {A[l] ... -EO a, A[L] ... O} ; The user-defined function for the potential becomes In[220]:= pot[s_] := Sum [(A(i) (;r + (r+l B(i) ) LegendreP [i, Cos [8]], {i, 0, S}] / .Asol The values of B [ i ] follow from the vanishing of the potential on the sphere. First, evaluate the potential at r=a and set the potential to zero. Second, the command Logic- Expand can be used to exttact equations obtained by setting the coefficients of the powers of Cos [0] to zero. This is done by ITacking the order of the expansion with O[cOS[O]]s+l and applying LogicalExpand to the potential equation, In[221]:= Beq[s_] := LOgicalExpand[ (pot [s] /.r... a) == 0 + o [Cos [8] ]8+1] 
8.4 Laplace's Equation in Spherical Coordinates 497 For example, if s=4 then you get five equations, In[222];= Beq[4] SB(3) 3B(3) Out[222]= - == 01\aEO -B(l) +  == 01\ B(2) 3B(4) -B (0) +  - -----g- == 01\ _ 3SB(4) ==01\ lSB(4) _ 3B(2) ==0 8 4 2 You now have sufficient information to solve for B [i]. In[223];= Bsol [s_] : = Solve [Beq[s]] / /Flatten; Let s=6 and apply Solve to the set of equations In [224] : = Off [Solve: : svars] In[225];= Solve[Beq[6]]//Flatten Out[225]= {B(l) ....aEO,B(O) ....0,B(3) ....0, B(2) ....O,B(S) ....0,B(4) ....0,B(6) ....O} where we turned off the warning message. You can convince yourself by increasing s that all the B [i] are zero if i>l, so the solutions for B [i] become In [226] ;= Bsol = {B[l] ... aBO, B[L] ... O}; The complete solution for the potential follows from substituting the values of B [i] into pot [s] or equivalently In[227];= potential = (Sum[(A{i) (;)1 + (;)1+\{i)) LegendreP [i, Cos [8]], {i, 0, 3}]) /. Asol/.Bsol Out[227]= [ a::o -Eor] coste) Observe that the total potential is a superposition of the applied potential (second term) and an induced dipole potential (first term). ->. The electric field follows from E = - VV, In [228] := eField = - Grad [potential, Spherical [r, 8, cfI]] / / ExpandAll { 2EOCOS(e)a 3 a 3 EOSin(e) . } Out [228] = r 3 + EO Cos (e) , r 3 - EO SJ.n (e) , ° 
498 Chapter 8 Electrostatics b. To view the equipotentiallines and the electric field, first convert to Cartesian coor- dinates and then use VEPlot. The ttansformation from spherical to Cartesian coordinates is accomplished with the rule In[229]:= r2xRule = {r, fI, <t>} ... CoordinatesFromCartesian [ {x,y, z}, Spherical]//Thread; Choose specific values for the parameters, In[230]:= values = {EO... 1, a... 1}; and use the user-defined function VEPlot to graph the equipotentiallines and the electric field. In[231]:= p1 = VEPlot[potential//.r2xRule//.values//. {y... O}, {x, -2.1, 2.1}, {z, -2.1, 2.1}, DisplayFunction... :Identity] ; Since the potential is only defined outside the sphere, we make a disk to mask the potential inside the sphere. In [232] := disk = Graphics [Disk[{O, O}, 1]]; Combining the disk and pl, you get In[233]:= Show[p1,disk, DisplayFunction... $DisplayFunction ] ; \ \ . . \  I i i , I ' \ '  ' " , " , "I // 'I I 
8.4 Laplace's Equation in Spherical Coordinates 499 . PROBLEM 3 Sphere with an Axially Symmetric Charge Distribution. Consider a sphere of radius a and assume the sphere has a surface-charge density that can be expressed in powers of cosn[O]. Use spherical coordinates and expand the potential in Legendre poly- nomials:  (A[i] (r + B[i] (tl)P[i, cos[O]] If En is the normal component of the electric field evaluated on the surface of the sphere, then the charge density on the sphere is equal to 47rCE;:utside - Enside). The normal electric field En is proportional to the radial derivative of the potential, V' [r] . t z x  aCe) a. Solve for the expansion coefficients {A [i] , B [i]} in terms of a given surface- charge distribution. b. Consider a sphere with a surface-charge density given by CCosCO) + C!)Cos 2 CO». Find the potential using the results derived in part a. Use CylindricalPlot3D to graph the potential. Graph the equipotentiallines and electric field in the x=O plane with VEPlot. Required Packages In[234]:= Needs[nCalculus'VectorAnalysis,n] Needs [nGraphics'ParametricPlot3D' n] Solution In [235] := Clear [nGlobal ' * n]; a. The potential can be written as an expansion in Legendre polynomials  (A[i] (r + B[i] (tl) P[i, cos[O]] Inside the sphere the potential must be finite at the origin, so all the B [i] terms must vanish, and the potential becomes 
500 Chapter 8 Electrostatics In [236] := potJ:nA[s.] := Sum [ ( ;:) i A (i) LegendreP [i, Cos [8] ] , {i, 0, s} ] Outside the sphere the potential must vanish as r -+ 00, so the A [i] coefficients must vanish, and the potential follows from In[237]:= potOUtA[s_] := ( ) i+l Sum [A[i]  LegendreP[i,CoS[8]], {i, 0, s} ] We have replaced B [i] with A [i] given in potinA since the coefficients in both ex- pressions must be the same to make the potential continuous across the sphere. The charge density on the sphere is equal to 47r(E::utside - Enside), where En is the normal component of the electric field evaluated on the surface and is proportional to the radial derivative of the potential, V' [r]. The expression for the charge density is, In[238]:= chargeDensity[s.] := 1 - (D [potJ:nA [s] , r] - D[potOUtA[s], r]) / /. 471" {r... a) For example, the first three terms of the charge density are In[239]:= chargeDensity[2]//Apart [ ] 15A(2) Cos 2 (8) 3A(1) Cos(8) 2A(O) - 5A(2) Out 239 = + + 8alT 4alT 8alT To find the coefficients A [i], first equate chargeDensity to the given surface charge Qdensity. Expand this equation to order s+ 1 in powers of Cos [0] . Use Log- icalExpand to obtain a set of equations that follow from equating the coefficients in front of equal powers of Cos [0] to zero. These steps are all performed by the function aEquation: In[240]:= aEquation[s_, Qdensity_] .- LOgicalExpand[ chargeDensity[s] == Qdensity + 0 [Cos [8] ] 8+1 ] Qdensi ty is the charge density to be specified (hence the use of the delayed equals, : =). Solve the aEquation equations to obtain rules for the A [i] coefficients: 
8.4 Laplace's Equation in Spherical Coordinates 501 In[241]:= aRu1e[s.,Qdensity.]:= Solve [aEquation[s, Qdensity], Array[A, s + 1, 0]] / /F1atten For a surface-charge density of Q/a A 2 cos[Of, the first four A[i] coefficients for this charge density are [ QCOS2 (8) ] In [242] := aRu1e 4, a 2 Out[242]= { 47fQ A(O) ->-,A(1) ->0, 3a 87fQ } A(2) -> -, A(3) -> 0, A(4) -> ° 15 a In this simple example, all A[i] for i>2 are equal to zero. You can verify this by taking larger values of s. The potential for r<a and r>a follows from [ QCOS2 (8) ] In[243]:= pot:InA[4] /. aRu1e 4, a 2 8 7f Q ( 3 Co2 (e) -  J r 2 Out[243]= 15a 3 47fQ +- 3a [ QCOS2 (8) ] In[244]:= potOUtA[4] /. aRu1e 4, a 2 8 7f Q ( 3 Co2 (e) -  J a 2 Out[244]= 3 15 r 47fQ +- 3r b. Consider the surface-charge density Q ( cos (9) + Cos (8) ) In[245]:= surfaceQ = a 2 //Expand QCos 2 (8) Out[245]= 2 a 2 + Q Cos (8) a 2 The user-defined procedures derived in part a can be used to evaluate this potential. The potential follows from potinA and potOUtA with values of the expansion coefficients given by aRule. If we set s= 8, then the potential outside the sphere is In [246] := potOUtQ = potOUtA[8] / / .aRu1e [8, surfaceQ] Out[246]= 4 7f Q ( fiL  J a 2 15 r 3 + 47fQ Cos(8) a 27fQ 3r 2 +  
502 Chapter 8 Electrostatics Terms that falloff faster than  are zero. The potential inside the sphere is r In [24 7] : = potInQ = potInA[8] / / . &Rule [8, surfaceQ] 4 7T Q ( 3 Cos> (e) - 1 J r2 [ 2 2 47TQCos(8)r 27TQ Out 247]= 3 + 2 +- 15 a 3 a 3 a Graph the potential in the {r , e} plane by joining the graphs for the potential inside and outside the sphere. Use the values In[248]:= values = {Q-+l,a-+l}; then the graphic for the potential inside the sphere is, In [249] := pl = CylindricalPlot3D [potInQ/ / .values, {r, O,l}, {e, 0, 27T}, DisplayFunction -+ Identity] ; and outside the sphere, it follows that In[250]:= p2 = CylindricalPlot3D[potOUtQ//.values, {r,l, 3}, {e, 0, 27T}, DisplayFunction -+ Identity] ; The complete graph for the potential for all values of r follows from combining pi and p2, In[251]:= Show[pl,p2, AxesLabel -+ {a, b, c}, ViewPoint -+ {-lo5, -2, 2}, BoxRatios -+ {l,l, l}, DisplayFunction -+ $DisplayFunction]; a 
8.4 Laplace's Equation in Spherical Coordinates 503 Consider the plot for the electric field and equipotential curves in the x=O plane and use VEPlot to graph the electric field and equipotentiallines. You must express the potential in Cartesian coordinates. The ttansformation from spherical to Cartesian coordinates fol- lows from the rule In [252] := r2xRule = {r, 9, iii} -+ CoordinatesFromCartesian [ {x, y, z}, Spherical] / /Thread; The potentials inside and outside the sphere as expressed in Cartesian coordinates and restricted to the x=O plane are given by eql and eq2, respectively: In[253]:= (*forO <r<h) eql [y_, z.] = potJ:nQ/ .r2xRule/. {Q -+ 1, a -+ 1, x -+ O} / / Sill\Plify; In[254]:= (*forl<r*) eq2 [y_, z_] = potOUtQ/ .r2xRule/. {Q -+ 1, a -+ 1, x -+ O} / / Sill\Plify; Use the command If to combine eql and eq2 into one function that is valid for all coordinate values. The condition i + i!- < 1 is True if you are inside the sphere so the potential is In [255] := pot [y_, z_] .- J:f [r + Z2 < 1, eql [y, z], eq2 [y, z]] Draw a circle to overlay on the plot In [256] := circle = {Thickness [0 .02], Circle [{O, O}, l]} / / Graphics; The graphics for the equipotentiallines and electric field follow from In[257]:= Show[ {VEPlot [pot [y, z], {y, -2, 2), {z, -2, 2}, DisplayFunction -+ J:dentity], circle} , DisplayFunction -+ $DisplayFunction] ; 
504 Chapter 8 Electrostatics . PROBLEM 4 Sphere with a Given Axially Symmetric Potential. Consider a sphere of radius rO whose surface is held at a fixed potential V [0] . Use spherical coordinates and expand the potential in Legendre polynomials: s ( ( r ) i ( rO ) i+l )  B[i] rO + A[i] -;: P[i, cos[O]] Lx v(e) a. Show the coefficients in the expansion can be expressed in terms of an integral over the surface potential and derive the expression for the potential inside and outside the sphere for an arbittary surface potential V [0] . b. Illusttate the procedure by considering the example V[O] = VoCOS(0)2. Plot the po- tential as a function of {r, O} using CylindricalPlot3D. c. Find the potential when the surface potential is 1. [II] and the radius of the sphere is rO=l. Plot the potential as a function of {r, O} using CylindricalPlot3D. 
8.4 Laplace's Equation in Spherical Coordinates 505 Required Packages In[258]:= Needa["Calculua'VectorAnalyaia'"] Needa["Graphica'ParametricPlot3D'"] Solution In[259]:= Clear["Global' *"]; a. The symmetty of the problem suggests you should use spherical coordinates {r, 0, cp} and assume the solution is independent of cpo Expand the potential inside the sphere in Legendre polynomials keeping only positive powers of r so that the potential is finite at r=O: In[260]:= pot:tn[v_, a_] .- Sum. [( :c, ) D B(V, n) P[n, Coa[9]], {n, 0, a}] where rO is the radius of the sphere and P are Legendre polynomials. Outside the sphere, keep only negative powers of r so that the potential vanishes at r= 00, the potential be- comes In [261] := potOut[V., a_] .- SUm [ ( r: r+J. B(V, n) P [n, Coa [9]], {n, 0, a} ] Continuity of the potential on the sphere required the coefficients to be the same in potOUt and potIn so we set A [i] =B [i] in potOUt. On the surface of the sphere the potential must be V [0] . We can expand V [0] in Leg- endre polynomials. Specifically, V[O] = L B[V, n]P[n, 8] where (2n + 1) L 1C . B[V, n] = dOsm[O]P[n, cos[O]]V[O] 2 ° The user-defined function for B [V, n] is In [262] := B[V., n_] := 1 "2 (2 n + 1) :tntegrate [V LegendreP [n, Coa [9]] Sin [9], {9, 0, 7\"}] b. To illusttate the procedure, consider an example where the potential on the sphere is VO CoS(0)2. For 8=4, the potential outside is In [263 ] : = pOut = potOut [YO Coa [9] 2,4] 2VOP(2,Cos(8)) r0 3 VOP(O,Cos(8)) rO Out[263]= 3 r 3 + 3 r 
506 Chapter 8 Electrostatics and the potential inside follows from In[264]:= pJ:n = potJ:n [VOCOS[9]2, 4] 2VOP(2,Cos(8))r 2 1 Out[264]= 2 +-VOP(O,Cos(8)) 3 rO 3 To plot the potential, choose the substitutions In [265] := values = {rO -+ 1, VO -+ 1, P -+ LegendreP}; First, plot the potential inside the sphere In[266]:= p1 = CylindricalPlot3D[pJ:n/ . values, {r, 0, 1}, {9, 0, 27f}, DisplayFunction -+ J:dentity]; and then plot the potential outside the sphere In[267]:= p2 = Cylindricalplot3D[pOut/ .values, {r, 1, 3}, {9, 0, 27f}, Displayll'unction -+ J:dentity] ; Combining the graphics, it follows that In[268]:= Show [p1, p2, BoxRatios -+ {1, 1, 1}, ViewPoint -+ {-lo5, -2, 2}, Displayl"unction -+ $DisplayFunction] ; C. Consider the case where the radius of the sphere is rO=l and the surface potential is given by 
8.4 Laplace's Equation in Spherical Coordinates 507 In [269] := surfacePot = Cos(9) 1.1-Cos(9) The first four terms of the potential inside and outside the sphere are In[270]:= {pJ:n2,pOut2} = ({potJ:n[surfacePot,3], potOut[surfacepot,3]}/. P -+ LegendreP / /. {rO -+ 1) / / Sill\Plify) ; First, plot the potential inside the sphere, In[271]:= p1 = CylindricalPlot3D[pJ:n2, {r, 0, 1}, {9, 0, 27f}, PlotRange -+All, DisplayFunction -+ J:dentity] ; and then the potential outside the sphere In [272] := p2 = CylindricalPlot3D[pOut2, {r, 1,3), {9, 0, 27f}, PlotRange -+ All, DisplayFunction -+ J:dentity] ; Combining plots, you have the potential for all regions of space: In [273] := Show [p1, p2, BoxRatios -+ {1, 1, 1}, viewPoint -+ {-1. 5, -2, 2}, DisplayFunction -+ $DisplayFunction] ; 
508 Chapter 8 Electrostatics . PROBLEM 5 Sphere with Upper Hemisphere VO and Lower Hemisphere -VO. Consider a sphere of radius rO with a surface potential that is described by a discontinu- ous function. The top hemisphere has a potential +VO, and the bottom hemisphere has a potential -VO. In spherical coordinates the potential in Legendre polynomials is t (A[i] Gr + B[i] (tl)P[i, cos[O]] +v o Lx -Yo a. Evaluate the expansion coefficients and find the potential inside and outside the sphere. Evaluate the series for the first few terms. b. Use ContourPlot to graph the equipotential curves in the x=O plane. Required Packages In[274]:= Needs[nCalculus'VectorAnalysis,n] Needs [nGraphics'parametricPlot3D,n] Solution In[275]:= Clear [nGlobal ' * n]; a. The symmetty of the problem suggests you should use spherical coordinates {r, 0, cp} and assume the solution is independent of cpo Therefore, expand the potential inside the sphere in Legendre polynomials with positive powers of r so that the potential is finite at r=O In[276]:= pot:tn[s_] :=Sum[( :o r B(n) P[n,Cos[e]], {n, 0, s} ] where rO is the radius of the sphere and P are Legendre polynomials. Outside the sphere, expand the potential in Legendre polynomials with negative powers of r so that the poten- tial vanishes at r = 00: 
8.4 Laplace's Equation in Spherical Coordinates 509 In[277]:= potOut[s_] := ( 0 ) n+J. Sum [ rr B(n)p[n,COS[9]],{n,O,S}] Continuity of the potential on the sphere requires the coefficients B [i] to be the same in potOUt and potIn. As was the case in the previous problem, it follows from the orthogonality of the Leg- endre polynomials that the coefficients B [i] are In[278]:= B[n.] := 1 2" (2 n + 1) (+ :tntegrate [VO LegendreP [n, Cos [9]] Sin[9], {9,O,/2}]+ :tntegrate [-VO LegendreP [n, Cos [9]] Sin [9], {9, 12, }]) ; Note that we used the information that v=vo for 0 < e < Jr/2 and V=-VO for Jr/2 < e < Jr. The first few terms for the potential outside and inside the sphere are, respectively, In[279]:= potOut[5] 11 vo P(S, Cos (8)) r0 6 Out [279] = 16 r6 7VOP(3,Cos(8)) r0 4 8 r 4 + 3 vo P (1, Cos (8)) r0 2 2 r 2 b. To view the potential, consider the values of the parameters In[280] : = values = {rO -+ 1, VO -+ 1, x- > O}; and then express the potential in Cartesian coordinates. The ttansformation from spherical to Cartesian coordinates follows from the rule In[281]:= r2xRule = {r, 9, iii} -+ CoordinatesFromCartesian [ {x, y, z}, Spherical] / / Thread; The conversion rules are In [282] := allRules = {P -+ LegendreP , r2xRule, values} / / Flatten; Applying r2xRule to potIn [8] and potIn [8] for 8=11, you get In[283]:= eq1= pot:tn[ll]//.allRules; In [284] := eq2 = potOut [11] / / .allRules; 
510 Chapter 8 Electrostatics Defining one function for the potential inside and outside the sphere, it follows that In [285J := potTot = J:f [r + z 2 :s 1, eq1, eq2] ; Next, draw a circle to overlay on the plot. In [286J : = circle = Graphics [{Thickness [0 .02], Circle [{O, O}, 1]}] ; Applying ContourPlot to pot Tot , you can see the equipotentiallines for this po- tential In[287J:= Show[{ ContourPlot[potTot//Evaluate, {y, -2, 2}, {z, -2, 2}, Plotpoints -+ 20, DisplayFunction -+ J:dentity] , circle} , DisplayFunction -+ $DisplayFunction] ; The islands on the top and bottom boundaries of the spherical surface result from the finite number of terms in the potential expansion. . 
8.5 Exercises 511 8.5 . EXERCISES The solutions to many of these exercises can be found on our web sites. 8.1 Parallel Plates and Strips Consider parallel plates located in the {x, z} plane. One plate is located at y=O and the other at y=L. The plate at y=L is at zero potential except for a strip along the x-axis from x = {+d, -d}. The strip is at potential V o ' (a) Find the potential and graph the equipotential surfaces and electric field. (b) Generalize the problem to allow for n parallel strips that have the same width, potential, and separation. 8.2 Parallel Plates and a Point Charge Two infinite, grounded conducting planes are at x= 0 and x=L. A point charge q is placed between the planes. (a) Find the charge induced on the planes and graph the results. (b) Generalize part a to include n charges between the plates. Graph the results for three charges. 8.3 Cylinder Divided into Segments Consider an infinite, hollow conducting cylinder of radius b. Divide the cylinder into two equal segments that run parallel to the axis of the cylinder. The top segment has constant potential + v, and the bottom has potential -v. (a) Expand the potential in cylindrical coordinates. Can you sum the series and get an exact expression for the potential? (b) Graph the equipotential surfaces and electric field for the potential. (c) Generalize the problem for a cylinder divided into 2n equal segments that have potentials that alternate in sign. 8.4 Elliptical Cylinder in a Uniform Electric Field An infinitely long, conducting elliptical cylinder bearing no net charge is placed in an initially uniform electric field Eo' The cylinder is grounded. The direction of Eo is perpendicular to the cylinder's axis. (a) Find the potential and its electric field. (b) Plot the equipotential surfaces and electric field. 8.5 Cylindrical Box and n Charges Consider a conducting cylindrical box with one end at z=O and the other at z=L. The radius of the cylinder is roo The walls are kept at zero potential. A positive charge is placed inside the cylindrical box. (a) Find the potential inside the cylindrical box. Plot the equipotential surfaces and electric field. (b) Find the charge induced on the conducting walls and plot the results. (c) Generalize the results to include n charges inside the box. 8.6 Distorted Sphere with a Potential Consider a distorted sphere whose surface is held at a fixed potential V [9] . The shape of the surface is described by the radial coordinate r = ro(l + cP[l, Cos9]). The parameter c and the Legendre polynomial P describe the distortion. (a) Derive an expression for the potential inside and outside the sphere. 
512 Chapter 8 Electrostatics (b) Find the potential when the surface potential is V [0] = COS [0]. Plot the potential as a func- tion of {r, O}. (c) Plot the potential found in part b in the two planes defined by x=O and z=O. 8.7 Concentric Spheres with Different Potentials on the Two Hemispheres Two concentric spheres have radii a, b (b>a) and are each divided into two hemispheres by the same horizontal plane. The upper hemisphere of the inner sphere and the lower hemisphere of the outer sphere are maintained at potential V. The other hemispheres are at zero potential. (a) Determine the potential. (b) Graph the electric field and equipotential surfaces. 8.8 Ring Charge Consider a total charge q distributed around a circular ring of radius roo The axis of the ring is along the z-axis, and the center of the ring is located at z=b. The charge per unit length is a function of <p. (a) Find the potential everywhere. (b) For the charge density, Q {Cos( <p) - Sin(24))}, find the asymptotic expression for the potential TO and electric field. (c) Plot the results. 8.9 Laplace's Equations in Other Coordinates Consider the coordinate systems EllipticCylindrical, Bispherical, and Toroidal. For each of these systems solve the following problems. (a) Express Laplace's equation as a product of three functions and derive an ordinary differential equation for each function. (b) Find the solutions for the functions and write the general expression for the potential. (c) Write a procedure that will return the separated Laplace equations when you input a given coordinate system. 
CHAPTER 9 Quantum Mechanics 9.1 . INTRODUCTION This chapter contains problems on nonrelativistic quantum mechanics found in standard texts for upper division physics students. We cover the essential points of Schrodinger the- ory for both one-dimensional problems and three-dimensional problems. Many kinds of graphics are used to display the results, and the reader is encouraged to modify the po- tentials, boundary conditions, and graphics to better understand the solutions. The purpose of this chapter is to develop an understanding of the Schrodinger equation by means of problem solving. We start this chapter with a brief inttoduction to Quantum Mechanics. In 1913, Danish physicist Niels Bohr made one of the first attempts to formulate a quantum theory of the atom. He realized that the electtons in hydrogen could possess only discrete sets of energy values. Bohr proposed three postulates concerning the sttucture of an atom: 1. Atomic electtons move in orbits restricted by the requirement that the angular mo- mentum 1 be an integral multiple n of fl = :l;;. Furthermore, the electtons in these orbits do not radiate. For an electton of mass m and velocity v moving in a circular orbit of radius r, the angular momentum quantization restricts the electton's velocity according to the relation 1 = mvr, where the angular momentum 1 = nfl. 2. Transitions from one state to another are accompanied by a gain or loss of energy equal to the energy difference between the two states. The energy loss can appear as electtomagnetic radiation. 3. If an electton falls from orbit n j to n f with a change in energy of Ej - Ef' the energy difference can appear as radiation with angular frequency Ej - E f = fl w, where w = 21rf, and f is the frequency. The success of Bohr's provisional theory with hydrogen-like atoms gave impetus for additional research on this quantum approach. The modern theory of quantum mechanics was ushered in with the works of Heisenberg, Born, Jordan, Schrodinger, and Dirac in the 1920s. Modern quantum mechanics uses wave functions to describe the probability that a particle will be found at a space-time point. In 1925, Erwin Schrodinger and Werner Heisenberg independently developed the new quantum theory. Schrodinger's method involves partial differential equations, whereas Heisenberg's method employs matrices. These two methods are mathematically equiva- lent. Most textbooks begin with SchrOdinger's equation. The time-dependent Schrodinger 513 
514 Chapter 9 Quantum Mechanics equation is a partial differential equation in space and time: .tz a ./r tz2 v 2 V ' fJt 'l'=- 2m I/t+ I/t where V represents the potential energy of the system. The operator V 2 is the Laplacian and in Cartesian coordinates it is a 2 &- &- V 2 - - ax? + a-j + az 2 SchrOdinger's equation is of fundamental importance in a wide range of physical phe- nomena where quantum mechanics is important. The concepts of energy eigenstates, quantum mechanical tunneling, and scattering are evident in solutions of the Schrodinger equation. The state of a quantum mechanical system is completely specified by the function I/t[, t], which depends on the coordinates of the particle and on time. This wave func- tion has the important property that it determines the probability that a particle is located at  at time t. The wave function must satisfy certain mathematical conditions because of this probabilistic interpretation. For the case of a single particle, the probability of finding it somewhere is 1, so that you have the normalization condition f I/t[, t]*I/t[, t]lf.iJ = 1 The wave function I/t describes the physical problem. The probability current or flux is given by the vector equation: J = W(2im)(I/t*VI/t - VI/t*I/t). The Schrodinger equation plays the role of Newton's laws in classical mechanics, i.e., it predicts the future behavior of a dynamic system. A wave equation that determines a wave function, predicts the probability of events. For time-independent potentials it is possible to express the wave function as a product iEnt e- T I/t[x, y, z]. The time coordinate gives the parameter En, which is the energy of the quantum state. The time-independent wave function for a single particle of energy En in a potential V obeys the time-independent Schrodinger equation: tz2 --V 2 1/t + V = E I/t 2m n The solution of Schrodinger's equation gives the wave function for a particle in a poten- tial V. The solutions of SchrOdinger's equation simplify for systems that can be described with one variable. For example, SchrOdinger's equation for systems that are only a function of the x-coordinate reduces to tz2 --ifl'[x] + V[x]l/t[x] = Enl/t[x] 2m 
9.2 One-Dimensional Schr6dinger's Equation 515 Further simplifications occur if the potential is a constant. The constant potential is the simplest one-dimensional boundary problem. This chapter is divided into two problem sections: 9.2 One-Dimensional SchrOdinger's Equation, and 9.3 Three-Dimensional Schrodinger's Equation. In section 9.2 we illustrate the affects of wells and barriers. Potential barriers in the form of a well allow you to inves- tigate quantized energy levels and their associated wave functions. Step potentials allow you to investigate phenomena associated with quantum tunneling and scattering. With a step barrier, some of the wave will be reflected, some will be ttansmitted, and some of the wave will penetrate into the barrier. These concepts are then applied to more complex problems for three dimensions in section 9.3. Exercises are included in section 9.4. Before starting the problems you might find it convenient to turn off the spell checker: In[i]:= Off [General :: "spell"]; Off [General :: "spelll"]; 9.2 . ONE-DIMENSIONAL SCHRODINGER'S EQUATION . PROBLEM 1 Particle Bound in an Infinite Potential Well. Suppose a particle is bound by the infinite potential well defined by V = 0 if 0 < x < a and V = 00 otherwise. Schrodinger's one-dimensional time-independent equation is fl2 - 2m 1ft" [x] + VIft[x] = En Ift[x] where V is the potential that describes the system. This simple one-dimensional boundary problem illusttates the methods used to evaluate quantized energy levels and their associ- ated wave functions. a. Show that the general solution of Schrodinger's equation inside the well can be writ- ten in the form 1ft = C[1] Cos[kx] + C[2] Sin[kx]] where En = h;;,2 . 00 00 V(x) o a x 
516 Chapter 9 Quantum Mechanics b. The boundary condition requires the wave function to vanish at x = 0 and a. Use this condition to show that the allowable energy states are En = n 2 Jr2fl2/2a 2 m, where n = 1,2,3.... Show the corresponding normalized wave functions are {2 sin[ nx v.ya. c. Explicitly verify that the first four wave functions are orthonormal and plot the wave functions. Required Packages In[2J:= Needs[nGraphics'Legend,n] Solution In [3 J : = Clear ["Global ' * n] ; a. The one-dimensional wave equation is li 2 1/1" [x] In[4J:= eq1 = 0 == (V-En) [x] - 2m Consider the region O<x<a, where the potential is zero. Schrodinger's equation reduces to In[5J:= eq2 = eq1/.V -+ 0 I/J" (x) f12 Out[5J= 0==- -Enl/J(x) 2m If you simplify the notation by expressing the energy En in terms of the wave-number k, li 2 k 2 In[6J:= krule = En-+-; 2m then Schrodinger's equation becomes In[?J:= schrod = Solve [eq2/.krule,1/1" [x] ] [[1,1] ]/.Rule -+ Equal Out[?J= I/J" (x) == -k 2 1/J(x) The general solution for this simple one-dimensional problem follows immediately from DSol ve: In [8J : = dsol = DSolve [schrod, , x] [ [1, 1]] Out [8J = I/J --> Function [ {x}, c 1 Cos (k x) + c 2 Sin (k x) ] The constants {C [1], C [2]}, as well as the allowable values of the energy En, are determined by the boundary conditions and by normalizing the wave function. The solution is returned in pure form so Reduce, applied in the next section, returns all the solutions for the boundary values. 
9.2 One-Dimensional Schrodinger's Equation 517 b. The boundary condition requires the wave function to vanish at x=O and a. Set I/t to zero at x=O and x=a and then use Reduce to find all possible solutions, In[9J:= soll = Reduce[{"'[O] == 0, "'[a] == O}/.dsol] Out[9J= C 1 == Oi\c 2 == oVcl == Oi\Sin(ak) == 0 The only nontrivial solution is C [1) =0 and Sin [a k) =0, which is equivalent to set- ting k=  where n is an integer. The allowable energy states follow from En= k2 : k 2 fl2 n7f In[10J:= En == -I .k-+- 2m a n 2 JT 2 h 2 Out[10J= En ==- 2a 2 m Note that the energy levels differ by a factor of n 2 . The solution for the wave function becomes In[llJ:= "'[x_,n_] =",[x] l.dSOl/.{C[l] -+0, k-+ n a 7f } ( nJTx ) Out[llJ= c 2 Sin  The constant C [2) follows from normalizing the wave function according to the criteria, 1= f I/t[x] * I/t[x]dx: In[12J:= normEq = 1 == Integrate ["'[X, n]2, {x, 0, a}] II Simplify[#, Element [n, Integers]]&11 Solve[#, C[2]] [[2,1]]& Vi Out[12J= c 2 -> ja where only the positive root was kept. The complete normalized wave function is In[13J:= "'[x.., n_] = ",[x, n] I .normEql ISiqllify Vi Sin ( 7 J Out[13J= ja C. You can integrate over the product of the wave functions to verify that they are or- thonormal. Form a table of integrations over the products of the first four wave functions, In [14J:= table = Table [Integrate ["'[x, i] "'[x, j], {x, 0, a}], {i, 4}, {j, 4}]; Displaying the results with TableForm, it follows that In[15J:= TableForm[table, TableBeadings -+ {Table[",[i], {i, 4}], Table["'[j], {j, 4}]}] 
518 Chapter 9 Quantum Mechanics Out[15]= 1/1(1) 1/1(2) 1/1(3) 1/1(4) 1/1(1) 1 0 0 0 1/1(2) 0 1 0 0 1/1(3) 0 0 1 0 1/1(4) 0 0 0 1 To graph the wave functions make a table of the wave functions for the first four energies and apply Plot. It follows that In [16] : = Plot [Table [r/f[n, x], {n, 4}] /. {a -+ 1} / /EValuate, {x, 0, 1}, PlotStyle -+ {{}, Dashing [{O. 05}], Dashing[{0.03}],Dashing[{0.01}]}, PlotLabel -+ StyleForm[r/f, FontSize -+ 14, FontWeight -+ Bold] , Plot Legend -+ {nn = 1 n, On = :2 0, nn = 3 n, on = 4 n }, LegendPosition -+ {1, -112}]; '" \ ! \! o . 2\ 0.4 !\O . r; \ .8 t \ \! ,,' \ Ii \ Y 1\ \/ / \,,,,,1 \ _ I ......... /\,,,,,' -n=1 -0.5 -1 - -- n=3 -n=4 This plot made use of PlotLegend and LegendPosition found in the add-on package Graphics' Legend' that was loaded at the beginning of this problem. Notice the wave functions with odd n={l, 3, . . .} are symmetric about x=1/2, and the wave functions with even n={ 2,4, . . . } are asymmetric. . PROBLEM 2 Particle Bound in a Finite Potential Well. Consider a potential well given by V [x] = -VO<O if -a<x<a, and V [x] = 0 otherwise. This problem is the finite generalization of the infinite well solved in the previous problem. Suppose a particle with V(x) = 0 V(x) = 0 V(x) = -Yo -a +a x 
9.2 One-Dimensional Schrodinger's Equation 519 negative energy En=-Wtt<O is bound in the finite well. The wave function follows from the solution of Schrodinger equation but the solution must be tteated separately in the three regions: x<-a, -a<x<a, and a<x. The boundary condition requires the wave function to vanish as x+oo and as x-oo. In addition, the wave function and its derivative must be continuous across the boundaries of the well. a. Show that the wave functions in the well, to the right of the well, and to the left of the well, can be written as I/tW = cSym Cos[kWx] + cAsym Sin[kWx] I/tR = cRe- qLRx I/tL = cLe qLRx -a < x < a x>a x< -a where kW = ...{iym(VO - Wn) h d ...{i yWn m an qLR = h . Notice the parameter kW and qLR are real since VO>Wn>O. Also observe that in the well there are symmetric (cAsym=O) and asymmetric (cSym=O) oscillating solu- tions. b. Use the boundary condition that the wave function and its derivative are continuous across the well's boundaries. Consider separately the boundary conditions that fol- low for the symmetric (cAsym= 0) and asymmetric (cSym= 0) in-well waves. Apply Reduce to get all possible solutions for the boundary conditions and determine the constants {CL, CR}. Also show for the symmetric wave that the energy eigenval- ues follow from the equation Tan [a kw) = 1r: and for the asymmetric wave the energy eigenvalues are determined by Tan [a kW) = - : . c. Consider the four potential well depths, VO={100, 200, 500, oo} and set {al, ml, hl}. Use graphic procedures to solve for the energy eigenvalues. Express the energy eigenvalues in a form similar to the infinite well by measuring the energy levels from the bottom of the well and parameterizing the energy values with n where Wn= Vo - n s 2 ":h 2 . Verify that the value of n approaches an integer in am the limit that VO 00. d. Repeat the energy eigenvalue determination using the command FindRoot with the parameters found in part c. e. Let VO=100 and plot the symmetric and asymmetric wave functions that correspond to the energy eigenvalues found in part d. Solution In[i?]:= Clear [nGlobal ' * n]; a. This one-dimensional boundary problem illusttates a simple nontrivial solution of Schrodinger's equation where the wave can penettate into the walls of the well. Begin with 
520 Chapter 9 Quantum Mechanics the one-dimensional Schrodinger equation, li 2 1/1" [x] In[18J:= schrodeq = 0 == (V - En) r/f[x] - 2m First consider the solution in the well (-a<x<a) where V<En<O. If you express the energy En in terms of the wave-number kW, kW 2 li 2 In [19 J : = EWrule = {En -+  + V}; then the solution of Schrodinger's equation can be expressed as In[20J : = r/f[x] I. DSolve [schrodeq, r/f[x], x] [ [1, 1]] I. EWruleilExpTOTrig II Simplify IIPowerExpand Out[20J= (C 1 +C 2 ) Cos(kWx) +i (C 1 -C 2 ) Sin(kWx) The wave-number kW is related to the energy via the relation kW = v 2m (;n-V) . If you rewrite this expression in terms of Vo and WD then -{21m (En - V) In[21J:= kWrule = kW-+ Ii I.V-+ -VO/.En-+-Wn . f2 y m ( va - Wn ) Out[21J= kW.... "yL. h where VO>WD>O. The value of kW is real and the solution is oscillatory. It is insttuctive to separate even and odd solutions. Thus, you define the constants so the wave function in the well t/IW [x] is In [22J := I/M[x.] = cSym Cos [kWx] + cAsym Sin [kWx] ; Now consider the solutions to the left of the well where x<-a and to the right of the well where a <x. The potential is zero in both regions. If we express the energy En in terms of the wave-number kLR, kLR 2 li 2 In [23J := ELRrule = {En-+ }; and then solve SchrOdinger's equation with V=O, it follows In [24J : = r/f[x] I. DSolve [schrodeq, r/f[x], x] [[1, 1]] I. V -+ O/.ELRrule 1 ISiD\plify IIPowerExpand Out[24J= eikLRXcl +e.ikLRXC2 The value of kLR is -{2 ...jiU. In [25J := kLRrule = kLR -+ Ii I. En -+ -Wn l/PowerExpand i Y2 ymywn Out[25J= kLR.... h 
9.2 One-Dimensional Schr6dinger's Equation 521 It is convenient to define kLR=J: qLR so that qLR is real: -{2 -Vm Wn In[26]:= qLRrule= qLR-+ h ; The solution becomes In [27] : = r/f[x] I. DSolve [schrodeq, r/f[x], x] [ [1, 1]] I. V -+ 01 .ELRrule 1 .kLR -+ I qLRII Simplify II PowerExpand Out[27]= eqLRXcl + e. qLRx c 2 The wave function has both exponentially decreasing and increasing terms. If you choose the values of C [1) and C [2) so the wave vanishes to the right of the well as x goes to +00 then it follows that In [28] := l/IR[x_] = cRe- qLRX ; (*x > a*) To the left of the well the wave function must vanish as x goes to -00 so In [29] : = I/fL [x..] = cL e+QLRx ; (*x < -a*) b. The boundary condition requires the wave function and its derivative to be continuous at the boundaries. Four equations follow from applying these continuity conditions at x=a and x=-a, In[30]:= eql = { (l/fL[x] -I/M[x] == 0) I. {x- > -a}, (I/M[x] -1/IR[x] == 0) I. {x- > +a}, (1/fL' [x] -I/M' [x] == 0) I. {x- > -a}, (I/M' [x] -I/IR' [x] == 0) I. {x- > +a}} Out[30]= {e.aqLRcL-CSymCOS(akW) +cAsymSin(akW) ==0, _e. aqLR cR + cSym Cos (a kW) + cAsym Sin (a kW) == 0, cL e. aqLR qLR - cAsymkW Cos (a kW)- cSymkW Sin(akW) == 0, cRe.aqLRqLR+ cAsymkWCos(akW) -cSymkWSin(akW) ==o} To find the wave function constants { cSym, cAsym} and the energy eigenvalue equa- tion you consider separately the symmetric (cAsym=O) and asymmetric (cSym=O) solu- tions. First proceed with the symmetric solutions. If you set the constant cAsym to zero in eql then the boundary condition reduces to In [31] : = (eq2 = eql1 .cAsym -+ 0 ) IIColumnForm 
522 Chapter 9 Quantum Mechanics Out [31] = cL e. aqLR - cSym Cos (a kW) == 0 cSym Cos (a kW) - cRe. aqLR == 0 cL e- aqLR qLR - cSym kW Sin (a kW) == 0 cR e. aqLR qLR - cSymkW Sin (a kW) == 0 You get all boundary value solutions by applying Reduce to eq2. Include a few ex- tta consttaints {cL*O, cR*O, cSym*O, kW*O, kLR*O}, so you are not burdened with trivial solutions, and apply Reduce In [32] := eq3 = Reduee[ {eq2, eL" 0, eR" 0, kW" 0, qLR " 0, eSym" 0, Cos [ a kW] " 0 } / /Flatten , {eL, eR} ] ; eq3 / /ColumnForm Out [32] = cL == cSym e aqLR Cos (a kW) cR == cSym e aqLR Cos (a kW) qLR == kW Tan (a kW) cSym * 0 kW * 0 Cos (a kW) * 0 Sin(akW) *0 The first two equations give the wave function amplitudes {cL, CR} and the third part gives the energy eigenvalue equation. Apply Solve to eq3 to separate out the amplitudes. In[33]:= symBol = Solve[eq3, {eL,eR}] //Siqllify//Flatten Out[33]= {cL-+cSyme aqLR Cos(akW), cR -+ cSym e a qLR Cos (a kW) } The third equation in eq3 gives the energy eigenvalue equation, which can be written as In[34]:= symEn = Tan [a kW] == qLR/kW; Let us now turn to the case of the asymmetric wave function. The solution is completely analogous to the symmetric case. The primary difference is that you let cSymO and set cAsym*O. The boundary conditions reduce to In[35]:= eq4 = Reduee[ { eql/ . eSym -+ 0, eL" 0, eR " 0, kW " 0, qLR " 0, cAsym " 0, Cos [ a kW] " 0 } / / Flatten, {eL, eR} ] ; eq4 / /ColumnForm 
9.2 One-Dimensional Schr6dinger's Equation 523 Out[35J= cAsyrn e a qLR kW Cos (a kW) cL == grR cAsyrn e a q kw Cos (a kW) cR == - qLR kW Cos (a kW) Sin (a kW) ==- qLR cAsyrn t 0 kW to qLRtO Cos(akW) to The first two equations give the amplitudes { cL, CR} and the third part gives the energy eigenvalue equation. Apply Solve to eq4 to get the wave amplitudes, In[36J:= asymSol = Solve [eq4 , {eL, eR} ] / /Simplify / /Flatten { cAsyrn e a qLR kW Cos (a kW) cL -7 , qLR cAsyrn e qLR kW Cos (a kW) } cR -> - qLR Out[36J= The energy eigenvalue equation for the asymmetric case is In[3?J:= asymEn = 'l'an[akW] == -kW/qLR; C. The ttanscendental equation for the symmetric energy eigenvalues follows from symEn and asymEn gives the asymmetric energies. Although you cannot analytically solve these energy eigenvalue equations, you can graphically solve them. Choose {al, ml, fil} and consider the four potentials VO={lOO, 200,500,00}: In [38J:= values = {a... 1, m... 1,11... 1, VO ... { 100, 200, 500, oo}} ; Before you proceed, re-parameterize the energy in terms of the expression W%l=vo- n 8 2fj2 : am n2h2 In[39J:= nRule = wn... vo - ---y-; Sa m This energy form is chosen so that in the infinite well limit (VO 00) the value of n approaches an integer. You can monitor the progression of the solutions toward, or away, from the case of the infinite well by comparing the values of n with integers. Define the rules { 1 2m (VO -wn) 1 2 (wn) m } . In [ 40 J : = kRules = kW... h ' qLR ... h ' and consider the energy values for the symmetric solutions. The eigenvalue equation for n follows from symEn In[41J:= eq5 = symEn/.kRules/.nRule//PowerExpand 
524 Chapter 9 Quantum Mechanics Out[41]= Tan ( n 2 71" ) 2-{2a...jffi vo- Sa m n71"h where nRule was used to express the solutions in terms of n. The allowed values for n follow from plotting the left and right sides of eq5 as a function of n, and observing where the curves intersect. Instead of plotting the left and right sides of eq5 you can equivalently plot the ArcTan of the two sides: In[42]:= pt1 = plot [ {ArC'l'an[eqS [[1]]], ArO'l'an[eqS [[2]]]}/. va1ues//Eva1uate, {n,O,9}, Frame ... 'l'rue, Frame'l'icks ... {{ {1, nn = 1 n }, {3, nn = 3 n }, {S, nn = sn}, {7, nn = 7 n}, {9, nn = 9 n }}, {O,O.S,l,1.S}}, p1otRange... {O.4, 1.6}, Disp1ayFunction ... :Identity] ; Attach the following text to enhance the readability of the graph. In[43]:= text = { 'l'ext[ nVO_oon, {6,1.S}], 'l'ext[ nvo = soon, {6,1.3}], 'l'ext[ nvo = 200 n , {6,1.1}], 'l'ext[ nvo = loon, {6,O.a}]}; Combining the text and graph along with grid lines, it follows In[44]:= Show [pt1, Graphics [text] , GridLines... Automatic, Disp1ayFunction ... $Disp1ayFunction] ; n=l n=3 n=5 n=7 n=9 1 1.5 1.5 1 n=l n=3 n=5 n=7 0.5 n=9 0.5 
9.2 One-Dimensional Schr6dinger's Equation 525 The four sloping horizontal curves come from the four choices ofvO substituted into the right-hand side of eq5. The slanted vertical lines come from the arctan[tan[!!j-]] function on the left-hand side of eq5; the intersections of these curves with the sloping horizontal lines give the values of n corresponding to the energy eigenfunctions. The sttaight vertical lines are an artifact of the Tan [x] function, which is singular at X=Il1T /2 for odd n; these lines and their intersections should be ignored. The curves intersect just below the odd- integer values. Notice that in the case of an infinite potential (VO=oo), the eigenvalues are precisely the integers n= { 1, 3 , 5 , 7 , 9, . . .} as expected. As Vo decreases, the values of n deviate more and more from integers. The asymmetric solutions follow from the equation asymEn, In[45]:= eq6 = asymEn/.kRu1es/.nRu1e//powerExpand Out[45]= Tan ( nn ) == _ nnn 2 22 2 2 -{2 a ..;m va - n s : 2 : Take the ArcTan of both sides of eq6 and plot the two curves. Define the text In[46]:= text = { Text [ nVO.oo n , {7, O}], Text [ nvo = soon, {7, -0.4}], Text[nVO=200 n , {7,-0.7}], Text [ nvo = loon, {7, -0.9 }]}; and display the results In[47]:= P1ot[ {ArCTan [eq6 [[1]]], ArcTan [ eq6 [[2]]]} /. va1ues//Eva1uate, {n,0.,9}, Frame ... True, FrameTicks ... {{{2, nn= 2 n }, {4, nn= 4ft}, {6, ftn= 6ft}, {s,nn=sn}}, {-1.5, -1, 0, 0.5, 1,1.5}}, P1otRange... {-1, 0.1}, GridLines... Automatic, Epilog... text ]; 
526 Chapter 9 Quantum Mechanics n=2 n=4 n=6 n=8 o 1 The intersections of the sloping horizontal curves with the sloping vertical curves are just below even-integer values. At VO=oo the values of n are even integers. d. Let us now solve for the symmetric and asymmetric n values by using the command FindRoot. The n values follow from the function In[48]:= nVa1ues [eq_, potentiaL, guess_] .- (n/ . FindRoot[ eq/ . {m... 1, a ... 1, h ... 1, VO ... potential} / /Eva1uate, in, guess}] [[1]]) The term eq stands for eqS in the symmetric case and for eq6 in the case of the asymmetric solutions. An initial guess must be given to find the roots. For the symmetric solutions, consider three different values for the potential, VO={100, 200, SOO} and solve for the first five eigenvalues. Let us make an initial guess for the five values of n that are just below odd integers: In[49]:= symGuess = {0.9, 2.9, 4.9, 6.9, 8.9}; The values of n are In[50]:= symVa1ues = {nVa1ues[eqS, 100, #] , nVa1ues[eqS, 200, #] , nVa1ues[eqS, SOO, #]}6i: I@. symGuess; The list for the asymmetric solution follows in a similar manner. Let the guess be just below the even integers, In[51]: = asymGuess = {lo9 , 3.9, S.9, 7.9 }; and then it follows that In [52] : = asymVa1ues = {nVa1ues[eq6, 100, #] , nVa1ues [eq6, 200, #] , nVa1ues [eq6, SOO, #]}6i: f@. asymGuess; 
9.2 One-Dimensional Schr6dinger's Equation 527 Combining the two classes of solutions and displaying the results in table form, you find In[53]:= partition[ Sort[{symva1ues,asymva1ues}IIF1atten], 3]11 'l'ab1eForm[#, 'l'ab1eSpacing... {O, 2}, 'l'ab1eEeadings ... { { On = 1", "n = 2", "n = 3", On = 4" , An = 50 IOn = 6 8 , An = 7", An = 8" I "n = gO}, {AVO = 100", AVO = 200", AVO = 500"}} ]6i: Out[53]= vo = 100 VO = 200 VO = 500 n=l 0.933848 0.952339 0.969335 n=2 1.86702 1.90442 1. 9386 n=3 2.79876 2.85598 2.90773 n=4 3.72819 3.80671 3.87664 n=5 4.65414 4.75628 4.84526 n=6 5.5749 5.70426 5.8135 n=7 6.48773 6.65015 6.78128 n=8 7.38736 7.59322 7.74848 n=9 8.26041 8.53247 8.71498 These are the first nine energy values for the potentials VO=100, 200 and 500. e. Let us graph the first nine symmetric and asymmetric wave functions for the potential VO=100. First consider the symmetric waves. Define the parameters and rules for the symmetric case: In[54]:= symRu1es = {kRu1es, nRu1e, symBol, a... 1, h ... 1, m...1,VO ...100, cSym...100, cAsym... O}II Flatten { -{2 y m (VO - Wn) -{2 ym Wn Out[54]= kW.... f1 ,qLR.... f1 ' n 2 n2 f12 Wn .... VO - , cL .... cSym e a qLR Cos (a kW) , 8 a m cR .... cSym e a qLR Cos (a kW) , a .... 1, f1 .... 1, m....1, VO ....100, cSym....100, cAsym.... o} Also define a wave function valid for all values of x. The complete symmetric wave func- tion to the left, inside, and right of the well is, In[55]:= C1ear[s,a]; (*Symmetric*) s[x.-I; x < -I, nO_] : = (I/!L [x] II .symRu1esl I. {n- > nO}) ; s[x-l; -1 <= x < I, nO.] : = ([x] II .symRu1esl I. {n- > nO}) ; s[x-l; x >= I, nO.] : = (!/IR [x] II .symRu1esl I. {n- > nO}) ; 
528 Chapter 9 Quantum Mechanics The values nO are the eigenvalues for the wave function. The five symmetric energy eigenvalues ofWn forVO=100 are given by In [56] := symEnergy = nValues[eq5, 100, #]Ii:/8-symGuess; The graphics for the corresponding wave functions are In[57]:= plotsym = Plot[s[x,#]//.symRules//Evaluate , {x, -2, 2} , PlotLabel- > I!IumberForm[#, 2] , Axes- > None , DisplayFunction- > :Identity ] Ii: /8- symEnergy; Displaying the results with GraphicsArray, you obtain In[58]: = Show [GraphicsArray [plotsym [ [1,2,3]], plotsym[ [4,5]]]]; 0.93 2.8 4.7 A -J\r -W- 6.5 8.3 -mv- . Now consider the plot for the four asymmetric wave functions. Define the parameters and rules for the asymmetric wave: In [59] : = asymRules = {kRules, nRule, asymSol, a -0 1,11 -0 1, m-ol,VO -0100, cAsym-olOO, cSym-o O}// Flatten { V2 y m (Va - Wn) Out[59]= kW.... !J ' V2 ym Wn n 2 7f2!J2 qLR .... !J ' Wn .... va - 8 a 2 m ' cAsym e a qLR kW Cos (a kW) cL.... , qLR cAsym e a qLR kW Cos (a kW) cR.... - , a.... 1, qLR !J .... 1, m.... 1, va .... 1 a a, cAsym.... 1 a a, c Sym .... a} The complete asymmetric wave function to the left, inside, and right of the well is, 
9.2 One-Dimensional Schrodinger's Equation 529 In[60]:= (*Asymmetric*) al/r[x-/; x < -1, nO_] : = (I/!L [x] / / .asymRules/ /. {n- > nO}) ; al/r[x-/; -1 <= x < 1, nO.] : = (f/M[x] / / .asymRules/ /. {n- > nO}); al/r[x-/; x >= 1, nO_] : = (l/IR[x] / / .asymRules/ /. {n- > nO}); The five asymmetric energy eigenvalues WD forVO=100 are given by In[61]:= asymEnergy = nValues[eq6, 100, #]Ii:/ksymGuess; The graphics follow from In [62] := plotasym = Plot[al/r[x,#]//.aSymRules//Evaluate , {x, -2, 2} , PlotLabel- > NwnberForm[#, 2] , Axes- > None , DisplayI!'uDction- > :Identity Ii: /fl.asymEnergy; Displaying the asymmetric results, it follows that In[63]:= Show[GraphicsArray[plotasym[[1,2]],plotasym[[3,4]]]]; 1.9 3.7 -JL --P0v 5.6 7.4 -W- -1Mr- . PROBLEM 3 Particle Hitting a Finite Step Potential. Consider a particle of energy En approaching a potential barrier defined by V[x] = 0 ifx<O; and V [x] =VO ifx>O. The general solution of Schrodinger's equation with constant potential is given by c1e ikx + c2e- ikx , where the wave vector is k2 = En - YO. The constant En represents the energy and the constant potential is vo. The wave to the left of the barrier iftL [x] has an incident wave and a reflected wave so it can be written as iftL[x] = e ikLx + e-ikLxR where kL = .v m."En and R is the reflection amplitude. The wave to the right of the b arrier iftR [x ] has. only a ttansmitted wave so it is of the form iftR[x] = eikRxT, where kR = .v 2m(E-VO) and T is the ttansmission amplitude. a. Use the boundary condition at the barrier to evaluate the amplitudes for the reflected and ttansmitted waves and show: R = t and T= JR ' 
530 Chapter 9 Quantum Mechanics V(x) = +V o V(x) = 0 x=O b. The flux follows from 2:m (ift*Vift- Vift*ift) and the current densities follow from apply- ing the flux expression to the appropriate parts of the wave function. The coefficient of ttansmission TT is defined as the ratio of the ttansmitted current density to the incident current density. Likewise the coefficient of reflection RR is the ratio of the reflected current density to the incident current density. Show that TT and RR can be d - (kL-kR)2 d - 4kLkR PI d th . expresse as RR- (kL+kR)2 an TT- (kL+kR)2 ' ot RR, TT an elf sum RR+TT as a function of En. c. Plot the real and imaginary parts of the wave function for energies above and below the barrier. d. Use Plot3D to graph the wave function as a function of the two parameters {x, En}. e. An animation is generated by forming a table of wave plots evaluated at different times. Animate the real parts of the incident, reflected, and ttansmitted waves for energies above and below the barrier. Required Packages In[64J:= Needs[nGraphics'Legend'n] Solution In [65J : = Clear ["Global' * "]; a. The general form of the wave is c1e ikx + c2e- ikx , where the wave vector is k2 = En - VO. A particle that approaches from the left (x<O) is reflected by the barrier at x=O so it has an incoming and reflected part: In[66J:= l/1L[x.] = e ikLx + e-ikLXR; The term e+ ikx represents the incident wave; without loss of generality you can set its coefficient to one. The term e- ikLx represents the reflected wave with amplitude R. To the left of the barrier the potential is Vo=o so the wave number kL is given by In[67J:= kLRule = kL... -{2 2m ; 
9.2 One-Dimensional Schr6dinger's Equation 531 The wave to the right of the barrier (x>O) has only a ttansmitted component ttaveling to the right, so it is of the form In[68J : = l/IR[x_] = e ikRx T; where the wave vector kR is _ r::  m (En - VO) In [69 J : = kRRule = kR ... 'V 2 fl2 ; The boundary condition requires the wave function and its derivative to be continuous at x=O. The two boundary equations are In[70J:= boundary = {1/fL[x] == l/IR[x], 1/fL' [x] == I/IR' [x] )//.x... 0 Out[70J= {R + 1 == T, i kL - i kLR == i kRT} Solving for the T and R amplitudes, you obtain In[71J:= RTrule = Solve [boundary, {R, T)]//Flatten// Sim,plify { kL-kR 2kL } Out [71J = R... kL + kR ' T... kL + kR b. The current densities follow from finding the flux due to the appropriate parts of the wave function. To find the ttansmission and reflection coefficients you must define the flux operator 2m (ift*Vift - Vift*ift). To consttuct the flux operator you first define the complex conjugate symbol (see Chapter 1), In [72J : = 8XP-': = 8XP /. {Clex [a., b_] H Clex [a, -b] } The "SuperStar" notation exp_* is done by enclosing the expression with () and making a superscripted *. It is just the complex conjugate operator. For example, In[73J:= (a_ib+e- iS )* Out[73J= a+eis+ib Conttast this with the built-in function Conjugate: In[74J:= Conjugate [a_ib+e- iS ] Out[74J= Conjugate(a-ib) +eiConjugate(s) The Conjugate function is more cautious as it does not assume {a, b, 8} are real. You next define the V operator, In [75J := Vf_ : = D[f, #]6i: I@. {x, y, z) which takes the gradient of a scalar, e.g., 
532 Chapter 9 Quantum Mechanics In[76]:= VI/r[x ] Out[76]= {IJ/ (X), 0, O} The flux operator is 11 In[77]:= flux[I/r_] := -(I/r*VI/r-VI/r*I/r) //Siq)lify 2im If you apply flux to iftL [x] In[78]:= l/IL[x]//flux//Siq)lify kL (R 2 - 1) h Out[78]= {- m ,0, O} then this expression has both the incident and reflected flux. You can obtain just the incident flux by setting RO, In[79] : = incFlux = flux[1/IL [x]] /. {R... O} { kLh } Out[79]= ----rn-' 0, ° The reflected flux is simply the difference of the incident flux and the total flux on the left -hand side, In[80]:= Rflux = (incFlux - flux [I/IL [x] ]) / / Sim,plify { kL R 2 h Out[80]= ,o, o} Finally, the ttansmitted flux follows from applying flux to iftR [x], In[81]:= Tflux = flux [I/IR [x] ] { kRT2h Out[81]= ,o, o} The vector currents are in the x direction so you can drop the vector notation and con- sider only the first component of the vectors. The ttansmitted and reflected coefficients follow from dividing the reflection and ttansmitted currents by the incident current: In [82] := RR, TT = Rflux[ [1]] /incFlux[ [1]], Tflux[ [1]] /incFlux[ [1]] kRT 2 Out[82]= {R 2 , kL} If you substitute the solutions for R and T into this expression, it follows that In[83]:= RR, TT = RR, TT/ .RTrule [83 { (kL-kR)2 4kLkR } Out]= , (kL + kR)2 (kL + kR)2 As a cross check, you can verify that the sum of the ttansmitted and reflected coefficients equals unity, thereby demonsttating current conservation: 
9.2 One-Dimensional Schr6dinger's Equation 533 1 In[84]:= RR+TT//SiJllplify Out[84]= 1 Let us plot as a function of En the ttansmitted and reflected coefficients as well as their sum. Choose the following specific numerical values In[85]:= values = {m-+ l,lI-+ 1, VO -+ 1}; Applying Plot to RR, TT and TT+RR, it follows In[86]:= Plot[ {RR, TT, TT + RR}/ .RTrule/ .kLRule/. kRRule/.values//Evaluate, {En, 1, 2}, Axes Label -+ {"ED, "Coefficient D }, PlotStyle -+ {Dashing[{0.06, 0.02}], Dashing[{0.02}],O}, plotLegend-+ {"RRD, DTT", DTT+RRD}, LegendPosition -+ {1, -1/2}, PlotRange-+ {O,l}]; Coefficient 1 o . 8 //-- 0.6 " 0.4\ o . 2 '..... ----- 1.21.41.61.82 E ------------ -- RR nn TT - TT+RR C. Consider the plots for the real and imaginary parts of the wave function when the incoming energy is greater than the barrier (En>VO), and for the case when the energy is below the barrier (En<VO). Let us first evaluate all the parameters in I{tL [x] and I/tR [x] . Define the general rule In[87]:= kRule = {kLRule, kRRule}; and then the evaluation of {I{tL [x] I I/tR [x] } is given by wave [x, En] : In[88]:= wave [x., En_] = {[x],[x]}/.RTrule/.kRule/. values / / Simplify; The function wave is a list of both the wave to the left and right of the barrier with all substitutions. Use Which to consttuct a wave I{t [x, En] that takes the appropriate solution for x to the left and to the right of the barrier: In [89]:= "'[:IL, En.] : = Which [x:s 0, wave [x, En] [[1]], x> 0, wave [x, En] [ [2]]] 
534 Chapter 9 Quantum Mechanics Now define the function waveplot2D to plot the Re and :Im parts of the wave. In[90J:= waveplot2D[Energy.] := Plot [{IIr [x, Energy] / / Re, 1/1 [x, Energy] / /:Im} , {x, -10, 10}, PlotStyle -+ {{}, Dashing [{O. 02}] }, AxesLabel -+ {"x", "y"}] ; Consider the case where the incoming particle has energy above the barrier En=l.l (i.e., 110% ofVO). The plot of the real and imaginary parts of the wave are In[91J:= waveplot2D[1.1]; y 1. , \ \ \ \ \ \ \ \ \ \ '3 \ I x \ I -0/5 -1 .5 The real part of the wave function is denoted by a solid curve and the imaginary part by a dashed line. Notice, the wave is oscillatory but the frequency decreases on the right of the barrier. Consider the case where the incoming particle has energy below the barrier En=O. 9 (i.e., 90% ofvo): In[92J:= waveplot2D[0.9]; y -10, ,I x 10 Notice that the ttansmitted wave is exponentially damped as the wave tunnels into the classically forbidden region. d. Let us illusttate how the wave function behaves as a function of both the energy and x by using Plot3D. Plot the Re and :Im parts of the wave function for values of En between 
9.2 One-Dimensional Schr6dinger's Equation 535 0.5 and 1.5. First, you have for the real component, In[93J:= Plot3D[[x,Energy]//Re, {x,-lO,lO}, {Energy, 0.5, lo5}, Plotpoints -+ 50, Axes Label -+ {nx n , nEnergyn, nn}] ; 10 Then, for the imaginary component, you have In[94J:= Plot3D[[x,Energy]//Im, {x,-lO,lO}, {Energy, 0.5,lo5}, Plotpoints -+ 50, AxesLabel -+ {Ox n , nEnergyn, nn}] ; 10 Observing the two graphs it follows that for Energy<l and x>O the wave damps as it tunnels into the classically forbidden region. For Energy> 1 the wave energy is above the barrier height and the wave continues to oscillate for x>O. e. Let us animate the real part of the incident, reflected, and ttansmitted waves. Multiply . Ent by the factor e-' tI, where Ii is set equal to one, to get the time dependence for the wave function. The graphics for the time dependent wave function is generated by the function timePlot. 
536 Chapter 9 Quantum Mechanics In[95]:= timePlot[time.,En.].- Plot [{Exp [-:I En time] "'[x, En] I IRe, Exp [-:I En time] "'[x, En] I 1:Im}, {x, -10,10}, PlotStyle-+ {O, {'1'hickness[0.008]}}, PlotRange -+ {-2, 2}] ; Here is a sample of timePlot for En<VO, In[96]:= timeplot[1.,O.9]; 10 The thin line is the real part, and the thick line is the imaginary part. To animate the wave you embed timePlot inside a Do loop, and plot this for a series of time steps. We choose timestep so that for a given number of frames, the animation moves through a complete cycle. Here is a sample with En<VO In [97] := frames = 1; Energy = 0.9; . 2 t1lll8step = (frames) Energy Do [timePlot [n timestep , Energy] ; , {n, 1, frames}] 10 where we have set frames=l. To generate more frames increase this number. Likewise, here is a sample with En>VO. 
9.2 One-Dimensional Schrodinger's Equation 537 In[98]:= frames = 1; Energy = 1.1; 271" timestep = ; (frames) Energy Do [timePlot [n timestep, Energy]; , {n, 1, frames}] 2 -2 . PROBLEM 4 Particle Propagating Toward a Rectangular Potential. Consider a par- ticle with energy En>O propagating from the left (x<-a) toward a rectangular well or bar- rier. The potential is described by: V (x) =VO if -a<x<a and V (x) =0 otherwise, where Vo is a constant. IfvO>O, then the potential describes a barrier and for Vo<o the potential describes a well. The general solution of Schrodinger's equation with a constant potential is given by c 1 e ikx + cze- ikx . The wave solutions to the left, right, and in the center of the potential must be tteated separately. The wave to the left of the potential, called I{tL, has an incoming and reflected component. You can set the amplitude of the incoming wave to one and let R be the amplitude of the reflected wave. The wave to the right of the potential, called t/tR, has only a transmitted wave; let its amplitude be T. The wave in the potential region (-a<x<a) can be described by two amplitudes, call them A and B. The boundary conditions determine the amplitudes {A, B, R, T}. V(x) = +V o Particle V(x) = 0 V(x) = 0 -a +a x a. Write the general form of the wave function to the left, center, and right of the welUbarrier. b. Use the boundary condition to evaluate the wave amplitudes and show 
538 Chapter 9 Quantum Mechanics e- 2iakLR (-1 + e 4iakW ) (kLR - kW)(kLR + kW) R= e 4iakW (kLR - kW)2 - (kLR + kW)2 2e- ia (kLR-kW)kLR(kLR + kW) A=- e4iakW (kLR - kW)2 - (kLR + kW)2 2e-ia(kLR- 3kW)kLR(kLR-kW) B= e4iakW(kLR-kW)2 -(kLR+kW)2 4e- 2ia(kLR-kW)kLRkW T=- e4iakW(kLR-kW)2 -(kLR+kW)2 c. The coefficient of ttansmission (TT) is defined as the ratio of the ttansmitted current to the incident current. Likewise, the reflection coefficient (RR) is defined as the ratio of the reflected current to the incident current. Show the x-component of the reflection coefficient is (kLR 2 - kW 2 )2 sin[2akW]2 RR= 4kLR 2 kW 2 cos[2akW]2 + (kLR 2 + kW 2 )2 sin[2akW]2 and the x-component of the ttansmission coefficient is 4kLR 2 kW 2 TT = 4kLR 2 kW 2 coS[2akW]2 + (kLR 2 + kW 2 )2 sin[2akW]2 Verify that TT+RR=l. d. As a function of En, plot the coefficients of ttansmission (TT) and reflection (RR) for a potential well (VO<O) and for a potential barrier (VO>O). e. As a function of the energy and potential, use Plot3D to plot the reflection and ttansmission curves. f. Plot the real part of the wave for the complete range of x. g. Animate the time dependence of the real part of the wave as it propagates through a barrier (VO>O, O<En<VO). Solution In[991 : = Clear [nGlobal ' * n]; a. The general solution of Schrodinger's equation with a consta nt poten tial is given by . k . k . v 2m (En-V) cle' x + c 2 e-' x. The general form of the wave number IS k = Ii . For x < -a there is an incident wave ttaveling to the right, and a reflected wave ttaveling to the left. The amplitude for the incident wave is set equal to one without loss of generality, and the amplitude for the reflected wave is called R. The form of the wave is In[lOOl:= t/fL[x...] = e ikLRx + e- ikLRx R; There is only a ttansmitted wave with amplitude T for x > +a, so the wave becomes In[lOll:= r/1R[x...] = e ikLRx T; 
9.2 One-Dimensional Schrodinger's Equation 539 The wave function in the centtal region (-a<x<a) is In[102]:= rIM[:L] = Be- ikWx +Ae ikWx ; Given the form of the potential function the expressions for kLR and kW are { J::  m (En -VO) In[103]:= kRules = kW-+ 'v2 1I 2 ' kLR -+ ...j2  2m }; b. The boundary condition requires the wave function and its derivative to be continuous across the boundaries. Applying these conditions at x=a and x=-a gives four equations: In[104]:= eql = {(t/fL [x] - rIM[x] == 0) /. {x -+ -a}, (rIM[x] -r/1R[x] ==O)/.{x-++a), (t/fL' [x] -I/IW' [x] == 0) /. {x -+ -a}, (I/IW' [x] - r/1R' [x] == 0) /. {x -+ +a}} / / Simplify; If you apply Solve to these equations then the amplitudes {A, B,R,T} follow, In[105]:= ABRTrule = Solve[eql, {A, B, R, T}] / /FullSimplify / / Flatten; ABRTrule//ColumnFor.m e-2iakLR (_1+e4iakW) (kLR-kW) (kLR+kW) Out[105]= R-. . e 41 akW (kLR _ kW) 2 _ (kLR + kW) 2 2 e. i a (kLR.kW) kLR (kLR + kW) A-. e4iakw (kLR-kW)2- (kLR+kW)2 2 e. i a (kLR.3 kW) kLR (kLR - kW) B-. e4iakw (kLR-kW)2 _ (kLR+kW)2 4 e. 2 i a (kLR-kW) kLR kW T-. e4iakW (kLR-kW)2 _ (kLR+kW)2 C. The ttansmission and reflection coefficients are defined as the ratio of the ttansmitted and reflected currents relative to the incident current. To construct the flux or current oper- ator 2m (I{t*VI{t - VI{t*I{t) you first define the notation for taking the complex conjugate (see Chapter 1), In[106] := exp . .- - .- exp /. {Complex [a_, b_] :-+ Complex [a, -b]} For more details of this operator see the previous problem. Beware, the constants in the expression are assumed to be real. If you define the gradient operator In[107]:= Vf_ :=D[f,#]&:/8{x,y,z} 
540 Chapter 9 Quantum Mechanics then the flux operator follows from 1I In [108] : = flux [tir-] : =  (tir. vtlr - vtlr. tIr) / / SiJllplify 2...m Applying flux to iflL gives both the incident and reflected flux to the left of the potential. The incident flux follows from setting R=O. In[109]:= incFlux = flux [t/fL [x] /.R-+ O/.ABRTrule] Out[109]= r L : h , 0, o} The reflected flux is simply the difference of the incident flux and the total flux on the left-hand side. In[110]:= Rflux = (inCFlux - flux[t/fL[x] / .ABRTrule]) / ToTrig/ /SiJllplify Out[110]= {(kLR (kLR2 _kW 2 )2 hSin 2 (2akW))/ (m (4 kLR 2 kW 2 Cos 2 (2 a kW) + (kLR2 + kw 2 ) 2 Sin 2 (2 a kW) ) ) , 0, 0 } The flux on the right-hand side follows from applying flux to t/tR. This flux contains only the ttansmitted flux so In[lll]:= Tflux = flux [I/IR [x] / .ABRTrule] / /ExpToTrig / / SiJllplify Out[lll]= {(4kLR 3 kW 2 h)/(m (4kLR 2 kW 2 Cos 2 (2 akW)+ (kLR2 + kw 2 ) 2 Sin 2 (2 a kW) ) ) , 0, 0 } The vector currents are in the x direction so you only need to consider the first com- ponent of the vectors. The ttansmitted and reflected coefficients follow from dividing the reflection and ttansmitted currents by the incident current, In[112]:= Out[112]= {RR, TT} = {Rflux [[1]] / incFlux[ [1]], Tflux [ [1]] / incFlux [[1]] }; {RR,TT}//ColumnFOr.m (kLR2 _ kw 2 ) 2 Sin 2 (2 a kW) 4 kLR 2 kW 2 Cos 2 (2 a kW) + (kLR 2 + kw 2 ) 2 Sin 2 (2 a kW) 4 kLR 2 kW 2 4 kLR 2 kW 2 Cos 2 (2 a kW) + (kLR 2 + kw 2 ) 2 Sin 2 (2 a kW) Notice, the current is conserved. In[l13]:= TT+RR==l //Simplify Out[l13]= True 
9.2 One-Dimensional Schr6dinger's Equation 541 d. Consider a potential well with VO=-lOO. To plot RR and TT as a function of the energy, make the following choice for the parameters. In[114j:= values = {1I-+1,m-+1,a-+1}; The graph of these coefficients for energies between 1 and 200 follows from In[115j:= Plot[ {RR, TT}/ .kRules/. {VO -+ -100}/ .values/ / Evaluate, {En, 1, 200}, AxesLabel -+ {"En", "RR, TT"}, Plot Style -+ {{}, Dashing [{O. 02, O. 02}] }] ; RR, TT 1 I, I' \ I \ I \ I \./ \ I \ I /' / ' , " 0.8 0.2 200 En The dashed curve is TT and the solid curve is RR. Notice the decrease in the reflection coefficient with increasing energy. For the next example consider a potential barrier with V=+l and let the values of En range from 0 to 5: In[116j:= Plot[ {RR, TT} / .kRules/. {VO -+ +1} / .values/ / Evaluate, {En, 0, 5}, Axes Label -+ {"EnD, "RR, TT"}, PlotStyle -+ {{}, Dashing[{0.02, 0.02}]}, Plotpoints -+ 50 ] ;  RR, TT 1 0.8 0.6 0.4 0.2 ---------- 2 3 4 5 En 
542 Chapter 9 Quantum Mechanics Again, the dashed curve is TT and the solid curve is RR. Note, for En above about 2VO the reflection coefficient of the barrier is essentially zero. e. You can use Plot3D to illusttate the reflection and ttansmission curves for a range of potential and energy values. Consider wells whose potentials range from Vo = 0 to - 2 O. For the ttansmission coefficient, you obtain In[117]:= Plot3D[TT/ .kRules / .values/.a -+ 1// Evaluate, {En, 0, 10}, {VO, -20, O}, Plotpoints -+ 40, Ticks -+ {Range [0, 10,5], Range [-20, 0, 10], {O, 1/2, 1} }, AxesLabel -+ {nEnergyn, npotential", nTT"}] ; Similarly for the reflection coefficient: In[118]:= Plot3D[ RR/ .kRules/ .ABRTrule/ .values/.a -+ 1// Evaluate, {En, 0, 10}, {VO, -20, O}, Plotpoints -+ 40, Ticks -+ {Range [0,10,5], Range [-20, 0, 10], {0,1/2,1}}, AxesLabel -+ {nEnergyn, nPotential n , "RRn}] ; 
9.2 One-Dimensional Schr6dinger's Equation 543 f. Consider the plot of the wave function for the complete range of x. Let {h 1 I m 1} and make all substitutions into the waves to the left of the potential, in the potential, and to the right of the potential: In [119] : = {IP"L [x., aa.] , t/M [x., aa.] , I/tR [x..., aa.] } = {IP"L [x] , t/M [x] , I/tR [x] } I .ABRTrulel . kRulesll.{h ...1, m...1, a... aa} II Simplify; Now define the function 1ft [x, a] , which extracts the appropriate solution in each region of the potential, In [120] : = 1/1 [x..., a.] : = Which [x s -a, IP"L [x, a] , -a<xs a, t/M[x,a],a<x, l/tR[x,a]] The function 1ft defines the wave everywhere. Set the boundary of the potential at a=2, the energy at En=l and let the potential well be VO-12. The graph of the real part of the wave function is In[121]:= Plot[ 1/1 [x, 2] I. {En... 1, Vo...-12}IIRe, {x,-15,15}, Epilog... {Thickness [0.02], Line[{{-2, O}, {2, O}}]}]; 0.6 0.4 o -15 10 -5 5 1 15 .4 .0.6 The dark line is the region of the well. Likewise, you can graph the absolute value of the wave function, IIft[x, a]12: In [122] := plot [ 1/1 [x, 2] 1/1 [x, 2]* II. {En... 1, VO... -12}, {x, -15, 15}, Epilog... {Thickness [0.02] , Line [ { {-2, O}, {2, O} } ] }] ; 
544 Chapter 9 Quantum Mechanics 3.5 3 .5 2 .5 1 .5 111M \lJ/JL -15 -10 -5 5 10 15 g. Let us animate the real and imaginary parts of the wave as it propagates through the barrier (O<En<VO). To get the time dependence for the wave, you multiply the wave by e-iEnt/h with h=l. The time dependence of a wave is described by the function timePlot. In [123] : = ti_plot [t., En., vo.] : = Plot[ {e-iED t/lJ t/r[x,2] liRe, e-iED t/lJ t/r[x, 2] I lID! }I I. {11... 1} I I Evaluate, {x, -15, 15}, PlotStyle ... {O' {Dashing[{0.02}], Thickness[0.008]}}, plotRange... {-2, 2}, Epilog... {Thickness [0.02] , Line[{{-2, O}, {2, O}}]}]; You then embed this into a Do loop to generate the sequence of frames for animation. Let us display the case where VO=l.l, and En=l, In[124]:= frames = 1; VO = 1.1; En = 1; timestep = 27r/(framesEn); Do [ti_Plot [ntimestep, En,VO], {n,l, frames}] 2 1.5 1 0.5 -1 - 0 5 5 
9.2 One-Dimensional Schr6dinger's Equation 545 The real part is the solid line, and the imaginary part is the thick dashed line. The number of animation frames is determined by frames. . PROBLEM 5 The One-Dimensional Harmonic Oscillator. Consider a particle bound by a force proportional to its displacement, F = -k x. The potential of the restoring force is the harmonic potential V[x] = k xl. The harmonic oscillator potential is one of the basic problems in quantum mechanics. It can be applied to the explanation of the vibration spectta of diatomic molecules, the motion of atoms in a solid lattice, or the theory of heat capacity. a. Solve the Schr6dinger equation, h 2 ift" [x] 2m + V[x]ift[x] = En ift[x] and express the results in terms of k = w 2 m, En = (n + )h w, and a 2 = ::m ' By considering the physical characteristics of the wave function, namely, that it vanish ,2 at infinity, show that the unrenormalized solution is e - W Hn [], where n is an integer and Hn[] are Hermite polynomials. Write the energy levels for the first few states. b. Show that the normalized wave function can be written as ,2 e -2;;2 Hn [] nl/ 4 .y2 n an! and display the solutions for n=O, . . . .4. Plot the normalized wave function and the square of the normalized wave function. Solution In [125] : = Clear [RGlobal' * 0] ; a. The one-dimensional Schr6dinger equation with a harmonic oscillator potential is 11 2 1/1" (x) In [126] := eq1 = 0 == (V- En) "'{x) - 2m [ kX 2 ] f12i/J"(x} Out[126]= 0 == - - En i/J(x}- 2 2m kx 2 I.V-+ - 2 Apply DSol ve to get the solution of this differential equation, In[127]:= eq2 = DSolve [eq1, "'[x], x] [[1]] I IPowerExpand I I Simplify 
546 Chapter 9 Quantum Mechanics { ..jk-Jffix2 [ [ {jk fro x ) [ 1 En...;m 1 ..jk...;m x 2 ] ] } Out[127]= i/J(x) ....e. C1HEnym 1 .r>:. +C 21 F 1 --;-; --;Jkj;.2 'In 4 2 vkn 2 n If you define the notation In[128]:= notation = {k...w 2 m, En ... (+n) hw, w... } ; ma 2 then the solution simplifies and you get In [129] := dsol = eq2 [[1]] //.notation//powerExpand//Simplify x 2 [ ( X ) [ n 1 X2 ) ] Out[129]=i/J(x)....e. 2a2 c1Hn a: +C 21 F 1 -"2;"2; 0:2 In the above notation w is the frequency defined by w = .../I and a is a convenient grouping, a = ..[;f , that determines the scale of the x-variable. The solution is a linear combination of BerndteH and BypergeometriclFl functions. The Bypergeo- metriclFl can be eliminated because it does not have the correct boundary condition at infinity, or it can be expressed as a linear combination of Hernd teH functions. In order for the wave to vanish at infinity, you must set n equal to an integer or zero in Her- miteH [n,x]. Hence, if you dispense with the BypergeometriclFl function and express the solution in terms of only Hernd teH polynomials where n=O I 1 I 2 I 3, it fol- lows that In[130]:= "'O[x_,n_] = "'[x]/.dsol/.C[2] ...O/.C[l]...l Out[130]= e.6 Hn () The wave function contains a Gaussian form multiplied by a polynomial of order n called a Hermite polynomial. The harmonic oscillator solution leads to a sequence of evenly spaced energy levels characterized by a quantum number n: In[131]:= energylevels = En/ .notation/.{w... ..j¥J Out[131]= JI (n+) n For example, the energy levels for n= 0 I 1 I 2 I 3 are In [132] := energylevels/.n... Range [0,3,1] 
9.2 One-Dimensional Schr6dinger's Equation 547 { l J[ 3 J[ S J[ 7 J[ } Out[132]= - - n, - - n, - - n, - - n 2m 2m 2m 2m In real systems the energy spacings are equal only for the lowest levels where the po- tential is a good approximation to the "mass on a spring" type harmonic potential. The most surprising difference between the classical simple harmonic oscillator and the quan- tum case is the so-called zero-point vibration of the n=O ground state. This implies that molecules are not completely at rest, even at absolute zero temperature. b. To normalize the wave function you define the norm In[133]:= norm[n_] := Integrate [tlrO [x, n] tlrO [x, n] , {x, -00, oo}, Assumptions ... { a > 0 , Element [n, Integers] } ] II Sqrt It can be shown that the norm is equivalent to  2n n!a.yii. Verifying this relation for the first 6 values of n, it follows that In[134]:= Table[norm[n] == Sqrt [ 2-n nl a Sqrt [11"] ] , {n, 0, 5}] Out[134]= {True, True, True, True, True, True} The normalized wave function becomes In [135] := tlrO [x, n] tIr[X_,IL] =  -vn 2 D anl e.6Hn() fT ["\/2n ex n! Out [135]= As the final cross check, you can verify that these first four wave functions are properly normalized by integrating over the square of the wave function: In [136] : = Table [ Integrate [tIr [x, n] 2 , {x, -00, oo}, Assumptions... { a > O} ] , {n, 0, 3} ] IIPowerExpand Out[136]= {1, 1, 1, 1} The first four wave functions are In[137]:= table = tIr[x, #]6i: I@ Range [0, 3] IISill\Plify; In[138]:= TableForm[table, TableHeadings ... {{ ntlr[x, 0] n, ntlr[x, 1] n, ntlr[x, 2] n, ntlr[x, 3] n }}] 
548 Chapter 9 Quantum Mechanics Out[138]= Ijr[x, 0] x 2 e- W Ijr[x, 2] fiTya x 2 Y2 e- w x fiT 0. 3 / 2 x 2 e-W (0. 2 -2X2) Y2 fiT 0. 5 / 2 x 2 e. w x(2x2-3o. 2 ) V3 {[1i 0. 712 Ijr[x, 1] Ijr[x, 3] Next, plot the first eight wave functions. The wave function plot follows from In [13 9] : = plot [ Table ["'[x, n] 12 + n, {n, 0, 7}] I. {a -0 1} II Evaluate , {x, -6, 6} , Epilog-oplot[0.6 zA2, {z, -6, 6}, PlotStyle -0 Thickness [0 .01], DisplayFunction -0 Identity ] [[1]] ] ; -2 2 4 6 -6 -4 The functions have been vertically offset so that the vertical axis roughly corresponds to the eigenstate. Also the amplitude of the waves was multiplied by 1/2. The curve for the harmonic potential was added with the command Epilog. Similarly, the plot of the square of the wave function is In[140]:= Plot[ Table [",[X, n]2 + n, {n, 0, 7}] I.{a -o1} l/EValuate, {x, -5, 5}, Epilog -0 Plot [0.6 zA2, {z, -6, 6}, plotStyle -0 Thickness [0 .01], DisplayFunction -0 Identity ] [[1]] ] ; 
9.3 Three-Dimensional Schr6dinger's Equation 549 . -4 4 -2 2 9.3 . THREE-DIMENSIONAL SCHRODINGER'S EQUATION . PROBLEM 1 Three-Dimensional Harmonic Oscillator in Cartesian Coordinates. Consider the three-dimensional Schr6dinger equation, _h 2 2m V 2 ift[x, y, z] + (V[x, y, z] - En) ift[x, y, z] = 0 (9.1) where the potential is of the form V [x, Y I z] =Vx [x] +vy [y] +Vz [z] . a. Assume the wave function is separable and can be written in the form X [x] Y [y] Z [z] . Reduce the three-dimensional problem to three separate one-dimensional dif- ferential equations for X [x] , Y [y] , and z [z] and show h 2 X"[x] O=-Ex+Vx [x] - 2mX[x] , h2y,,[y] O=-Ex+vy [y] - 2mY[y] , h 2 Z"[z] O=-Ex+Vz [z] - 2mZ[ z] where En=Ex+Ey+Ez. b. Consider the harmonic oscillator potential Vx [x] = !kx x 2 , vy [y] = !ky y2, and Vz [z] = ! kz Z2. Make use of the one-dimensional harmonic oscillator solution found in a previous problem and find the general solution for Schr6dinger's equation. If the normalization criteria is L: X [x, nx]2dx=1, then show the normalized solution is X[x,nx]  e -];.I H [ n .l ] _ n x' ax - nl/ 4 y 2 nx a x n) . 
550 Chapter 9 Quantum Mechanics Likewise, for Y [y, ny] and Z [z, nz] show that Y[y,ny] e-H [ n z. ] = n y' a y nl/ 4  2nyayny! and Z [z,nz] ? e-2;;fH [ n -'- ] _ n z' a Z - ,"1/4  2nzan' " z z' where {:ox, ny, nz} are integers and Hn [n, z] are Hermite Polynomials. c. Plot the two-dimensional wave function X [x] Y [y] . Required Packages In[141]:= Needs["Calculus'VectorAnalysis'"] Solution In[142]:= Clear ["Global ' *"]; a. You begin by setting the coordinates to Cartesian [x, y, z] using the command SetCoordinates found in the package Calculus 'VectorADalysis', In[143]:= SetCoordinates[Cartesian[x,y,z]]; Assume the wave function is separable and let In[144]:= t/r[x., y., z_] = X[x]Y[y]Z[z]; The form of Schr6dinger's equation is _fl2 In[145]:= eql = 2;" Laplacian [t/r[x, y, z]] + (VX[x] +vy[y] +Vz[z] -En)t/r[x,y,z] Out[145]= (-En+Vx(x) +Vy(y) +Vz(z)) X(x) Y(y) Z(z)-  ( f12 (Y(y) Z(z) X"(x)+ 2m X(x) Z (z) Y" (y) + X(x) Y(y) Z" (z))) where the potential V[x,y, z] has been replaced with Vx[x] +vy[y] +Vz [z]. Schr6- dinger's equation follows from setting eql to zero. Delay doing this until a later time because it is more convenient to work with the nonequation form. The terms with the same variable separate if you divide eql by 1ft [x, y, z] : In[146]:= eq2 = eql/t/r[x,y, z]//ExpandAll X" (x) f12 y" (y) f12 Out[146]= 2 mX(x) 2 mY(y) Z" (z) f12 -En+Vx(x) +Vy(y) +Vz(z) 2mZ (z) 
9.3 Three-Dimensional Schr6dinger's Equation 551 Three ordinary differential equations can be exttacted from eq2 by grouping terms with the same variable. Let En=Ex+Ey+Ez, In[147]:= Enrule = {En-> Ex + Ey + Ez} ; and define a selection operator to select terms with the same variables and with the relevant separation constant Ex, Ey, or Ez: In[148]:= select [eq., EL, var_] : = Select [eq, (!FreeQ[I, var] I I I FreeQ [I, Ei]) 6i:] If you apply select to the three variables and set the results to zero, then you get three equations: In[149]:= fieldEq = 0== { select [eq2/ . Enrule, Ex, x], select [eq2/.Enrule, Ey,y], select[eq2/.Enrule,Ez,z]}//Thread; fieldEq //ColumnForm X" (x) f12 0== - -Ex+Vx(x) 2mX(x) y" (y) f12 0== - -Ey+Vy(y) 2mY(y) Z"(z)f12 0==- -Ez+Vz(z) 2 mZ (z) Out[149]= b. For the harmonic oscillator potential, { kxx2 kyy2 kz Z2 } In[150]:= potential = VX(x}... -,vy(y) ... -,Vz(z} ... - ; 222 the one-dimensional field equations become In[151] := {xEq, yEq, zEq} = fieldEq/ .potential; {xI!:q,yEq,zEq}//ColumnForm lex x 2 f12 X" (x) o == - - Ex - 2 2mX(x) kyy2 f12 Y" (y) o == - - Ey- 2 2 mY(y) kz Z2 f12 Z" (z) o == - - Ez - 2 2mZ(z) Out[151]= The solutions for {xEq,yEq, zEq} are the one-dimensional harmonic oscillator so- lutions that were solved in a previous problem. You only need to consider the solution for X [x] , since the solutions for Y [y] and Z [z] are similar. As was done for the one- dimensional harmonic oscillator, if you define the notation k.x = w.x2m, Ex = ( + nx)h wx, and ax =  Ii muJx' In [152] := notation = {kx ...mwx 2 , Ex... (nx + ) wxh, IIJX'" m: 2 }; 
552 Chapter 9 Quantum Mechanics then the solution for xEq follows. In[153]:= xSol = DSolve[xEqll.notation,X[x],x] [[l]]IISimplify Out[153]= {X(x) ..e.6 [Cl( a: ) +C 21 F 1 [ - r; ;; :2 )]} As in the one-dimensional case, you obtain a linear combination of HermiteH and Hypergeometric1F1 functions. Note, Hypergeometric1F1 is either divergent in the limit of large x, or proportion to the Hermi teH polynomials; therefore, you do not need them for the solution of the harmonic oscillator. Only for nx equal to an integer or zero will the Hermi teH functions have the correct behavior as xoo. The normalized solution is In[154]:= X[x_, nx_] X[x] l.xSOlII.{c 2 ->0,C 1 -> 1 } -vn .y 2 DX ax nxl Out[154]= e.6Hnx() 1'r Y 2 nx axnx! Let us double check the normalization by integrating over the product X[x, nx]2 for n=O, 1. . .5: In[155]:= Table [ Integrate [X[X, nx]2 , {x, -00, oo}, GenerateConditions -> False] , {nx, 0, 5} ]IIPowerExpand Out[155]= {1, 1, 1, 1, 1, 1} Setting GenerateConditionsFalse suppresses printing out special cases in ad- dition to speeding up the evaluation of the integral. You can trivially write the solutions for Y [y, n] since this problem is symmetric in all the variables. In[156]:= Y[y.,ny_] =X[y,ny] I.{ax->ay} 2 ( ) e. '"' ::L ""11y ay Out[156]= 1'r y 2 nY ayny! as well as for Z [z,n], In[157]:= Z[z_,nz_] =X[z,nz]/.{ax->az} e.6 z (  ) Out[157]= 1'r y 2 nz az nz! 
9.3 Three-Dimensional Schr6dinger's Equation 553 The complete normalized wave function is given by the product X [x, nx] Y [y, ny] Z [z,nz], where nx, ny, and nz are integers. c. Let us plot a typical two-dimensional wave function that is of the form X [x] y [y] . Set ax=ay=l for simplicity, In[158]:= aRule= {ax-+1, ay-+1}; and consider the graphics for the wave with {nx=3, ny=2}: In[159]:= waveP10t = Plot3D[X[x, 3] y[y, 2] / .aRule, {x, -4, 4}, {y, -4, 4}, Plotpoints -+ 35, DisplayPunction -+ :Identity] ; Add to this graphic the harmonic potential described by xl + i: In[160]:= vPlot = Plot3D [0.15 (x2 + y2) - 2, {x, -4, 4}, {y, -4, 4}, Plotpoints -+ 35, Disp1ayPunction -+ :Identity]; The normalization and displacement of the potential are chosen for aesthetics. Finally, if you combine these graphics in a single plot it follows that In[161]:= Show[{vPlot,wavePlot}, DisplayFunction -+ $DisplayFunction ] ; 2 . PROBLEM 2 Schrodinger's Equation for Spherically Symmetric Potentials. Having solved the Schrodinger equation in Cartesian coordinates, let us turn to the next logical set of coordinates-spherical coordinates {r, (), I/>}. Consider SchrOdinger's equation with a spherically symmetric potential V=V [r] and assume the wave function is of the form if1[r,(),I/>]= R[r] 8[()] <1>[1/>]. 
554 Chapter 9 Quantum Mechanics a. Express SchrOdinger's equation in spherical coordinates and derive an equation for the angular function <1>[1/>]. Solve for <1>[1/>] and show that <1>[1/>] = ef;im"', where m", is an integer or zero. b. Eliminate the I/> variable in Schrodinger's equation using the results in part a. Derive for 8[8] and R [r] the remaining two equations and show: 8"[8] = -1(1 + 1)8[8] + ml/>2 csc[8f8[B] - cot[8]8'[8] 2 R[r] 2m R" [r] + -;:R' [r] - 1 (1+1) 7 = hl (V[r] -En) R [r] Caution, be aware of the difference between I ("el") and 1 ("one") here. c. Let z=Cos [8] and show that the 8[8] equation in part b can be expressed in the canonical form of Legendre's equation, m 2 8(z) f8(z) + f 2 8(z) +  - 2zE>'(z) + (1 - z:-)8"(z) = O. -1+z Solve Legendre's equation and show the physical solution is an associated Legen- dre polynomial, LegendreP [l,mtfI,Cos [8] ], where I = 0,1,2,... and m", = -I, ...,0, ..., I. d. The product of the angular functions 8[8]<1>[1/>] is proportional to e +im"'Legendrep [1, mtfI, Cos [8] ] . Show the product Y[f, m"" 8,1/>] = C[f, m",]P[f, m"" cos[8]]e+im'" agrees with Mathematica's spherical harmonic if C[f, m",] = 2f + 1 (f - m)! 4n (f + m)! Required Packages In[162]:= Needs["Calculus'VectorAnalysis'"] Solution In[163]:= Clear ["Global ' * "]; a. You start by setting the coordinate system found in the add-on package Calcu- lus 'vectorAna1ysis' to spherical coordinates {r, 8, I/>}: In[164]:= SetCoordinates[Spherical[r,9,]]; Assume the wave function is of the form In[165]:= I/f[r, 9,] = R[r]9[9]!I[]; 
9.3 Three-Dimensional Schr6dinger's Equation 555 The form of Schr6dinger's equation is 11 2 In[166]:= eq1= - 2m Laplacian [I/f[r, 9, 1/>]] + (V-En)I/f[r,9,1/>] 1 Out[166]= (V-En) R(r) 8(9) ifI(q;) - 2mr 2 (!J 2 Csc (9) (Sin(9) 8(9) ifI(q;) R" (r) r 2 + 2 Sin(9) 8(9) ifI(q;) R'(r) r+Cos(9) R(r) ifI(q;) 8'(9)+ R (r) Sin (9) ifI (q;) 8" (9) + Csc (9) R(r) 8 (9) ifI" (q;) ) ) where Schr6dinger's equation follows from setting eql to zero. Delay setting this equation to zero, since it is easier to work with this nonequation form. First separate the cp variable followed by separating the () and r variables. To separate the cp variable you multiply eql by r;t:,f ' r 2 Sin 2 (9) In[167]:= eq2 = eq1 //ExpandAll I/f[r, 9, 1/>] r Sin 2 (9) R' (r)!J 2 Cos (9) Sin (9) 8' (9) !J2 Out[167]= - - mR(r) 2m8(9) r 2 Sin 2 (9) R" (r)!J 2 Sin 2 (9) 8" (9) !J2 2mR(r) 2m8(9) ifI" (q;) !J2 - Enr 2 Sin 2 (9) + r 2 VSin 2 (9) 2 mifl (q;) Notice the term with the cp variable is isolated so it can be set equal to a constant. Define the operator, In [168] : = select [eq., var.] : = Select [eq, (IFreeQ [I, var]) &:] to select those parts of an equation with a certain variable. Apply select to eq2 and separate out the cp variable. If you then set the results equal to the separation constant ;: mcp2 it follows that 1I2mtf>2 In[169]:= eq3 = select [eq2, 1/>] == - 2m !J2 ifI" (q;) mq;2 !J2 Out[169]= - == - 2 m ifI ( q; ) 2m The form of the separation constant ;: mcp2 is defined in anticipation that mt/J is an integer or zero. Rearranging terms, you find In [170] : = I/>Eq = Solve [eq3, II" [1/>]] [ [1, 1]] / .Rule- > Equal Out [170]= ifI" (q;) == _mq;2 ifI (q;) Solving <I>[cp] for cp, it follows that In [171] : = eq4 = DSolve [I/>Eq, II [1/>],1/>] [[1]] Out[l71]= {ifI(q;) -7 c 1 Cos(mq;q;) +c 2 Sin (mq;q;) } 
556 Chapter 9 Quantum Mechanics Equivalently, you can convert the trigonometric functions to exponential functions with a proper choice of constants. In[172]:= eq4/.{C[1] -+ 1, C[2] -+ {I:, -I:}}// MapAll [Trig'l'OExp, #] &: / / Map [Thread, #, 2]&: //Flatten Out[172]= {iI?(<t» ->eim<l><I>,iI?(<t» ->e.im<t><t>} To summarize, the solution for <1>[1/>] follows from the rule In[173]:= I/>Rule = II [1/>] -+ ei...;t/>; For the wave function to be periodic the value of mt/J must be either zero, a positive integer, or a negative integer. b. Equations for e[ B] and R [r] follow from eq2 if you eliminate the I/> variable using I/>Eq derived in part a. Eliminate the I/> variable and then dividing by sin 2 [B], it follows that In[174]:= eq5 = (eq2/. (I/>Eq/ . Equal -+ Rule» /Sin [9] 2/ /Expand. 2 2 f12 R" (r) r 2 f12 R' (r) r -En r + V r - - + 2mR(r) mR(r) m<t>2 f12 Csc 2 (9) f12 Cot (9) e' (9) f12 e" (9) 2m 2me(9) 2me(9) Out [174]= The variables in eq5 can be grouped with terms that contain either B or r variables but not products of the variables. You can now set these two groups equal to another separation constant. Apply the operator select to eq6 and separate out the r variables. The radial equa- tion follows if you then set the results equal to a separation constant _ f(f;h2 : 1 (I + 1) 1'1 2 eq6 = select [eq5, r] == - 2m f12 R" (r) r 2 f12 R' (r ) r -Enr 2 +Vr 2 - 2mR(r) mR(r) In[175] := Out[175]= 1 (! + 1) f12 2m The form of the separation constant - f(f;h2 was chosen in anticipation that the allowed values of I are {O, 1,2,3, ...}. You can simplify eq6 by solving for R' , [r], In [176] : = rEq = Solve [eq6, R" [r]] [[1, 1]] / .Rule- > Equal/ /ExpandAll Out[176]= R" (r) == R(r) 1 2 R(r) 1 +- 2 EnmR(r) f12 + 2mVR(r) f12 2 R' (r) r The e equation follows in a similar manner: 1 (I + 1) 1'1 2 In [177] : = eq7 = select [eq5, 9] == 2m 
9.3 Three-Dimensional Schr6dinger's Equation 557 m.p2 Csc 2 (9) f12 Out[l77]= 2m 1 (I + 1) f12 2m Cot (9) e' (9) f12 2me(9) e" (9) f12 2me(9) Simplify eq7 by solving for 0"[0], In[178]:= 9Eq = Solve [eq7, en [9]] [[1,1]] I. Rule -+ Equal I I ExpandAll Out [178]= e" (9) == -e (9) 1 2 - e (9) 1 + m.p2 Csc 2 (9) e (9) - Cot (9) e' (9) Equation BEq is Legendre's equation. c. The canonical form of Legendre's equation is usually written in terms of the variable z=Cos [0] . The following procedure called vChange implements a change of variables in a differential equation: In[179]:= vChange[l!:q_,I/f_,x_,z_,f_].- I!:q/. {D [I/f [x], {x, n_}] >+ Nest[( (1/D[f,z]) D[#,z])&:,I/f[z],n], I/f[x] >+I/f[z],x:-+f} When this operator is applied to a differential equation Eq of function ifi [x] , it changes the variables from x to z where x=f [z] . The Nest command just applies the chain rule over and over until all the higher derivatives have been changed to the z variable. If you apply vChange to 8Eq with the change of variables O=ArcCos [z] , it follows that In[180]:= eq8 = V'Change [9I!:q, e, 9, z, ArcCos [z]] I I ExpandAll I I Sill1Pli fy Out[180]= (m.p2 + (Z2 - 1) 1 (I + 1) ) e (z) ( ) 2 ==2ze'(z)+ z2_1 e"(z) z - 1 You can solve for e [z] in eq8 by applying DBol ve: In [181] : = eq9 = DSolve [eq8 , e [z] , z] II Flatten { mq, m q, } Out[181]= e(z) -->c1P, (z) +c 2 Q, (z) The solution is a linear combination of LegendreP and LegendreQ functions. The LegendreQ [I,m, z] has a log [ : ] singularity at z={ -1, +1}, e.g., In[182]:= LegendreQ[2, 1, z]  (3 Z2 - 2) 3 r-; ( z + 1 ) Out[182]= z2_1 -2 z \jl-zoLOg l-z 
558 Chapter 9 Quantum Mechanics so they cannot represent physical solutions. Thus, you are left with the LegendreP [1, m, z] , In[183]:= 9Rule = eq9/. {C [1] -+ 1, C[2] -+ O} I I SiJllplify Ou t [183] = {e (z) -> pr;t (z) } The desired solutions given by BRule are associated Legendre polynomials where 1={0,1,2,3,...} and mtfl={-1,...,1}. d. You can replace the product of e[Cos[8]] and <I>[iP] with a spherical harmonic. Mul- tiply the product ofe[Cos[8]] and <I>[iP] with a normalizing constant norm[l,m]. In[184]:= norm[/,m] 9[z] 11[1/>] 1.9Rule/.I/>Rule/. Z -+ COB [9] I.mq, -+ m Out [184]= eimq,  (Cos (9)) norm (I, m) To make the product agree with Mathematica's spherical harmonic, set the normalization constant to 1 In[185]:= norm[/.,m...] = _I- 2 'V7T (2 1+ 1) (I - m) I (m + I) I The product becomes In[186]:= Y[I_, m..., 9_, 1/>.] = norm[/,m] 9[z] 11[1/>] 1.9Rule/.I/>Rule/. z -+ COB [9] I .DII/J -+ m ei mq, 1(2/+1) (I.m)! p1!' (Cos (9) ) Out[186]= \J (m+l)! / 2-{lr To verify that the expressions Y [1 ,m,8, iP] match Mathematica's spherical harmonic functions called Spherica1HarmonicY [1, m, 8, iP] , form the following table In[187]:= 'l'able[ SphericalEarmonicY[/, m,9, 1/>] == Y[/, m, 9, 1/>], {I, 0, 4}, {m, -I,!}] II SiJllplifyllPowerExpand Out [187]= {{True}, {True, True, True}, {True, True, True, True, True}, {True, True, True, True, True, True, True}, {True, True, True, True, True, True, True, True, True}} At least for 1=0 t04 the functions Y [1,m, 8, iP] match Spherica1HarmonicY[1,m, 8, iP]. It is also true for all other values of I and In. . PROBLEM 3 Particle in an Infinite, Spherical Well. Consider a three-dimensional well with infinite depth and radius a defined by V [r] = 0 if r<a; V [r] =00 if a<r. Assume the wave function separates and is of the form R [r] e [8] <I> [iP]. This is the 
9.3 Three-Dimensional Schr6dinger's Equation 559 simplest spherically symmetric problem and is a close analogy to the one-dimensional infi- nite square well. The angular functions are spherical harmonics so the problem is reduced to solving the radial wave equation: 2m 0== -1(1+1) R[r] +(En-V[r])R[r]+2 r R'[r]+R"[r] Ii 00 V(r) 0 a r a. Solve the radial equation for R [r]. Require the solutions to be finite at r=O and h th th h . al I . C[1]BesseU U +/"kr ] If th . s ow at e p YSIC so utIons are ...[r . e constant IS C [ 1] = "';1 + 2f , then show that the solution is normalized according to the criteria, ,100 R[r]2dr = 1. Display the explicit wave functions for 1= 0,1,2,3. (Note, we use an unconventional normalization here.) b. Use the boundary condition at the wall to derive an expression for the energy lev- els.ConsiderthestatesS(1= 0), P(1= 1), D(1= 2), F(1= 3), G (1= 4.) and find the first five energy levels for each state. Make use of the command Besse1JZeros found in the package Numerica111ath 'Besse1Zeros ' . Dis- play the results in table and graphic forms. c. Plot R [r] for the first few states and energy values. Required Packages In[188]:= Needs[RNumericalMath'BesselZeros'"] Needs ["Graphics' Legend'"] Solution In[189]:= Clear ["Global ' *"]; a. Enter the radial wave equation 2mR(r) (En -V(r» r 2 In[190]:= rEq = 0 == 2 + R" (r) r 2 + 1'1 2 R' (r) r -I (I + 1) R(r) /. { k21'12 } V(r) -+ 0, En -+ 2m 
560 Chapter 9 Quantum Mechanics Out[190]= O==k 2 R(r) r 2 +R"(r) r 2 +2R'(r) r-I (1+1) R(r) where V [r] =0 and En = k2 . Applying DBo1 ve to rEq, it follows that In[191]:= dso1 = DSo1ve[rBq,R[r],r]//F1atten//Simp1ify { J,+" (kr) C 1 + Y,+" (kr) c 2 } Out[191]= R(r)... 2" vr 2" The solutions are Bessel functions of type Besse1J and Besse1Y. Further investiga- tion shows that BesselY [ + f, r] is divergent as rO. Therefore, these are not physically valid as wave functions. The radial wave function becomes In[192]:= R[r_,I_,k..:1] = R[r] /.dS01/.{C[1] -+, C[2] -+o} J,+ (kr) Out[192]= vr Let us check the normalization criteria, fooo R[r, f, k]2dr = 1: In[193]:= :Integrate [R[r, I, k] -2, {r, 0, a>} , Assumptions -+ {k > 0, I> -1/2}] Out[193]= 1 A table of the explicit wave functions for 1= 0,1,2,3 follows. In [194] : = 'l'ab1eForm[ R [r, I, k] &:/@.Range [0, 3], 'l'ab1eEeadings -+ { { "I = 0", "I = 1", "I = 2", "I = 3" }} ] / / Simp1ify//PowerEKpand I" 0 {f Sin(kr) -{kr if (Sin(kr) -krCos(kr)) k 3 /2 r2 N (3 kr Cos (kr) + (k2 r 2 - 3) Sin(kr)) k 5 / 2 r 3 {¥ (k r (k2 r 2 - 15) Cos (k r) + 3 (5 - 2 k 2 r2) Sin (k r) ) k 7 / 2 r 4 1=1 Out[194]= I" 2 I" 3 b. The boundary condition requires the wave to vanish at the boundary r=a. This condi- tion is equivalent to finding the values ofka, where Besse1J [1+1/2, k a] vanishes. Since En= k it follows that these discrete values of ka determine the quantized energy levels. We limit the evaluations to the first five energy levels in this section. The zeros of Besse1J [1+1/2, k a] follow from the command 
9.3 Three-Dimensional Schrodinger's Equation 561 In[195]:= ?BesselJZeros BesselJZeros[nu, n] gives a list of the first n zeros of the order nu BesselJ function. BesselJZeros[nu, {m, n}] gives a list of the mth through the nth zeros. More... found in the add-on package Nwnerica1l1ath' Besse1Zeros '. Consider, in turn, the states 8(1=0), P(l=l), D(1=2), F(1=3), G(1=4) and find the first five en- ergy levels for each state. The list of zeros for 1=0,1,2,3,4 is In [196] : = zeros = BesselJZeros [1/2 + #,5] &: 1fI. Range [0,4] 3.14159 6.28319 9.42478 12.5664 15.708 [4.49341 7.72525 10.9041 14.0662 17.2208 Out [196]= 5.76346 9.09501 12.3229 15.5146 18.689 6.98793 10.4171 13 .698 16.9236 20.1218 8.18256 11.7049 15.0397 18.3013 21.5254 The first list are the five values ofka, where BesselY [! +0, r]=O, i.e., the energy levels for the 8 states. The remaining lists contain the five values of ka for the states P, D, F, and G. To display the results in a table you apply Tab1eForm to zeros: In[197]:= 'l'ableForm[zeros, 'l'ableSpacing -+ 1, 'l'ableHeadings -+ {{ RS _ WaveR, Rp _ WaveR, RD _ WaveR, RF _ WaveR, RG - waveR}, {RFirst R , RSecond R , RThird R , RFourth R , RFifth R }}] First Second Third Fourth Fifth S - Wave 3.14159 6.28319 9.42478 12.5664 15.708 Out[197]= P - Wave 4.49341 7.72525 10.9041 14.0662 17.2208 D - Wave 5.76346 9.09501 12.3229 15.5146 18.689 F - Wave 6.98793 10.4171 13 .698 16.9236 20.1218 G - Wave 8.18256 11.7049 15.0397 18.3013 21. 5254 These are the values for ka, or equivalently the energy levels for the 8, P, D, F, G states. The results can also be displayed in the form of an energy level graph. If you define the levels In[198]:= levels = 'l'able[ {{i - 0.4, zeros [ [i, j]]}, {i + 0 .4, zeros [ [i, j] ] } } , {i, 1, Length [zeros] }, {j, 1, Length [zeros [[1]]]}] ; and graph them along with the appropriate text, you get 
562 Chapter 9 Quantum Mechanics In[199]:= Show[ {Graphics [{Thickness [0.01], Map [Line, levels, {2}]}], Graphics [Text [-S-, {1, 1}]], Graphics [Text [np_, {2, 1}]], Graphics [Text [-D-, {3, 1}]], Graphics [Text [-Fn, {40, 1}]], Graphics [Text [nGn, {5, 1}]] }, Frame -+ True, P10tRange -+ {{O, 5.9}, {-1, 25}}]; 25 20 15 10 5 S P D F G 0 1 2 3 4 5 C. Consider the states S, P, D, F and G and plot the wave functions that correspond to the first five energy eigenvalues. Let us first consider the wave function plot for the S (1=0) state. If you set a=l, then the plot for the 1=0 wave function corresponding to the five lowest eigenvalues, kl, k2 , k3 , k4, and kS, is In[200]:= Plot[R[r, 0, k]/.{k -+ (zeros [ [0 + 1]]) }//EValuate, {r,O,l}, PlotStyle -+ {{}, Dashing [{O .01}], Dashing[{0.02}],Dashing[{0.03}], Dashing[{0.05}]} , PlotLabel -+ StyleForm [- "'- , FontSize -+ 140] , PlotLegend -+ {k1, k2, k3, k4, k5} , LegendPosition -+ {1, -1/2}, Epilog -+ Text [StyleForm[ns (I = 0) - Staten, FontSize -+ 140], {0.5, 2}] ] ; 
9.3 Three-Dimensional Schr6dinger's Equation 563 1/1 -kl -k2 _mk3 n_ k4 - - k5 S (1=0) -State 1 You can repeat this command for the P(l=l), D(1=2), F(1=3) and G(1=4) states with the obvious changes. Instead of doing the individual states, let us do all the states using a GraphicsArray. The corresponding plots for S, P, D, F, andG states follow from In[201J:= rPlots = Table [ Plot [ R[r, I, zeros [ [+1 + I, n]]] II Evaluate, {r, 0.01, 1}, Ticks -+ None, PlotRange -+ All, PlotLabel-+ {n, I}, DisplayFunction -+ :Identity ], {n,1,S},{t,0,4}]; In [202J : = rPlots IIGraphicsArray I I Show; {l, O} {l, l} {l, 2} {l, 3} {l, 4}   0 L6 L6 {2, O} {2, l} {2, 2} {2, 3} {2, 4}      {3, O} {3, l} {3, 2} {3, 3} {3, 4}    W  {4, O} {4, l} {4, 2} {4, 3} {4, 4}      {5, O} {5, l} {5, 2} {5, 3} {5, 4}      The values of n denotes the first, second, .. . energy levels and the value of I gives the state. Notice that all the radial wave functions vanish at the boundary r=a=l. . PROBLEM 4 Particle in a Finite, Spherical Well. Consider a three-dimensional finite well of radius a defined by V [r] =-VO if r<a; V [r] =0 if a<r. This is the finite gen- eralization of the infinite well in the previous problem. Unlike the infinite well the wave function can tunnel into the boundaries. Assume the wave function is of the form R [r] e [0] <I> [tf>]. The angular functions are spherical harmonics so the problem is reduced to 
564 Chapter 9 Quantum Mechanics solving the radial wave equation with a constant potential, 0== -1(1+1) R[r] +12"zR[r]+2 r R' [r]+"zR" [r] where 12 = 'rl (En-V). The regions O<r<a and a<r must be tteated separately. V(r) = 0 V(r) = -V o o a r a. Use the condition that the wave function must be finite at the origin and vanish as roo and solve for the general form of the wave inside and outside the well. b. To match the interior and exterior solutions you must join them with boundary con- ditions. The boundary conditions require the wave function and its derivative to be continuous at r=a. Fix the parameters, hl, al, ml, V-110, and use the boundary condition at the wall to derive the first four energy values for the S (1=0), P (1=1) and D (1=2) states. Display the results in table form. c. Plot the radial solution for the S, P, and D wave functions that correspond to their first four energy states. Required Packages In[203]:= Needs[ftGraphicS'Legend'ft] Solution In[204]:= Clear [ftGlobal ' * ft]; a. Enter the radial wave equation, In [205] := rEq = 0 == k 2 a(r) r 2 + an (r)  + 2 a' (r) r- 1 (1+1) a(r) /.En-+-WD/.V-+-VO Ou t [ 205] = 0 = = k 2 R (r) r 2 + R" (r) r 2 + 2 R' (r) r - I (I + 1) R ( r) 
9.3 Three-Dimensional Schr6dinger's Equation 565 where k? = 'fl (En-V) and V is a constant. Applying DSo1ve to rEq, it follows that In [206J := rRule = DSolve[rEq, R[r], r] //Flatten//EXpandAll { J,+" (kr) c 1 Y,+" (kr) C 2 } Out [206J = R (r) -> :Z.vr + :Z.vr The values of k inside and outside the well are, respectively, { ...[2 .ym ""vo - wn In[207J:= kRule= kJ:n-+ 1.1 ' 11. ...[2 .ym -.fWD. } kOut -+ 1.1 ; where V=-VO, En= -WDl and o<wn<VO. Notice the value of kin is real and the value of kout is complex. Define kOUt=J: qOut so that qout is real. Let us consider the region inside the well. To examine the behavior near the origin consider the series expansion of R [r] around the origin for 1-+0,1,2,3: In[208J:= Series [R[r] / .rRule/.I -+ I, {r,O,l}]& /@ Range[0,3]//ColumnFor.m Out [208J = (2 if 3/2 \f IT C 2 . ,,2 k c 2 r ( 2 ) - + "k - C 1 + .  + 0 r "kr 71" ,,271" _ IfC 2 _ --/kc 2 +k3/2 fic r +o ( r3/2 ) k 3/2 r 2 V2lr 3 ;: 1 3 ( (i c ) ( k3/2 C ) r \f IT 2 C 2 2 ( 3/2 ) - k 5/2 r 3 - --/kV2lrr - 4 V2lr + 0 r 15 (If c 2 ) 3 c 2 --/kc 2 ( 3/2 ) - k 7/2 r 4 - (k3/2 V2lr) r 2 - 4 V2lr + 0 r The rows are the expansions for 1=0,1,2, and 3. The constant in front of BesselY [f + ,r] must be set equal to zero to prevent the Besse1Y from diverging as r-+O. The Ull- renormalized wave function for r<a is In [209J := waveJ:n[kJ:n_, 1_, r_] = R[r] / .rRule/. {C [1] -+ cJ:n, C [2] -+ 0, k -+ kJ:n}//Siq>lify //PowerBxpand cIn J'+i (kIn r) Out[209J= .vr The explicit wave functions for 1=0,1,2, and 3 are: In[210J:= TableFor.m[waveJ:n[kJ:n, I, r ]&/@ Range [0, 3], TableHeadings -+ { { nl = 0 n, nl = 1 n, nl = 2 n, nl = 3 n }} ] / / Simplify//powerBxpand 
566 Chapter 9 Quantum Mechanics f = 1 cIn {f Sin (kIn r) VkIll r cIn {f (kIn r Cas (kIn r) - Sin (kIn r) ) kIn 3 / 2 r 2 cIn {f (3 kIn r Cas (kIn r) + (kIn2 r 2 - 3) Sin (kIn r) ) kIn 5 / 2 r 3 cIn{f (kInr (kIn2 r 2 -15) Cas (kInr) + 3 (5 - 2 kIn 2 r2) Sin(kInr)) kIn 7 / 2 r 4 Out[210]= 1=0 f = 2 f = 3 The general form of the wave function outside the well with Vo=o becomes, In[211]:= eql = R[r]/.rRule/.k -+ 1qOut//powerExpand J,+l (i qOut r) C 1 Y,+l (i qOut r) C 2 Out[211]= 2 + 2 .;r .;r The boundary value problem reduces to finding C [1] and C [2] so that R [r] vanishes as r-+oo. By themselves Besse1J and Besse1Y don't vanish at 00. To see what the constants must be, let us evaluate eq1 for 1=0: In[212]:= eql/.f -+ 0/ /Trig'l'OExp / / Siqllify / / powerExpand//Collect[I, {Exp[a_] }]&: Out[212]= (-1) 3/4 e.qoutr ( - i c 1 - C 2 ) V2lr yqOut r (-1) 3/4 e qOUt r (i C 1 - C 2 ) V2lr yqOut r There are both exponentially increasing and decreasing terms. To eliminate the expo- nentially increasing terms you want to pick C [2] =:1: C [1]: In[213]:= eq2=eql/.C[2] -+lC[l] J,+l (iqOutr) C 1 Y,+l (iqOutr) C 1 Out[213]= ":! + ":! .;r .;r This combination of Bessel functions vanishes as r-+oo. This exponential decay is valid for all values of 1. The exterior wave function is In[214]:= waveOut[qOut_,f_,r_] =eql/.rRule/.{C[l] -+cOut,C[2] -++1 cOut} cOut J,+l (i qOut r) i cOut Y,+ 1 (i qOut r) Out[214]= 2.;r + Jr The explicit wave functions for 1=0,1,2, and 3 are: In[215]:= TableFor.m[ (waveOut [qOut, I, r] / /Trig'l'oExp / / Simplify/ /powerExpand ) &:/@ Range [0, 3], TableHeadings -+ {{nf=0","f=1","f=2","f=3" }}] 
9.3 Three-Dimensional Schr6dinger's Equation 567 1 = 1  ..[2 cOut e- qout r .yTr .y qOu t r (-1) 3/4 cOut e. qOut r {f (gOut r + 1) qOut 3 / 2 r 2 ..[2 cOut e-qOut r (qOut 2 r 2 + 3 qOut r + 3) .yTr qOu t 5 /2 r 3 (-1) 3/4 cOut e. qout r {f (qOut 3 r 3 + 6 qOut 2 r 2 + 15 gOut r + 15) qOut 7 /2 r 4 Out[215]= 1=0 1 = 2 1 = 3 They all vanish as roo, as expected. b. The boundary condition requires the wave function and its derivative to be continuous at r=a. The continuity of the wave at the boundary is described by bel: In[216]:= bel = (waveJ:n[kJ:n, " r] == waveOut[qOut, " r]) 11.{r-+ a} cInJ'+i (akIn) Out[216]= -va cOutJ,+J. (iaqOut) icOutY,+l (iaqOut) . + ;; -va -va The constant CJ:n is an arbittary normalization constant and can be set equal to one. Solving bel for eOUt, you get In[217]:= eOutRule= Solve [bel, eOut] I .eJ:n -+ 1 I I Flatten IISimplify { J,+l (a kIn) } Out[217]= cOut -> . 2. . J,+! (1 aqOut) + 1. Y,+! (1. aqOut) The derivative condition is given by be2, In[218]:= 002 = (D [waveJ:n [kJ:n, " r], r] == D[waveOut[qOut, " r], r]) II. {r- >a}IISiqllify; The energy eigenstates follow from fixing land solving 002. Let us consider the energy eigenvalues and graphs of the corresponding wave functions for different values of 1. Fix the numerical choices for various parameters and collect all the relevant rules into allRules: In [219] := allRules = { -Y2 -y m (VO - wn) kJ:n -+ fl ' qOut -+ ...[2  mfl": ' eOutRule, fl -+ 1, a -+ 1, m -+ 1, VO -+ 110, eJ:n -+ 1}1 IFlatten; 
568 Chapter 9 Quantum Mechanics If you substitute the numerical parameters into bc2, then the boundary condition be- comes In[220J:= 002 Sol ['.] = OO2//.cOutRu1e/.cJ:n-+1//.a11Ru1es//. allRu1es / / simplify; The energy levels follow from finding wn that satisfy the boundary conditions in bc2Sol. Consider the first four energy levels for 1=0 (S-state). The boundary value equation becomes In[221J:= eq3 = 002 Sol [0] / /siqllify Out[221J= [12 (2 v440 - 4wn .ywn Sin ( V 220 - 2wn)- 4 (Wn - 110) Cas ( V220 - 2 wn ) ) )/ (ylf(440-4Wn)3/4) ==0 Notice that the resulting S- Wave expression depends purely on wn. This equation can be solved by applying FindRoot. However, to use this command you need to estimate the wn values. An estimate follows from graphing the left-hand side of eq3: In [222J : = Plot [eq3 [[1]] / /Eva1uate, {WD, 0, 110}] ; 10 7.5 5 The eigenvalues occur where the curves intersect the x-axis. The values of ka for the first four approximate values are {10, 40,70, 90}. The numerical values for the eigen- states follow (more accurately) from FindRoot. In[223J:= sVa1ues= FindRoot[eq3,{WD,#}]&: /@{10,40,70,90} Out[223J= {{Wn->6.55387}, {Wn-> 42.0025}, {Wn-> 71.3642}, {Wn-> 92.7371}} The energy values for the p and D states follow in a similar fashion. The boundary condition equations for the p and D states follow from eq4 and eq5, respectively, In[224J:= eq4=bc2S01[1] //Simplify; 
9.3 Three-Dimensional Schr6dinger's Equation 569 and (this may take a minute or so), In [225J := eq5 = OO2Sol [2] / /Sim,plify; The guesses for the p and D eigenvalues follow from plotting the right sides of eq4 and eq5: In [226J : = Plot [{eq4 [ [1]], eq5 [[1] ] } / /Evaluate, {WD, 0, 110}, PlotStyle -+ {{}, DaShing [ { 0 .01}]} ] ; 8 6 , , , , , , , , , , , , , , , :  : : , , , -2 -4 The first four energy values for the p states follow from applying FindRoot to eq4, In [227 J : = pValues = FindRoot [ eq4 , {WD, #}] &: /@ {20, 60, 80, 100} Out[227J= {{Wn -. 25 .4847}, {Wn -. 58.4703}, {Wn -.83. 9514}, {Wn -. 101.154}} Similarly, the first three energy values for the D states are In [228J := dVa1ues = FindRoot[ eq5, {WD, I}]&: /@ {10, 40, 70, gO} Out[228J= {{Wn -. 8.49601}, {Wn -. 44.4765}, {Wn -.73 . 9698}, {Wn -. 95.458}} To display the results in a table you apply TableForm to the energy levels. In[229J:= TableFor.m[{sValues,pValues,dValues}, TableSpacing -+ 1, TableHeadings -+ {{DS-Wave", uP-Wave", "D-Wave" }, {"First D , "Second", "Third", "Fourth" }}] S - Wave P - Wave D - Wave First Wn-.6.55387 Wn-.25.4847 Wn -.8.49601 Second Wn -.42.0025 Wn-.58.4703 Wn-.44.4765 Third Wn-.71.3642 Wn -.83.9514 Wn -.73.9698 Fourth Wn-.92.7371 Wn-.101.154 Wn-.95.458 Out[229J= 
570 Chapter 9 Quantum Mechanics C. Now that the energy eigenvalues have been found, you can smoothly join the wave function in the well to the wave function outside the well. The wave function inside and outside the well are In[230]:= {in[r., I., WD.], out [r_, 1_, WD.]} = {waveIn[kIn,I,r],waveOut[qOut,I,r]}II. allRules; The complete wave function is In[231]:= wave [r_, I., WD.] = Which[rs 1, in[r,I,WD],r>l, out[r, I,WD]]; For the S-wave eigenfunctions, the plot of the first four energy eigenvalues are In [232] := Plot [wave [r, 0, WD] I .sValues I IRe l/Evaluate, {r,O,1.3}, PlotStyle -+ {{}, DaShing [{O. 01}], Dashing[{0.02}],Dashing[{0.03}]}, PlotLegend -+ Evaluate [WD/. sValues [[#]] &:/@Range [4]] , LegendPosition-+ {1, -1/2}, Epilog-+Line[{{l, -3}, {1,3}}]] ; 1.5 1 -6.553 -42.0 ----71.3 ---92.73 0.5 -0.5 The legend displays the value of the energy level. The command Re was wrapped around the wave to eliminate the small complex numerical errors. For the P-wave eigenfunctions, you have In[233]:= Plot[wave[r,l,WD] l.pValuesIIRe//Evaluate , {r,O,l.3}, PlotStyle -+ {{}, Dashing [{O. 01}], Dashing[{0.02}],Dashing[{0.03}]}, PlotLegend -+ Evaluate [WD/. pValues [[#]] &:/@Range [4]] , LegendPosition -+ {1, -1/2}, Epilog-+Line[{{l,-3}, {1,3}}] ] ; 
9.3 Three-Dimensional Schrodinger's Equation 571 -25.4 -58.4 ----83.9 ---101. -0.25 -0.5 Finally, for the D-States: In[234J:= Plot[wave[r,2,WD] /.dValues//Re//Evaluate , {r, 0, 1.3}, PlotStyle -+ {{}, Dashing [{O .01}], DaShing [{O .02}], Dashing [{O. 03}] }, PlotLegend -+ Evaluate [WD/. dValues [[#] ]&:/@Range [3]] , LegendPosition -+ {1, -1/2}, Epilog-+Line[{{1,-3}, {1,3}}] ] ; -8.49 -44.4 ----73.9 ---8.49 Note that all the above waves are smooth at the boundary r=a=l. This is a consequence of the fact that the wn are the eigenvalues that follow from the boundary conditions. . PROBLEM 5 The Hydrogen Atom in Spherical Coordinates. Consider Schrodinger's equation in spherical coordinates {r, {} , f/J}, -1i 2 2m V 2 ,p-[r, {}, f/J] + (V[r] - En) ,p-[r, {}, f/J] = 0 (9.2) with the Coulomb potential V [r] = 4-;' . The wave function can be written as a product ,p-[r,{},f/J] = R[r] E>[{}]<I>[f/J]' The angular dependence is given by spherical harmonics and the radial function R [r] satisfies the equation: 2 R[r] 2m R"[r] +-R'[r] - 1(1+1)-(V[r]-En) R[r] =0 r r Ii a. Require the radial solution to vanish at the origin and infinity and show the solution reduces to 
572 Chapter 9 Quantum Mechanics R[r] e- ao'n lC[2]LaguerreL [-1 +n-f, 1 +2f, arJ where aO= 4h1I"€O is the Bohr radius. em If C [2] = 21+( (  ) ( aOn (-I+n-f)! a0 3 n 4 (n + f)! then show that R [r] is normalized according to the criteria,1oo R[r]2"zdr = 1. b. Write the explicit wave function for {n=l, 1=0}, {n=2, 1={ 0,1}} and {n=3, 1={0,1,2}}. Graph the radial probability density p[r] = "zR[r]2 for the states n={1,2,3}. c. The angular dependence is given by Y [1, m,B, f/J]. Plot the absolute value of the wave function for 1 = 0, 1, and 2 for all the allowable values ofm and for fixed r. Required Packages In[235J:= Needs [Oaraphics'ParametricP1ot3D'O] Solution In [236J : = Clear [Oa1oba1' * 0] ; a. Enter the radial equation 2mR(r) (En-V(r» r 2 In[237J:= eq1=0== 2 +R"(r)+2R'(r)r-'('+1)R(r)/. 11 Out[237J= 0-- e 2 V[r] -+--/.En-+-WD 4 7fr eO ( e2 ) 2 2m 47TrEO -Wn R(r) r 2 + b R" (r) r 2 + 2 R' (r) r - f (t + 1) R(r) where the potential was replaced with the Coulomb expression and the negative energy bound states were replaced by a positive expression WI1= -En. The solution for R follows from applying DSo1 ve to eql, In [238J := eq2 = DBo1ve[eq1, R[r], r] [[1]] 
9.3 Three-Dimensional Schr6dinger's Equation 573 { 'hLog(r)-..fi..;mrYWn [ Out[238]= R(r)  e fl C 1 U ..J2 ..;m e 2 - 8 7f -vwn ( 60 h - 8 7f -vwn 60 h 8 7f -vwn60h 2 2 2..J2..;m r -vwn ] , t +, n + If!. Log(r)-.{2.,Jmrywn e h c 2 L 2 '+1 [ -{2...;m e 2 -8 JT..;w;., eO !:i-alf ywnED 1'1 8n ywn eOh 2..J2r-vwn ]} You can define some substitutions to simplify the notation. Given that aO=  is the em Bohr radius, you can define the rule m -7 41r o eaZ to insert this combination of factors. For a e the energy En, you parameterize this as a function of n 2 via the relation Wn = 32Ii Z : Z ':zea z , If you define the substitutions In [239] := substitutions = { 47fS01l2 e' m } m -+ &0.2 I Wn -+ 32 n2  602 fl2 ; then the radial solution becomes In[240]:= eq3 = eq2//.substitutions //PowerExpand//SiDlPlify Out[240]= {R(r)  e. r' ( c 1 U ( - n + ( + 1, 2 ( + 2, :0: ) + c 2 L;!l ( :0: ) ) } This solution is a linear combination of LaguerreL and BypergeometricU func- tions. The BypergeometricU function is either divergent or for integer values of n and I is proportional to the LaguerreL functions. Further inspection shows that valid candidates are n={1, 2,3, . . .}, 1={ 0,1,2, . . . ,n-1}. The physical wave function is In[241]:= eq4=eq3/.{C[1] ....O} Out[241]= {R(r) e. a6n r'c2L;.\( :0: )} For the radial equation to be normalized fooo R(r)2,2dr = 1 the value of C [2) must be multiplied by 
574 Chapter 9 Quantum Mechanics In[242]:= rNOrm=2,+1 (  ) ' aOn (n - I - 1) I a0 3 n' (n + I) I ; The normalized radial solution is In[243]:= rwave[n., 1_, r_] = R[r]/. eq4 [[1]] /. C[2] -+ rNorm// PowerExpand/ / Simplify Out[243]= 2'+1 aO.'.; e.a;¥n n+ 2 r' y (n - f -1) ! L:_\ [) y (n + t) ! The principle quantum number is n={ 1, 2 , 3, . . . } and the angular momentum quan- tumnumberis l={O,I,... ,n-I}. To verify the normalization 1 00 R[r]2r2dr = 1, con- sider the first few values of n: In [244]:= Integrate [r2 {rwave [1, 0, r], rwave [2, 0, r], rwave [2, 1, r] }2, {r, 0, (0), Assumptions -+ {Re [aO] > O} ] Out[244]= {1, 1, 1} b. The explicit wave function for {n=l, l=O}, {n=2,1={O,I}} and {n=3, 1={O,I,2}} is In [245] := eq5 = Table [rwave [n, I, r], in, 1, 3}, {t,0,n-1}]// TableForm [#, TableHeadings -+ { { On = 1 0, on = 2 0, On = 3 O} , {nl = on, nl = 10, 01 = 2 n )}]&: n=l f = 0 2 e--fIT a0 3 / 2 e. (2 - 10) 2 ..[i a0 3 / 2 2e. (27a0 2 -18raO+2r 2 ) 81 ..J3 aO 7 /2 f = 1 Out[245]= n=3 r e-2aQ r 2 -[6 a0 5 / 2  e.rl;o r ( 4 - 2L ) '\I "3 3 aO 27 a0 5 / 2 n=2 f = 2 n=l n=2 n=3 2 rx e. r 2 '\1 15 81 a0 7 / 2 Analysis of the radial wave functions can be performed by plotting these functions along the radial coordinate, thus giving insight into the electtonic SITucture of the atom. Define the plot operator for the probability densities r2R[r]2, 
9.3 Three-Dimensional Schr6dinger's Equation 575 In[246J:= plot [n., I., rmax.] : = Plot [r2 rwave[n, I, r] 2 l.aO .... 1// Evaluate, {r, 0.01, rmax}, Ticks.... {{1, 4, 8, 14, 20}, {0.1, 0.3, O.S}}, DisplayFunction .... Identity] ; where aO=1. The plots of the probability densities for {n=l, 1=0}, {n=2, 1={0, 1}} and {n=3, 1={0,1,2}} are,respectively, In [247J : = Show [GraphicsArray [Table [plot [n, I, n * 7], in, 1, 3}, {I, 0, n - 1}]] ] ; o.  o. O. 0.A4 0'4 0., !\ 0., !\  0., f\  c. The complete wave function is a product of the radial wave function and spherical harmonics. To plot the angular part of the wave function for fixed r you only need to consider the plot of the spherical harmonics. Consider the plots for the absolute value of the spherical harmonics. Define the plot operator In [248J := plot[t_,DL] := S,phericalplot3D[ S,phericalHarmonicY [I, m, e, rII] / lAbs l/Evaluate, {e, 0, :If}, {rII, 0, 2:1f}, Boxed.... False, Axes.... False, DisplayFunction.... Identity] ; The graphs for 1=0,1, and 2 with the allowable values ofm={ -1, 1}, follow from In[249J:= Ptl = Table [plot [t, m], {I, 0, 2}, {m, -I, I}] ; Show[GraphicsArray[ptl]]; 
576 Chapter 9 Quantum Mechanics e ele ..f.. . 9.4 . EXERCISES The solutions to many of these exercises can be found at our web sites. 9.1 Infinite Potential Well with Rectangular Perturbation Consider the symmetric double potential barrier: V(x) = 00 if x < 0; V(x)=O ifO<x<a l ; V(x) = VI if a l < x < a 2 ; V(X) = 00 if a 2 < x < a 3 . (a) Solve the one-dimensional SchrOdinger's equation for the wave function. (b) Make a table of eigenvalues. Graph the eigenvalues as a function of VI . (c) Graph the first few wave functions for some fixed value of VI' Use Plot3D to compare how the wave functions change with VI' (d) Develop a perturbation procedure that solves this problem. 9.2 Tilted Square Well Consider the tilted potential well: V(x)=V I ifx<O; V(x) = VI + V 2 (x/a) = 0 if 0 < x < a; V(x) = VI + V 2 if a < x; (a) Consider a particle bound in the well. Solve SchrOdinger's one-dimensional equation for the eigenfunctions. (b) Make a table of the eigenvalues and graph the first four wave functions. (c) Find the transmission and reflection coefficients for a particle with energy greater than VI' Graph the coefficients, and show how the results depend on V 2 . 9.3 The Wentzel-Kramers-Brillouin Approximation Consider the one-dimensional Schrodinger equation with a potential V [x] . Assume the wave function is of the form u=R [x] Exp [i S [x] Ih]. 
9.4 Exercises 577 (a) If R [x] is a slowly varying function, derive an equation for S [x] in tenns of the potential V[x]. (b) Derive a procedure that returns the probability of tunneling through a potential barrier. 9.4 Plot of the Electron Probability Density Derive two operators using ScatterPlot that plots the probability density of a wave function. Make the density of dots proportional to the probability density given by the wave function. Construct a density operator that plots the results in two dimensions, and a second operator that plots the results in three dimensions. Apply the two operators to the hydrogen wave functions. 9.5 Perturbed Harmonic Oscillator Consider a particle that is bound by a potential V = !A:x2 + px 4 . Treat the last tenn pX' as a perturbation. (a) Find the perturbed solutions for the eigenvalues and eigenfunctions. (b) Compare the perturbed and unperturbed solutions by graphing the results as a function of p. (c) Construct a perturbative function using Module for the ont-dimensional Schrodinger equa- tion with an arbitrary potential. 9.6 Perturbation Theory Paraboloidal coordinates {, 17, cp}, wherex=17  Cas [cp], y =17  Sin [cp], and z=l/2 (2_ 17 2 ) , is another coordinate system where the SchrOdinger equation can be separated if the poten- tial is of the fonn V [ i: ] _ Vg[] + V q [17] '0,17 - e + rT Examples of such systems are the hydrogen atom and the hydrogen atom in a constant electric field. Let the potential be of the fonn Vg[] + V q [17] V[, 17] = e + rT and assume the wave function can be expressed as the product of three functions f [] g [17] 4>[cp] . (a) Separate the variables and find the ordinary differential equations for f []. g [17], and 4>[cp], (b) Consider the hydrogen atom in an electric field. The potential for the system is, V(r) _;2 _ eEoz. Find the differential equations. 9.7 Separation of Variables in Cylindrical Coordinates Consider the following problems in cylindrical coordinates. (a) Express SchrOdinger's equation _Jj2 2m V 2 rfrfp, 6, z] + (Vfp, 6, z] - En) rfrfp, 6, z] = 0 (9.3) in cylindrical coordinates {p, 6, z}, where x = pCos[6], y = pSin[6] , and z = z. Let the potential be of the fonn V = Vpfp] + Vz[z] and assume the wave function can be expressed as the product of three functions Rfp ]8[ 9]h[ z]. Derive ordinary differential equations for Rfp], 8[6], and h[zl 
CHAPTER 10 Relativity and Cosmology 10.1 . INTRODUCTION 578 In this last chapter we solve problems taken from special relativity, general relativity, and cosmology. Einstein recognized that the classical ideas of space and time were suspect. He rejected the idea that space and time were independent of each other and developed, with simple postulates, a relationship between space and time. In Newtonian mechanics the ttansformation between inertial (nonaccelerating) frames is simple due to the absolute nature of time. Inertial frames can differ by a rotation of the coordinates, a ttanslation of the space origin, a ttanslation of the time origin, and by a difference in constant velocity. These general ttansformations form a 10 parameter group of ttansformations called the Galilean ttansformations. If we find one inertial frame, then we have found all of them by the Galilean ttansformations. For a time it appeared that ether could single out an absolute frame. In 1878 Maxwell proposed the existence of ether as the universal substance that acted as a medium for the transmission of electtomagnetic waves. It seemed reasonable to assume that the frame of "still ether" coincided with the frame of the fixed stars and could be identified with absolute space. Experiments tried without success to detect our motion through the ether. Ether had no measurable properties and the speed of light in free space was the same everywhere, regardless of the motion of the source or observer. In 1889 the Irish physicist George FitzGerald pointed out that the results could be explained if the length of material bodies changed as they move through ether. In 1892 Lorentz, unaware of FitzGerald's paper, proposed an almost identical conttaction. They postulated that the movement through ether produced a "real" conttaction of length. A more natural explanation had to wait until 1905 when Einstein proposed the special theory of relativity. The special theory of relativity postulated that the laws of physics held in all inertial frames moving with respect to one another at a constant velocity. Gone was the notion of an absolute frame of reference and there was no need for ether. The next step in understanding spacetime was Einstein's theory of general relativity, proposed in 1915. General relativity merged Newtonian gravity with ideas that stemmed from special relativity. The basis of general relativity was the postulate that an observer cannot distinguish between the local effects produced by a gravitational field and those produced by an acceleration. This postulate, known as the principle of equivalence, fol- lows from the experimental observation that the inertial mass of a body is exactly equal to its gravitational mass. Consequently, Einstein postulated that the laws of physics must be expressed by equations having the same form in all frames of reference, regardless of their motion. Thus, the general theory covered acceleration as well as uniform motion and was able to describe gravity. General relativity called for a new geometty-a geometty of 
10.2 Special Relativity 579 curved four-dimensional spacetime. General relativity abandons the notion of a gravita- tional force and instead thinks of moving masses as responding to the curvature of space- time. The presence of mass curves spacetime and the curvature acts back on the motion of the mass. In general relativity spacetime is described with Riemannian geometty and the geometty is determined by the energy and momentum density in space. This final chapter is divided into three sections: Special Relativity, General Relativity, and Cosmology. At the beginning of each section we include an overview of the subject followed by problems. The methods used to solve these problems are not unique; you are encouraged to find procedures that will illuminate the physics and to find other approaches that make the calculations faster. You may wish to turn off the spell checker before starting this chapter: In[l]:= Off [General :: spell]; Off [General :: spelll]; 10.2 . SPECIAL RELATIVITY 10.2.1 . Overview In 1905 Einstein proposed two postulates that formed the foundations of special relativity. One postulate relates to the constancy of the speed of light and the other to the formal invariance of physical laws in different inertial reference frames. 1. Principle of the Constancy of the Speed of Light: The velocity of light as measured in a vacuum is the same in all inertial systems and is independent of the motion of the observer or source. 2. Principle of Relativity: Physical laws and principles have the same form in all iner- tial systems so there does not exist any preferred inertial system. The first postulate is the prescription used to find the space and time ttansformations be- tween inertial frames. The relation between inertial frames in classical mechanics is simple due to the absolute nature of time. To illusttate a classical ttansformation, consider two in- ertial frames 2.: and 2.:'. Let the coordinates of a certain event in frame I be {t,x,y,z} and in 2.:', the coordinates of the same event are {t', x', y', z'}. The absolute nature of time means t = t'. Let the coordinate systems be coincident at t = 0 and assume the relative motion of the two frames is along the x-direction. If the velocity of 2.:' relative to 2.: is V, then the clas- sical ttansformation between the inertial frames is x' = x - Vt, y' = y, z' = z, t' = t. This classical ttansformation is called a Galilean ttansformation. Galilean ttansformations do not satisfy the first postulate of special relativity because they do not preserve the velocity of light. The ttansformations between inertial frames that keep the velocity of light constant are known as Lorentz ttansformations. A Lorentz ttansformation relates the coordinates {t, x, y, z} of an event in I to the coordinates {t', x', y', z'} of the same event in another inertial system I'. To consttuct the Lorentz ttansformation, let {dt, dx, dy, dz} be the infinitesimal distance between two nearby points in an inertial frame I. The space and time coordinates of a light ray between these nearby points satisfy the equation 0 = dt 2 - 
580 Chapter 1 0 Relativity and Cosmology dx2 - di - dz 2 . (We choose natural units and set the speed of light equal to one (c = 1) in this chapter.) The equation for light suggests we define a function ds 2 by the relation ds 2 = dt 2 - dx2 - di - dz 2 . We call ds 2 the line element. The propagation of light is described by ds 2 = O. Similarly in I' the line element is ds '2 = dt'2 - dx'2 - dy'2 - dz,2 and light is described by ds'2 = O. The first postulate of relativity is satisfied if the ttansformation between the frames leaves the line element invariant, ds 2 = ds'2. The line element allows us to inttoduce the concept of a metric since ds 2 can be written s ds 2 = TJ J1yd# dx Y , where the coordinate differentials are {dt, dx, dy ,dz} and the metric IS [ 10 o -1 TJjlY = 0 0 o 0 o o -1 o jj ] We assume the Einstein convention and sum over repeated indices. The pseudo- Euclidean matrix TJjlY is the metric for the spacetime. In I' the line element is ds,2 = TJjlY dx'J1 dx'Y. To find the ttansformation between the two inertial frames, we assume a linear ttansformation x'J1 = a/xv. The conditions for a/ needed to preserve the speed of light are TJjlY = 2.: 2.: TJaf3a: d;.. Consider the values of a/ that connect one inertial frame I with another inertial frame I' moving with relative speed v along the z-axis. The Lorentz ttansformation that relates coordinate frames with different velocities and no rotations of the coordinates is called a boost. The Lorentz boost between these two inertial frames is z' = y(z - vt), t' = yet - vz), y' = y, x' = x, where y = k . (Recall, c = 1.) The expression for aa J1 is [ yO 0 -vy ] 010 0 = 0 0 1 0 -vy 0 0 y The second postulate of relativity requires the equations of physics to have the same form in all inertial coordinate systems. An equation written in a form-independent manner is said to be covariant. The consttuction of covariant equations leads to the study of tensors; tensors are those objects that are invariant under coordinate ttansformations. The simplest of all tensors is a scalar. If 4> is a scalar in coordinates x, then in the coordinates x' the scalar is 4>', where 4>' = 4>. For example, the line element ds 2 is a scalar since ds'2 = ds 2 . A scalar is called a tensor of rank zero. The next most elementary tensor is of rank one, or a vector. In four-dimensional spacetime, a vector has four components and can be either conttavariant or covariant. If the components vi' (IL = 1,2,3,4) ttansform like the coordinate differentials d#, the vector is conttavariant, v'J1 = X; vr. The components of conttavariant vectors are denoted with superscripts. If the components of a vector, va (a = 1, 2, 3, 4), ttansform like v = : v f3 ' the vector is covariant. We can generalize these ttansformations to define tensors of arbittary rank. An arbittary tensor can be covariant, conttavariant, or mixed. The metric can be used to convert conttavariant indices to covariant indices. For ex- ample, consider the conttavariant vector AY and lower its index with the metric TJj1Y' AJ1 = 
10.2 Special Relativity 581 T/J1.A Y . Indices are raised with the inverse metric tensor T/ av . If AJ1 are the components of a covariant vector, then the conttavariant vector is AJ1 = rfY Ay. The scalar product of to four-vectors is fined as T/J1YAJ1 BY. The product is a scalar. If we defie A = {Ao, A} and BJ1 = {SO, B}, then the scalar product gives T/J1YAJ1BY = AOBo - A . B. A special case of this relation  t:!le square of the length of a four-vector V Y that is defined to be T/JlY VJ1 V Y = VO VO - V . V. Due to the presence of the minus sign in the metric, we can dis- tinguish three types of four-vectors: timelike if T/JlY VJ1 VY > 0, spacelike if T/JlY VJ1 VY < 0, and null if T/J1Y VJ1 V Y = O. An event is represented by a single point in spacetime {to' x o , Yo, Zo}. The path of a particle, called its world line, is described by the four parameterized coordinates .xJ1[s] = {t[s], x[s], y[s], z[s]}. The tangent to the world line is a four-velocity vector. VJ1 = d.xJ1 = { dt dx dy dZ } ds ds' ds' ds' ds The tangent is a conttavariant vector and is the generalization of the three-velocity in Newtonian mechanics. For a world line the magnitude of the vector is unity, T/JlY VJ1 V Y = 1. The four-velocity of a photon is a null vector, T/JlY VJ1 VY = O. The notation simplifies if . V y { ..... } h dt d th thr I ....... { dx dy dz } S . h we wnte = y, yv , were l' = liS an e ee-ve OCIty IS V = Iii' Iii' Iii' mce t e magnitude of th:., fo-vector for a particle is one, T/JlY VJ1VY = y2(1 -  . ) = 1, it follows that y-2 = (1 - v . v). The four-momentum is closely related to the four-velocity. The four-momentum is de- fined by pi1 = m o VJ1, where VJ1 is the four-velocity and m o is the rest mass or proper mass of the particle. This vector can be written in terms of three-vector noton, pi1 = {m o 1', moy} = {E, P}, where E = moY is the total energy of the particle and P = moy is the relativistic three-momentum. The magnitude of the momentum vector is just the rest mass of the particle, T/J1Ypi1pY = m. A relation.....beeen energy, momentum, and mass follows from this observation, T/J1Ypi1pY = E 2 - P . P = m. An important four-vector is the four-momentum of a photon. The photon's four-momentum vector can be written as k Y = hv o {1, ";-}, where V o is the frequency measured by an observer at rest relative to the source, h is Planck's constant, and .,;- is the normalized three-vector, .,;-..,;- = 1. The three- vector .,;- points in the direction the phon  propagating. The four-momentum vector is obviously null since T/J1YkfkY = h2v(1 - n . n) = O. . PROBLEM 1 Decay of a Particle. Consider a stationary particle with rest mass m l that decays into two particles, one of mass m 2 and the other of mass m3' Let the four-momenta for the particles be p, pi, and pj. The conservation of energy and momentum is pj = p: - pi. It is often the case that the algebra for calculations in special relativity simplifies if the problem can be expressed in terms of scalars. Evaluate the scalar equation m = T/J1Ypjp and get an expression for Y2 = _  . Show that the kinetic energy of the particle with 2 2 V l- mass m is (ml-m2) -m3 2 2ml 
582 Chapter 10 Relativity and Cosmology pI After  /P2 m. Before . m1 m3'p, Remarks and Outline The conservation of energy and momentum P; = p; - pi gives two nontrivial equations between the initial and final momentum. These equations are so simple that the solution for the kinetic energy is sttaightforward. Try it. It is not necessary to use the scalar equation m = 1JJ1VP;P3 to simplify the algebra for this simple case, but this is an excellent example to illusttate the use of scalars. Solution In [21: = Clear ["Global' * "] ; In the rest frame of particle one, the four-momenta vectors are defined by the rules, In[31:= momRule = {pI ....ml{l, 0, 0, O}, p2 ....m2y2{1, 0, 0, -v2}, p3 .... m3 y3{1, 0, 0, V3}} 1 where yi = y I .2 (recall, c=l). The fact has been used that in the rest frame of particle I-vl one the speeds v2 and v3 must have opposite signs to be consistent with the zero initial three-momentum. You can align these particles along the z-axis without loss of generality. The conservation of four-momentum gives a relation between these three momenta, In [ 41 : = conRule = {p3 .... pI - p2} ; If we define the metric In[51:= 17 = DiagonalMatrix[{l, -1, -1, -I}]; it then follows from the scalar invariant m = 1JJ1yP;P3 and conRule that In[61:= eql = m3 2 == p3 .17.p31 .conRule/ . momRule I . {V2 ....  1 - y2 } I I ExpandAll Out[61= m3 2 == m1 2 - 2m2)'2 ml +m2 2 where v2= 1 -  was used to eliminate the speed v2. Solving for Y2' you get 
10.2 Special Relativity 583 In [7] : = sol = Solve [eql, y2 ] / / Simplify / /Flatten { m12 + m2 2 - m3 2 } Out [7] = )'2 -> 2 ml m2 The kinetic energy of m2 is the total energy m2 y2 minus the rest mass m2: In [8] : = FullSimplify [m.2 y2 - m.2 / . sol] (ml-m2)2 -m3 2 Out[8]= 2ml . PROBLEM 2 Two-Particle Collision. A particle of rest mass m l collides with a station- ary particle of mass m 2 . The collision produces two particles with masses m 3 and m4' The threshold kinetic energy in the laboratory is defined to be the kinetic energy just sufficient to make the center of mass energy equal to the sum of the rest masses in the final state. Before After pI /P3 _m3 p2 . . . m1 m2 e. m4 "'P4 a. Write the initial four-momenta for the two particles in the laboratory frame and find the total initial four-momentum, FiT. Do the same for the total four-momentum as measured in the center-of-mass frame, EtMT. b. Consider the scalar invariant llJJvIi' pV, where Ii' is the total momentum. Evaluate the invariant in the laboratory and center-of-mass frames. Equate the expressions and solve for the threshold energy. Express the results in terms of the kinetic energy of the particle with mass m l . Use the definition of threshold energy and show that the initial kinetic ener gy of the P article with mass m is (m3+m4)2_(ml +m2)2 1 2m2 . Solution In [9] := Clear ["Global ' *"]; a. Let the initial four-momentum of the particle with mass ml be Fil and the four- momentum of the stationary particle be Fi2. The initial four-momenta of the two particles in the laboratory frame are In[10]:= pLl = {El, pl, 0, O}; pL2 = {m.2, 0, 0, O}; 
584 Chapter 1 a Relativity and Cosmology and the total initial four-momentum is In [11] : = pLT = pLl + pL2 Out[ll]= {El +m2, pl, 0, O} Next, write the initial four-momenta in the center-of-mass frame: In[12]:= pCMl = {ECM1, kCM1, 0, OJ; pCM2 = {ECM2, -kCM1, 0, OJ; Note, we have used the fact that the sum of the three momenta is zero. The total four- momentum is In [13] : = pCM'l' = pCMl + pCM2 Out[13]= {ECM1+ECM2, 0, 0, O} b. Consider the scalar invariant 1] JJV Ii' pV, where Ii' is the total momentum. Evaluate the scalar invariant in both frames. Since it is a scalar it must be ttue in all reference frames. If you equate the two expressions, you get In[14]:= 17 = DiagonalMatrix[{l, -1, -1, -l}]; In[15]:= eql = pLT.I7.pLT == PCM'l'.I7.PCM'l' Out[15]= (El+m2)2 _p12 == (ECM1+ECM2)2 The threshold energy is obtained when In[16]:= eq2 = ECMl + ECM2 == m3 + m4; where m 3 and m 4 are the rest masses of the final particles. To find the threshold energy in terms of the kinetic energy of particle one, you must express the energy EJ and the three-   momentum pI in terms of kinetic energy. The kinetic energy TJ is related to EJ and pI by the equations In [17] : = {eq3, eq4} = {El = = Tl + m1, pl = = "1/ E1 2 - m1 2 } Out [17] = {El == ml + Tl, pl == ,j E1 2 - m1 2 } Using eql, eq2, eq3, and eq4 to express TJ in terms of the rest masses, you get In [ 18] : = sol = Solve [{eql, eq2, eq3, eq4}, {Tl}, {El, pl, ECM1}] / /Flatten/ /Simplify { m12+2m2ml+m22_(m3+m4)2 } Out[18]= Tl.... 2m2 
1 0.2 Special Relativity 585 . PROBLEM 3 Compton Scattering. A photon with wavelength AD collides with an elec- tton of mass m at rest and scatters with a new wavelength A1. Let the incident photon move along the z-axis and let the scattered photon be in the x-z plane, making an angle (}l with the z-axis. The scattered electton moves along a direction making an angle (}2 with the z-axis. Let P: and pi be the initial four-momenta of the photon and electton, respectively. The final four-momenta of the photon and electton are /J and p;., respectively. Before After p3 p2 u . m m p4 pI . AO L a. Write the initial and final four-momenta. Consider the scalar invariant m 2 = 1]JJvp;.p and show the change in wavelength as a function of the photons scattering angle (}l is A1 _ AD = h(1 - cos[(}I]) . m b. Write the four equations that follow from the conservation of four-momentum pi + pi = /J + p. Show the kinetic energy of the recoil electton m( y f - 1) is h(1 - cos[(}I]) AO(I + m;o -cos[(}IJ) where y f = _ h and vf is the recoil velocity of the electton. "V l-vf2 c. Show that - tan [ e 2] - h+m AO Solution In[191:= Clear [nGlobal ' * n]; a. The initial photon and electton four-momenta are h In[201:= pl= AO {1,0,0,1}; p2 = m {l, 0, 0, O}; 
586 Chapter 1 a Relativity and Cosmology where AD is the initial photon wavelength, h is Planck's constant, and the photon is moving along the z-axis. The final four-momentum vectors are h . In[21J:= p3 = A1 {1, S1n[81], 0, COB [81] }; p4 = myf{l, -vf Sin[82], 0, vf COB [82]}; where A1 is the scattered wavelength of the photon, y f = .,.!---;; , and vf is the recoil V l-vf2 velocity of the electton. The photon and electton are moving in the x-z plane and the angles are measured relative to the z-axis. Consider the scalar invariant m 2 = 1]JJVP'4. It follows from the conservation of energy- th JJ JJ JJ JJ E . th al . ., f d momentum at p4 = PI + P2 - p3. xpressmg e sc ar mvanant m terms 0 PI' P2' an P3' it follows that In [22J := 17 = DiagonalMatrix[{l, -1, -1, -1}]; In [23J := eq1 = (m2 == (p1 +p2 -p3) .17. (p1 +p2 -p3)11 SimplifYIIExpandAll) 2 Cos(e1) h 2 2h 2 2mh 2mh Out[23J= .1..0.1..1 - .1..0.1..1 +;;:0 - J:1 == 0 Solve eq1 for A1, In[24J:= lamRule= Solve[eq1, A1][[1,1]] II BxpandAll Cos (e1) h h Out[24J=A1-> +-+.1..0 m m The shift Al-AO is: In [25J := A1 - AOI .1amRulel I Collect [I, {m, h}]& h (1-Cos(e1)) Out[25J= m b. The four equations that follow from the conservation of four-momentum are In [26J : = (eq2 = p1 + p2 == p3 + p4 II Thread) I I Columnl"orm Out[26J= h h AD + m == .1..1 + m yf h Sin(e1) . 0== .1..1 -mvfyf SJ.n(e2) True h h Cos (e1) AD == .1..1 +mvfyf Cos(e2) The expression for the electton's kinetic energy is m (yf-1) and the value of yf follows from the first equation, 
10.2 Special Relativity 587 I:rl [27] : = eq3 = Solve [{eq2 [ [I]]}, yf ] I IJ!'latten I I Simplify Out [27] = { yf -> h (Ai - AD) + 1 } m AD Ai Using lamRule to eliminate '\1, the kinetic energy for the recoil electton becomes In[28]:= « m(yf-l) l.lamRule/.eq31IFactor) I. lamRule I. AO -+ him temp I I Factor) I. temp -+ AO m/h Out[28]= - h (Cos (81) - 1) AD ( mo - Cos (81) +1) C. The second and fourth equations in eq2 give two relations between the angles ()j and ()2' In [29] : = eq40 = eq2 [ [{2, 4)] ] { h Sin(81) . Out[29]= 0== Ai -mvfyf Sm(82), h h Cos (81) } AD == Ai +mvfyf Cos(82) Eliminating yf, it follows that In[30]:= eq5 = Eliminate [eq2 [[ {2, 4o}]], yf] I I Simplify hAl Sin(82) . Out[30]= AO*O/\Al*O/\ AD ==hSm(81+82) You can use lamRule to eliminate '\1 In[31]:= eq6= eq5/.1amRulell ExpandAll [#, Trig -+ True] &: Out[31]= AD * ° /\ Cos (81) h +  + AD * 0/\ m m Cos(Sl) in(S2)h2 + Sin(2)h2 +.1..0 Sin(82) h AD h Cos(82) Sin(81) +h Cos(81) Sin(82) and use Solve to reduce this expression to the desired form. In[32]:= Solve[eq6/.{Sin[82] -+Tan[82] Cos[82]}, Tan [82]] [[1,1]] I. tan -+Tan/. Rule -+ Equal I I S:iJ!wlify mAD Cot (@) Out[32]= Tan(82) == 2 h + mAD 
588 Chapter 10 Relativity and Cosmology . PROBLEM 4 Moving Mirror and Generalized Snell's Law. Consider a mirror at rest in the reference frame :I'. As observed in :I', the mirror's rest frame, an incident beam of light makes an angle em relative to the normal and, according to Snell's law, reflects at the same angle. The photon's four-momentum vector can be written as k V = h V o {1, }, where V o is the frequency measured by an observer at rest relative to the source, his Planck's constant, and  is the normalized three-vector, .  =1. The frequency of light in :I' is v m and is the same for the reflected and incident beam. The laboratory frame :I is moving with velocity v along the normal. In the laboratory frame, the incident light has frequency Vi and makes an angle e i with the normal to the mirror. The reflected beam in :I has frequency v r and makes an angle Or relative to the normal. A   Y m Y r k f' k a. Write the four-momentum vectors for the incident and reflected momenta in the lab- oratory and mirror reference frames. Relate these vectors by a Lorentz boost. Show that the generalized Doppler formula is 1- v 2 Vi = v r 1 + v 2 + 2vcos[Bi]" b. Show that the generalized Snell's law is [ eo ] [ e ] I-v cot i tan ; = 1 + v ' Solution In[33] : = Clear [RGlobal' * R] ; a. The photon's four-momentum vector can be written as k V = h V o {1, }, where V o is the frequency measured by an observer at rest relative to the source, h is Planck's constant, and  is the normalized three-vector, .  = 1. The three-vector  points in the direction the photon is propagating. The momentum four-vectors in the laboratory frame for the incident and reflected waves are In[34]:= xi = vi{l, Cos[8i], Sin[8i], O}; Kr = vr{l, - COS [8r], Sin [8r], O}; 
10.2 Special Relativity 589 where {8 i , 8r} are the incident and reflected angles of the beam and {Vi' V r } are the incident and reflected frequencies as measured in the laboratory frame. Without loss of generality the value of h has been set equal to one. In the mirror's frame, the reflected and incident frequencies v m are equal and by Snell's law the angle of incident and reflection 8m are the same. The momentum vectors in the mirror's frame are In [35J : = KJni = vm{l, Cos [em], Sin [em] , O}; br = vm{l, - Cos [em], Sin [em] , O}; The four-momenta in the laboratory and mirror frames are related by Lorentz ttansfor- mations. The boost between two coordinate systems moving with relative speed v along the x-axis is ( y -vy In [36J := boostx = 0 o -vy 0 y 0 o 1 o 0 o : ], where the symbol y = b and the speed of light, c=l. The incident four-momenta in the two frames are related by a Lorentz boost, In [371 := (eql = (Ki == boostx.KJni) II Thread) I I Columnl"orm Out[371= vi == yvm-vyvm Cos(8m) vi Cos(ei) ==yvmCos(8m) -vyvm vi Sin(ei) == vm Sin (8m) True Another four equations follow from relating the reflected four-momenta: In[38J:= (eq2 = (Kr == boostx.Kmr) II Thread) II Columnl"orm Out[38J= vr==yvm+vyCos(8m) vm -vr Cos (er) == -vy vm - y Cos (8m) vm vr Sin(er) == vm Sin (8m) True Eliminate the variables cos[8 r ], sin[8 r ], cos[8 im ], sin[8 im ] and VIII. in eql and eq2 and solve for vi, In [39J := soll = Solve [{eql, eq2}IIFlatten, vi, {Cos [8r], Sin [8r], Cos [em], Sin [em], vm}] II Flatten . (v 2 -1)vr {V1 -> v2 + 2 Cos (ei) v + 1 } Out[39J= This is the generalized Doppler shift. 
590 Chapter 1 a Relativity and Cosmology b. To get a generalized Snell's law we first eliminate vi from eql and eq2 using soll. Then use Eliminate to eliminate Cos [8m), Sin [8m) and y: In[40]:= eq3 = Eliminate [ {eq1, eq2 , vr;. 0, vi;' 0 , v;' 0, v;' -1 , v;' 1 }/.sol11IFlatten, {Cos[9m],Sin[9m],y}] II Map [Simplify , #]&:; eq3 II Col umnl"orm Out[40]= 2 (2 v + (v2 + 1) Cos (ei) ) 2 Cos (er) == v 2 + 2 Cos(ei) v+ 1 (v2 -1) Sin(ei) Sinter) ==- v 2 +2 Cos(ei) v+1 v*l v*O v+1*O vm * 0 vr * 0 v Cos (ei) + 1 * 0 v 2 +2Cos(ei)v+1*O Use the second equation to get an expression for v, In[41]:= eq4 = Solve [eq3 [[2]] , v] II Simplify II Powerl!:xpand II Simplify {{ Sin(ei+er) } { Sin(ei-er) }} Out[41]= v-->-Sin(ei) + Sin (er) , v--> Sin(ei) +Sin(er) Only the second solution has the correct nonrelativistic limit. This second equation can be written in the form In [42] := 1-v ( l-V ) - == -1.eq4[[2]] IISimplify v+1 v+1 1 - v ( ei ) ( er ) V + 1 == Cot 2 Tan 2 Out[42]= . PROBLEM 5 One-Dimensional Motion of a Relativistic Particle with Constant Ac- celeration. Consider a relativistic particle accelerated by a constant force directed along the x-axis. Let the particle move along the x-axis and solve for its distance as a function of coordinate time t. The motion is assumed to be described by the relativistic equation d([t]) = g, where v[t) =x' [t), t is the coordinate time, and g is the acceleration con- stant due to the force. Assume the initial velocity is v[O) =vO, and the initial position is x[O) =xO. 
10.2 Special Relativity 591 a. Solve for x [t) and show the solution has the expected nonrelativistic limit. b. Plot x [t) for the relativistic and nonrelativistic solutions. Solution In [43] : = Clear [nGlobal' * n]; a. The relativistic equation of motion for constant acceleration is In[44]:= eqMotion = D [ x' [t] , t ] == Sf V l-x'(t)2 XU (t) x' (t) 2 XU (t) Out[44]= + == g (1_X'(t)2)3/2 ,} 1-x'(t)2 where t is the coordinate time. The algebra simplifies if we solve eqMotioD with ar- bittary boundary conditions and then fix their values at the end of the calculation. You must be careful in using PowerExpand because the operation will not always choose the correct sign of the roots. Solving eqMotioD for x[t), you get In[45]:= eql = DSolve [{eqMotioD } II Flatten , x[t], t] II SimplifyllPowerExpand II Simplify II Flatten { ,} g2t2_2gClt+cf+l Out[45]= x(t)->c 2 + , g ,} g2 t 2 - 2 gC l t + cf + l } x(t) -> c 2 - g Only the first solution satisfies eqMotioD. To verify this result substitute the two so- lutions given by eql into eqMotioD. You get In [46] : = eqMotion/. D[eql [[i]], t] I. D[eql [[i]], {t, 2}]&I@{l, 2} II Simplify II PowerExpand II Simplify Out[46]= {True, 2 g == O} Solution one is the correct answer: In [471 := eq2 = x[t] I. eql [[1]] ,} g2 t 2 - 2 gC l t + cf + 1 Out[471= c 2 + g The initial conditions are related to C [ 1) and C [ 2) by the two equations In[48]:= initialConditions = {( eq2) == xO, (D[eq2, t]) == vO}/.t -+ 011 PowerExpand 
592 Chapter 10 Relativity and Cosmology -Jcf+ 1 C Out[48J= {c 2 +-==xO,-  ==vO} g \f cf + 1 U sing the rule In [49J := gamRule = {1-V0 2 -+  , v0 2 -1-+ -  }; to simplify the expressions for C [1) and C [2) , you get In[50J:= eq3 = «Solve[initialConditions, {C[l],C[2]}] IISimplify)11 powerExpand) I. gamRule II powerExpand Out [50J = {{ C 2 -> xO - , C 1 -> -vO I'}' {c 2 -> xO - , C 1 -> vO I'} } You can easily check that only the first expression for these constants reproduces the correct initial condition. The rule for the constants and initial condition is In[51J:= crule=eq3[[l]] Out[51J= {C2->XO-'Cl->-VOI'} Eliminating C [ 1) and C [ 2) in eq2, the result for x [t) follows In [52 J : = xsol = eq 2/. crulel 1 Simplify gxO - I' + -J g2 t 2 + 2 gvO I' t + vo 2 1'2 + 1 Out[52J= g The nonrelativistic limit is recovered for small vO and g: In[53J:= nonRelResult = Series [( xsol/.'( -+  ) , {sr, 0, 1}, {vO, 0, 1} ] II Normal gt 2 Out[53J= T+vOt+xo b. Set the values of the parameters to In[54J:= values = {XO -+ 0, vO -+ 1/2, g -+ -0.1, 1 } '(-+ . ";1- v0 2 ' and plot the relativistic and nonrelativistic motions. If you define the text for the graphic, 
10.2 Special Relativity 593 In [55] := text = {Text[StyleForm[DRelativistic D , FontFamily- > DTimes - Bold n , FontSize-+ 10], {10, 1.2}], Text [ StyleForm [Dnon - relaltivistic n, FontFamily- > nTimes - Bold n , FontSize-+l0], {8, 0.2}]}; and combine it with the plot of x [t] , it follows that In[56]:= Plot[{xsol,nonRelResult}//.values// Evaluate, {t, 0, 12}, GridLines -+ Automatic, Axes Label -+ {Dt n, nxn}, PlotStyle -+ {{'l'hickness [0.01] }, {Dashing[{0.06,0.1}], 'l'hickness[O.OOl]}}, Epilog -+ text]; x 1. t o. -0. The solid curve is the relativistic result and the dashed curve is the nonrelativistic motion. . PROBLEM 6 Two-Dimensional Motion of a Relativistic Particle in a Uniform Elec- tric Field. A particle with mass m and charge e moves in a uniform static electric field Eo. The electric field is assumed to be along the y-axis. The four-momentum for the par- ticle is pI1 = {may, moY} ={E, p}, where E = may is the total energy of the particle and p = may  = {Px' pY' Pz} is the relativistic three-momentum. The equation for the three-momentum is dp .... dt = eEo. The relativistic equation of motion reduces to P [t] = 0, P [t] =e Eo, P [ t ] = O. 
594 Chapter 1 0 Relativity and Cosmology a. Assume the initial momentum is perpendicular to the electric field so Px[O] =Pxo' py[O]=O, and Pz[O]=O. hothatpx[t!.=pxO, ->.py[t]=e EO t,andpz[t]=O. Use the relations E2_ P . P = m6 and P = moYv to show that my =  m2 + px0 2 + e 2 E02t 2 . b. Solve for the particle's path and compare the nonrelativistic limit and the relativistic solution. Solution In [57] : = Clear [ nGlobal' * n] ; a. It you define the relativistic three-momentum vector In[58]:= pVec[t.] = {px[t],py[t],pz[t]}; then the equations of motion for the particle's relativistic three-momentum are In [59] : = eqMotion = pVec' [t] == {O, eEO, O}IIThread Out[59]= {px'(t) ==O,py'(t) ==eEO,pz'(t) ==O} The initial conditions are assumed to be In[60]:= initial = {px[O] == pxO, py[O] == 0, pz [0] == O}; The equations of motion and initial conditions can be integrated to give expressions for the relativistic momentum components: In[61]:= momRule = DSolve[eqMotion-Join-initial, {px[t], py[t], pz [t]}, t] [[1]] Out[61]= {px(t) ->pxO,py(t) ->eEOt,pz(t) ->O} An expression for Y follows from the energy and momentum relation (my)2 = p. p +m 2 , where p = pVec. It follows that In [62] := yRule = m ¥ == Sqrt [ pVec [t] . pVec [t] + m 2 I. momRule]IIS0 1Ve[#,¥]&IIFlatten {Y -> .Jm 2 + PX0 2 m + e 2 E0 2 t 2 } Out[62]= 
10.2 Special Relativity 595 b. The relativistic momentum and three-velocity are related by p = moY . If we let  = {, , } and P =Pvec, then it follows that In[63J:= eq1 = pVec [t] == m-y{x' [t], y' [t], z' [t]}/. momRule/.-yRule//Thr ead Out[63J= {pxo ==  m2 +pxo 2 + e 2 E0 2 t 2 x' (t), eEO t == m2 +pxo 2 + e 2 E 0 2 t 2 y' (t), 0==  m2 + pxo 2 + e 2 E0 2 t 2 z' (t) } If the particle starts from the origin, In [64J := initial = {x[O] == O,y[O] == 0, z[O] == O}; then the subsequent path follows from In [65J := path = DSolve[{eq1,initial}//Flatten, {x[t], y[t], z [t]}, t] / /Flatten; path / /ColumnForm pxO Log ( 2 e EO t + 2  m2 + px0 2 + e 2 E0 2 t 2 ) - pxO Log ( 2  m2 + pxo 2 ) Out[65J= x(t) -> eEO  m2 + px0 2 + e 2 E0 2 t 2 _  m2 + px0 2 y(t) -> eEO z(t)->O To plot the motion assume the values In [66J : = values = {m -+ 1, e -+ 1, EO -+ 0.1, pxO -+ 0 .1}; The plots for x [t] and y [t] are In[67J:= Plot [{x[t], y[t]}/ .path/ / .values/ / Evaluate, {t,O,5}, GridLines -+ Automatic, PlotStyle -+ {'l'hickness [0.01] , Dashing[{0.06, 0.1}] }, Axes Label -+ {nt n, ny or x n } ] ; 
596 Chapter 10 Relativity and Cosmology y or x 1. / o. o. o. o. / t where the solid curve is the x-coordinate and the y-coordinate is the dashed curve. The nonrelativistic limit follows from expanding x [t] andy [t] in a time series, keep- ing the leading-order term, and then assuming m 2 > P;o' It follows from path that the relativistic and nonrelativistic equations for {x, y} are In[68]:= relXY = {x[t], y[t]}/ .path; In [69] := nonrelXY = (Map [Series [#, {t, 0, 2}] &:, relXY] /. {pxOA2 -+ O}//powerExpand// Simplify / /Normal) Out[69]= { PXO t , eEO t 2 } m 2m The motion in the x-direction moves with uniform speed and the motion in the y- direction moves with constant acceleration or as t 2 . To compare the relativistic and non- relativistic motions let us plot the relativistic and nonrelativistic coordinates on the same graph. The plot for the x-coordinate is In[70]:= Plot [ {relXY[ [1]], nonrelXY[ [l]]}/ .values/ / Evaluate, {t,O,30}, GridLines -+ Automatic, PlotStyle -+ {Thickness [0.01] , Dashing[{0.06, O.l}] }, AxesLa.bel-+ {Rt R , nX R } ]; x 2. ./ ./ 1. o. 
10.3 General Relativity 597 where the dashed curve is the nonrelativistic x-coordinate and the solid curve is the rela- tivistic path. There is no force in the x-direction so the nonrelativistic motion is sttaight, but the y factor causes the relativistic path to curve down. The y component is being accelerated by an electric field along the y-direction. The graph for the y-coordinate is In[71J:= Plot[ {relXY[ [2]], nonrelXY[ [2]]}/ . values/ / Evaluate, {t, 0, 30}, GridLines -+ Automatic, Plot Style -+ { 'l'hickness [0.01] , Dashing[{0.06, O.l} ] }, Axes Label -+ {nt n , nyn} ]; y 4 / 3 / 2 30 t 1 The dashed curve is for the nonrelativistic motion and the solid curve describes the rela- tivistic motion. The y factor causes the relativistic and nonrelativistic paths to differ. . 10.3 . GENERAL RELATIVITY 10.3.1 . Overview The theory of general relativity was formulated by Einstein in 1916 and is based on the principle that the local gravitational force can be replaced by an accelerating reference frame. The local indistinguishability between gravity and acceleration is a consequence of the equivalence of inertial and gravitational masses. The equivalence principle is the basis of general relativity. In conttast to special relativity, general relativity abandons the pseudo-Euclidean metric and replaces it by a general four-dimensional metric gj1v' where g j1V is a function of the coordinates :xJ1. Einstein's field equations are then used to relate the metric gj1V to the matter-energy density in space. In general relativity gravity is no longer considered to be a physical force ttansmitted through space and time but is a manifestation of the curvature of spacetime. The curvature of spacetime is defined by kffj1v = r pV ,j1 - r pj1 , v + I1j1 r%v - rv r%j1 
598 Chapter 10 Relativity and Cosmology where IPr is the Christoffel symbol; this symbol is related to the metric and its derivative by ra _ 1 a0 (g ) py - 'ig yo,p + gpo,y - gPY,o The Riemann curvature tensor RpJ1v measures the change in a four-vector as it is par- allel ttansported around a closed path. It follows that if space is flat then RpJ1V = 0 and a parallel ttansported vector will return to its original value. The metric for a flat spacetime corresponds to geometty described by special relativity and does not contain the effects of a gravitational field. Several important tensors can be formed from the Riemann tensor. We can lower the index of the mixed curvature tensor Rho to get the covariant tensor Rapyo = gaJ1R/Jyo. The Ricci tensor RJ1v' a second rank tensor, follows from summing over two curvature indices, RJ1v = RYJ1YV' We also have the mixed Ricci tensor RJ1 v = fta Ray and the Ricci scalar R = J!p. Following Einstein, a possible choice for the empty space field equations is RJ1V = 0 An equivalent form of the vacuum equations is Gap = Rap - !gapR = 0 where Gap is called the Einstein tensor. The generalized field equations that include matter are 8JTG GJ1V = 7TJ1v where GJ1V is the Einstein tensor and v is the sttess energy density. Geodesics play the same role in curved spacetime as sttaight lines do in flat spacetime. A geodesic path satisfies the equations d2 + r a d dx Y = 0 ds 2 py ds ds where rpy is the Christoffel symbol. An alternate form of the geodesic equation is  ( d ) _! a(gap)d d = 0 ds gJ1/3 ds 2 aJtl ds ds The path is timelike if the four-velocity tangent to the geodesic vr = dJ: satisfies vavr = + 1 and null if the four-velocity satisfies va vr = O. Null geodesics represent the motion of light and world lines of particles follow timelike paths. Spacetlmes often possess special symmetries. Such symmetries are useful in picking the "best" coordinate systems and for finding conserved constants associated with the geodesic equations. For example, if a metric gap is spherically symmetric, then it is formally in- variant under rotations. This means that rotational coordinate ttansformations leave the 
10.3 General Relativity 599 metric form-invariant, gp[x'] = gap[x'], where x' are the rotated coordinates and gp[x'] is the ttansformed metric expressed in terms of the rotated coordinates. If the metric is rotationally invariant, then the ttansformed metric gp[x'] is the same function of its argu- ments as the original metric gap[x'] is of its argument x'. A ttansformation leaving gap[x] form-invariant is called an isometty. We restrict our attention to symmetries that can be consttucted from infinitesimal ttansformations. The finite ttansformation follows from an infinite sequence of infinitesimal ttansformations. Consider the infinitesimal ttansformation x'J1 = :xf + sgJ1[x] where s is small. Let us find the requirements for gJ1 [x] to generate an isometty. The metric and ttansformed metric are related by the tensor ttansformation equations, gap[x] = ; X; gv[x']. If the metric is form invariant, then gap[x] = ; X; gJ1v[x']. Considering the infinitesimal ttansformation given above and evaluating this equation to lowest-order in s, you find that _ aggo-[x] J1 agV[x] ag J1 [x] o - g [x] + ax" gPV[x] + ax? gJ1<T[x] These equations are called the Killing equations and any solution gJ1[x] is called a Killing vector. If a metric admits a Killing solution gJ1[x], then the metric has an infinitesimal isometty. With some algebra, these equations can be written in the form gJ1;V +gV',J1 = 0 where gJ1;V is the covariant derivative of gJ1 defined by gJ1;V =  - I;vga' When a spacetime has a symmetty it can be used to simplify the geodesic equation. If V J1 is the tangent to a geodesic and gJ1 is a Killing vector, then the scalar product gJ1YJ1g" gives a constant of motion. The symmetries of the geometty guarantee a conservation law or first integral for the geodesic. Obviously, a ttemendous amount of algebra is involved in doing calculations in general relativity. It is almost a requirement that some computer algebra program be used to do the calculations. In this section of problems we have consttucted several user-defined proce- dures for doing common repetitious calculations. They are usually listed in the Remarks and Overview included at the beginning of the problems. . PROBLEM 1 Killing Vectors and Spherical Symmetry. In [72] := Clear [ftGlobal ' * ft]; Consider the following metric In[73]:= gj.lY = DiagOnalMatrix[ { gOO (r) I gll (r) I _r 2 I -r2 Sin 2 (9) }]; gj.lY / /MatrixForm gOO(r) 0..'£731= [ : o gl1(r) o o o o _r 2 o o -,,' ,:n' (e) ] 
600 Chapter 1 0 Relativity and Cosmology This metric has a symmetty if there is a vector 1;p that is a solution of the Killing equa- tions 1;a:f3 + 1;p;a = 0, where the semicolon ; means covariant derivative. To find all the Killing vectors for the metric is in general a hard task. However, we can simplify the calculation by stating the Killing vectors and then showing that they satisfy the Killing equations. a. This metric has four Killing vectors: three vectors are associated with rotational symmetty and a fourth Killing vector is associated with the invariance under time ttanslations. Consider the following four conttavariant vectors kf': kt J1 = {I, 0, 0, O} kx" = {O,O, -Sin[4>], -Cos[4>]Cot[8]} !if = {O, 0, Cos[4>], Sin[4>]Cot[8]} k?f = {O, 0, 0, -I} and verify that these four vectors satisfy the Killing equations for the metric gJ.lV. Use the user-define procedure listed below under Remarks and Outline that returns the nontrivial Killing equations. b. IfV J1 = {t' [8], r' [8], ()' [8],4>' [8]} is the four-vector tangent to a geodesic, then a constant of motion follows from gJ1yVJ1kY, where k Y is a Killing vector and gJ1Y is the metric. Find the constants of motion using the four Killing vectors. Express t' [8] , ()' [8] , and 4>' [8] in terms of the four constants of motion. Remarks and Outline You need two procedures to do this problem, one to calculate the killing vectors and another to calculate the Christoffel symbol. The user-defined function that returns the nontrivial Killing equations 1;a:f3 + 1;p;a = 0 is In[74]:= killingZq[Contrav_, g_, r_, x...:{t,r,EI,4>}] := Module [{tempI, temp2, temp3, temp4}, tempI = g. Contrav; temp2 = Outer[D, tempI, x] - templ.r; temp3 = temp2 + Transpose [temp2] ; temp4 = (temp3 II Flatten) == Oll'l'hread II Simplify; Complement [ Select [temp4, FreeQ [#, True&:] ] ] ] ; The Killing equations are computed when the conttavariant vector (ContraV), metric (g), Christoffel symbol (f), and variables (x) are entered into the procedure call killingEq. If no equations are returned, then the vector is a Killing vector. The procedure was written in a manner that required the calculation of the Christoffel symbol Ifi.r = 19 a °(gyo,p + g/M,y - gpy,o) 
10.3 General Relativity 601 The user-defined function for the Christoffel symbol is In[75]:= christ [met_, var_ :{t,r,9,4>}] := Module[{templ, imet, result}, tempi = OUter[D, met, var] ; imet = :Inverse [met] II Si.q>lify; result = 1/2 (Transpose [imet . tempi, {1, 3, 2}] + Transpose [imet.templ, {1,2,3}] - imet. Transpose [tempi, {3, 2, 1}] ); Return[result]]; If you input the metric and variables, then christ returns a list of all 4 x 4 x 4 = 64 components for the symbol. The individual components follow from rpy = r[[a,,8, y]], where the variables are labeled by t  1 , r 2 , ()  3, and ifJ 4. To understand these procedures, you should execute the steps one at a time until you understand each. Solution a. Define the four conttavariant vectors kf': In [76] := kt = {1, 0, 0, O}; kz = {O, 0, 0, -1}; Ice = {O, 0, - Sin[4>], - Cos [4>] Cot [9]}; Ity = {O, 0, Cos [4>], - sin[4>] Cot [9]}; The Christoffel symbol for the metric gJ.lV is In [77] := r = christ[gy]; Applying the user-defined function killingEq to all four conttavariant vectors at once, you get In[78]:= (killingEq[#, gy, r]&:/@{kt, kz, 1ce,1ty} IISimplify) Out[78]= {{L {}, {}, {}} There are no nontrivial equations, so the four conttavariant vectors kt, kz, kx, and ky are all Killing vectors. b. The constants of motion follow from the scalar product gJ1yVJ1F, where k Y is the Killing vector, gJ1Y is the metric, and the tangent four-velocity VJ1 is In [79]:= velocity = {t' [s], r' [s], 9' [s], 4>' [s] }; Form the scalar product gJ1yVJ1F for each of the Killing vectors and equate them to the constants, {en,jx,jy,jz}: 
602 Chapter 1 0 Relativity and Cosmology In[80J:= kconst = { en == gy.velocity.kt, jx == gy.velocity.kx, jy == gy.velocity.ky, jz == gy.velocity.kz}; kconst//ColumnFo Out[80J= en == gOO (r) t' (s) jx == sin(ct» e' (s) r 2 + Cos (e) Cos (ct» sin(e) ct>' (s) r 2 jy == r 2 Cos (e) Sin(e) Sin(ct» ct>' (s) - r 2 Cos (ct» e' (s) jz == r 2 Sin 2 (e) ct>' (s) The first constant corresponds to the conservation of energy and the next three constants correspond to the three components of the conserved angular momentum. We can solve these equations for t' [s], if/ [s] and ()' [s]. The expressions for t' [s] and 4>' [s] follow from the first and fourth equations In[81J:= Solve [kconst [[ { 1, 4}]], {t' [s] ,1/1' [s]}] / / Flatten//ColumnFo Out[81J= t'(s)  gOO (r) ct>'(s)  jzCs2(e) r The equation for ()' [s] is In [82J : = Solve [kconst [ [{ 2, 3}]], EI' [s], 1/1' [s] ] / / Flatten//Simplify Out[82J= {e'(s)  jx Sin(ct» ;2jyCOS(ct» } . PROBLEM 2 Schwarzschild Solution. In [83 J : = Clear ["Global' * "] ; Just months after Einstein published his theory of gravity, Karl Schwarzschild (1916) found an exact solution that corresponded to the gravity field outside a nonrotating spherical mass source. It is by far the most important vacuum solution in general relativity. The derivation simplifies if you make use of the static and spherical nature of the source. We first inttoduce coordinates that are appropriate to the problem, i.e., spherical coordinates {t, r ,0, 4> }. We also assume the metric is rotationally invariant and independent of time. It follows from problem one that the metric that satisfies these consttaints is In[84J:= gy = DiagOnalMatrix[ { gOO (r), gll (r), _r2, _r 2 Sin 2 (EI) }] ; The problem is to find the values for gOO and gll that correspond to a spherical star of mass M. 
10.3 General Relativity 603 a. Set the components of Einstein's tensor to zero, G/l V = 0, and solve for the metric components. Assume the boundary condition that follows from the weak field limit. The weak field limit relates Newtonian gravity to the metric component gOO-> 1+, where <I> is the Newtonian gravitational potential. Use the user-defined proce- c dures defined in the Remarks and Outline below to compute the Einstein tensor. b. The critical radius at r =?S# is called the Schwarzschild radius and is a measure of c the importance of the effects of general relativity. Evaluate the ratio for the radius of the Moon, Earth, Sun, white dwarf and neutton star with the Schwarz schild radius. Remarks and Outline To calculate the Einstein tensor we need the expression for the Christoffel symbol and curvature tensor. The Christoffel symbol was defined in the previ- ous problem: In[85]:= christ[met_,var_ :{t,r,e,tI>}] .- MOdu1e[{temp1,imet}, temp1 = Outer [D, met, var] ; imet = Inverse [met] / / Sill\P1ify; 1/2 (Transpose [imet .temp1, {1, 3, 2}] + Transpose [imet.temp1, {1,2,3}] - imet. Transpose [temp1, {3, 2, 1}] ) ] ; If we know the Christoffel symbol then the curvature tensor Kfi/lV = rpV,/l - rp/l,V + r/lI1v - rVr/l follows from In[86]:= CUrvR[christ_,var_:{t,r,e,tI>}].- Module [ {temp1 } , temp1 = Outer [D, christ, var] ; (Transpose[Outer[D,christ,var], {1, 2, 4, 3}]- Transpose[Outer[D,christ,var], {1,2,3,4}]+ Transpose [Inner [Times, christ, christ, Plus, 2], {1, 3, 4, 2}]- Transpose [Inner [Times, christ, christ, Plus, 2], {1,4,3,2}]) If the Christoffel symbol and coordinates are entered into curvR, then a list of 4 x 4 x 4 x 4 = 256 components are returned. The individual components follow from CurvR [ . . .] [ [1, 2 , 3 , 4] ], where the variables are labeled by t -71, r-72 , () -73, and <p -74. Not all these components are independent due to the algebraic symmetries of the curvature tensor. 
604 Chapter 10 Relativity and Cosmology Finally, the Einstein tensor Gap = Rap - !gapR follows from the user-defined procedure In[87]:= einstein[curv_,met_] := Module [{d_, tEID\Pl, tEID\P2, i, j, s}, d_ = Length [met] ; tEID\Pl = Simplify [ l!:x;pandAll [ Table [SUm [curv [ [s, i, s, j]], {s,d_}], {i,d_}, {j,d_}]]]; tEID\P2 = Simplify [ l!:x;pandAll [ SUm [J:nverse [met] [[j, i]] curv[ [s, i, s, j]], {s, d_}, {i, d_}, {j, d_}]]]; Simplify [ l!:x;pandAll [ Table[tEID\Pl[[i,j]]- (1/2) met [ [i, j] ]tEID\P2, {i, d_}, {j, d_}]]]] The Einstein tensor is calculated when the curvature RhO and the metric are entered into einstein. The Einstein tensor Gap is a symmetric tensor. Solution a. The metric components gOO [r] and gll [r] follow from solving the vacuumequa- tions G /lY = O. To find the Einstein tensor you first compute the Christoffel symbol ffi", for the metric gJ..lV In[88]:= r = christ [gj.lV, {t,r,8,tf>}]; where the spherical coordinates are {t,r,8, iP}. To view the individual components, enter f[ [a,b,c]] where a, b, and c take on the values {l, 2, 3, 4}. You now compute the a curvature tensor Rfryo: In[89] : = R = CUrvR[r, {t, r, 8, tf>}] / / Simplify; Given the metric and curvature components you can use the user-defined function ein- stein to calculate the Einstein tensor G/l Y : In[90]:= Gj.lV = einstein[R, gj.lV] 1 In general, GJ..lV has 16 components but with our simplifying assumptions on the form of the metric only the diagonal components are nonzero. The vacuum equations follow from setting the components of G /lY to zero. The nontrivial equations that follow from G /lY = 0 are 
10.3 General Relativity 605 In[91]:= {eqGtt, eqGrr, eqGee, eqG/f>if>} = MapAt [Flatten, Gj.lV == 0, 1] II Thread I I Select [#1, FreeQ [I, True] &:] &: I I Simplify; where Select was used to pick out the nontrivial equations. These four equations cor- respond to the diagonal components of G /lY and are called {eqGt t, eqGrr, eqG88, eqG(/J<jJ} . Only the first two equations, eqGtt and eqGrr, are needed to determine the two un- known functions gOO and gll. The two relevant vacuum equations are In [92] := vacuumeq = ( { eqGtt, eqGrr} I I Solve [I, {gll' [r], gOO' [r] }] &:1 I Flatten) I . Rule .... Equal; vacuumeq IIColumnForm Out[92]= r ( - gOO(r) _ gOOjr) ) gll (r)2 r ' gll (r) r gll' (r) == gOO (r) , ! gll (r) 1 J gOO (r) == r gOO (r) l -  - r 2 Applying DSolve to vacuumeq, the solutions for gll [r] and gOO [r] follow In[93]:= sol = DSolve [vacuumeq, {gll [r], gOO [r]}, r] I ISimplifyl IFlatten eCl r (e Cl r - 1) c 2 } Out[93]= { gll(r).... C ,gOO(r).... l-e"r r The values for C [1] and C [2] follow from the weak field condition gOO [r] - > 1- 2Gf r as r goes to infinity. It is obvious that the constants that give this value c are In[94]:= bdcond. = {C[l] .... Log [ 2 ]' C[2] .... 2; } { [ C2 ) 2GM } Out[94]= Cl....Log 2GM 'c 2 ....7 where the velocity of light is c, G is the gravitational constant, and II is the mass. The Schwarzschild metric is In[95]:= (gj.lvi .soll .bdcond/.G.... tEIDIP c 2 r I I . i G S:uapl fy) I .tEIDIP.... rc 2 
606 Chapter 10 Relativity and Cosmology 2GM 1-- 0 0 0 c 2 r 1 Out[95]= 0 2GM _ 1 0 0 c 2 r 0 0 _r 2 0 0 0 0 _r 2 Sin 2 (8) Far from the origin the gravitational effects vanish and the metric reduces to the familiar Minkowski metric expressed in spherical coordinates. b. The critical radius at rs = 2 m = 2Gf1 is called the Schwarz schild radius. The value c of the Schwarzschild radius is usually very small compared to the size of a moon, planet, or star. Let us evaluate the ratio of rs to the radius of the Moon, Earth, Sun, white dwarf star, and neutton star. The values of the {mass, radius} for the Moon, Earth, Sun, white dwarf, and neutton star are given by the list of lists, In[96]:= data = {{ 7.35 * 10 25 g, 1. 738 * 10 8 am}, {5.977 *10 27 g,6.378 *10 8 am}, {No, 6.9598 * 10 10 am}, {MO, 1.738 * 10 10 am}, {No, 10 6 am HI. No.... 1.989 * 10 33 g ; Displaying the data in table form, it follows In[97]:= names = {Moon, Earth, SUn, "white dwarf" , neutron star}; TableForm[data, TableReadings .... {names, {Mass, Radius}}]/.am....l0- 5 km Out[97]= Moon Earth Sun whi te dwarf neutron star Mass 7.35 X 10 25 g 5.977 X 10 27 g 1. 989 x 10 33 g 1. 989 X 10 33 g 1. 989 x 10 33 g Radius 1738. kIn 6378. kIn 695980. kIn 173800. kIn 10 kIn The relevant constants needed for a numerical evaluation are In[98]:= constants = {c.... 3. * 10 10 am/sec, c 2 am } G.... 7 .425 * 10- 29 ---g- ; If you define the simple user-defined procedure [ . 2GM In 99]:= Rat1o[{IL,r_}] := -y-11.constants c r 
10.3 General Relativity 607 and then apply it to data, it follows that the ratios 7' where rs = 2Gm/ c 2 , are In[lOOJ:= Transpose [{names, Ratio [#]fc/@data }] / / TableForm Out[lOOJ= Moon Earth Sun white dwarf neutron star 6.28006 X 10. 11 1.39163 x 10- 9 4.24389 x 10. 6 0.0000169946 0.295367 The ratios 7 are very small and the effects of general relativity can usually be ignored except for neutton stars and possibly for white dwarfs. . PROBLEM 3 Geodesics for the Schwarzschild Metric. The paths for geodesics fol- low from the equation !!-. ( g d:xf3 ) _ ! a(g afi) dXX d:xf3 = 0 ds J1I3 ds 2 ax" ds ds Use the user-defined procedure geodesic given below under Remarks and Outline to find the four geodesic equations. a. Restrict the motion to the plane () [s] = lr/2, write the explicit geodesic equations for the Schwarzschild metric, and show " [ ] 2mr'[s]t'[s] t s = 2mr[s] - r[s]2 ( -1+ 2m )[ _ mr'[s]2 2 +mt'[S]2_ r [S]3if>,[S]2 ] r[s] ( 2m ) r"[s] = 1 -  r[s]2 if>"[s] = 2r'[s]if>'[s] r[s] wherem = . c b. Integrate the t ' , [s] and if>" [s] equations and reduce the equations to the forms En t'[s] =  1- -.!!! r -4h 2 m 2 + 4h 2 mr[s] - h 2 r[s]2 + mr[s]3(En 2 - r'[sf) r"[s] = (2m - r[s])r[s]4 h if>'[s] - - ,2 
608 Chapter 1 a Relativity and Cosmology c. Find the expression for r'[S]2 that follows from evaluating the time1ike condition 1 = gj1YvPvY. Show that r'[S]2 can be written in the form ,2 2 2h 2 m h 2 2m r [s] = (En - 1) + - - - + - r[s]3 r[sf r[s] In[ 101] : = Clear [nGlobal' * n]; Remarks and Outline The procedure to calculate  ( g d:xf3 ) _  o(gafi) dx!' d:xf3 = 0 ds J1f3 ds 2 oxl1 ds ds is In[102]:= geodesic [met_, var_, parameter_ :s] .- Module[{metl,templ,vell,varl}, vell = D [Through [var [parameter] ] , parameter]; varl = Through [var [parameter] ] ; metl = met/. Thread [var .... Through [var[parameter] ]]; temp1 = (D[met1.vel1,parameter]- (1/2 D[met1, #] .vell.vellrc/@.var1} == {O, 0, 0, O}}IIThread] If the metric and coordinates are entered into the operator geodesic, then four geodesic equations are calculated. Solution a. The form of the Schwarzschild metric is In[103]:= gj.lY = DiagOnalMatrix[ { gOO (r), gl1 (r), _r2, _r 2 Sin 2 (e) }] [ gOO (r) 0 0 0 ) Out[103]= 0 gll (r) 0 0 o 0 - 0 o 0 0 _r 2 Sin 2 (8) where the metric components are defined by the rule In[104]:= camp = { gOO.... ( 1- 2m rc ) , gll.... ( - rc )} ; #1 1 - H and m= G; . Applying the user-defined operator geodesic to gj1Y' you get four equations for the general metric. 
1 0.3 General Relativity 609 In[105]:= eql = geodesic [gj.lY , {t, r,e, ifI}]11 Sill\Plify ; The equations simplify if you solve for {t' , [S], r" [s] , 8" [s ], if>" [s n, evaluate the metric components, and restrict the motion to the 8 =  plane: In[106]:= eq2 = (Solve [eql, {t" [s], r" [s], e" [s], ifI" [s]}] II Flatten) 1 .COD\P/. e.... (71"12&) 1 . Rule .... Equal II Simplify; eq2 II ColumnForm Out[106]= 2 mr' ( s ) t' ( s) t" (s) == 2mr(s) -r(s)2 (  - 1) [ - <P' (s) 2 r ( s ) 3 - r(s) 2 r" (s) == rnr'(S)\ +mt'(s)2) (1.) True <p" (s) = = 2 r' (s) <P' (s) r(s) We restricted the motion to a plane using the rule 8  (nl2&:). These are the desired equations listed in part a of the problem. b. The equations for t' , [s] and if>" [s] can be integrated once. It follows from the following "trick" that t' [s] is In[107]:= eq3= DSolve[eq2[[1]] ,r[s],s][[l,l]] I. Rule.... Equal 2 e 2rnc1 m t' (s) Out[107]= r(s) == e2rnc1 t' (s) -1 Solving this equation for t' [s] and choosing an appropriate expression for the con- stant, it follows that In[lOB]:= trule = Solve [eq3, t' [s]] [[1,1]] I. 1 C[l].... - 2m Log[En]IIFlatten Enr(s) Out[lOB]= t'(s).... r(s) - 2m This is one of the equations listed in part b of this problem. We can also apply this same trick to the equation for if>" [s] : In[109]:= iflrule = (DSolve [eq2 [[4]] , r[s], s] [[1,1]] I. Rule.... Equal I 1 Solve [I, ifI' [s]] [ [1, 1] ] & ) I. C [1] .... Vb. 
610 Chapter 1 a Relativity and Cosmology [ , h Out 109]= <jJ (s) ....  r(s) which is the second equation in part b. The equation for r' , [8] reduces to the desired form if we eliminate 4/ [8] and t' [8] in the radial geodesic equation given by eq2 [ [2] ] , In[110]:= eq4 = eq2 [[2]] / .trule/ .tf>rule/ /Simplify Out[110]= r"(s) == m (En 2 - r' (s) 2) r (s) 3 - h 2 r (s) 2 + 4 h 2 m r (s) - 4 h 2 m 2 (2m-r(s)) r(s)4 c. To get an expression for r'[S]2, evaluate the timelike criteria 1 = g/lY vPvY , where g/lY is the Schwarzschild metric and v Y is the four-velocity vector defined by In[111]:= vel = {t'[s],r'[s],O,tf>'[s]}; Restrict the variables to the () = 1f/2 plane and then change the metric variables to be functions of the parameter 8 In[112]:= met = (gj.lv/.cOlllp/.e.... /.r....r[s]/. e....e[s]) ; The timelike condition becomes In[113]:= eq5 = 1 == vel.met.vel r'(s)2 ( 2m J Out[113]= 1==-+ 1-- t'(S)2_ r (s)2<jJ'(S)2 1- r(S) r(s) You can eliminate the derivatives t' [8] and 4/ [8] with the rules derived in part b: In [ 114] : = eq6 = eq5/ . trule / . tf>rule / / Simpli fy (En 2 _r'(s)2) r(s)3-h 2 r(s) +2h 2 m Out[114]= ==1 r(s)2 (r(s) -2m) Solving for r'[s]2 you get In [115]:= r' [s] 2/. Solve [eq6, r' [s]] [[1]] / / Simplify 2m h 2 2h 2 m Out[115]= En 2 +---+--1 r(s) r(s)2 r(s)3 
10.3 General Relativity 611 . PROBLEM 4 Time It Takes to Fall into a Black Hole. Radial geodesics are one of the simpler types of paths to calculate, because their four-velocity has only two nonzero terms { t' [s] , r' [s] , 0 , 0 }. Consider the radial timelike geodesics for the Schwarzschild metric. In Problem 3 it was shown that the geodesic equations satisfy the following two expressions: En t'[s] = - 1- 2m r 2h 2 m h 2 2m r'[sf = (En 2 - 1) + - - - + - r[s]3 r[s] 2 r[s] Radial geodesics follow from setting h=O in the second equation. a. Assume the initial conditions r' [0] =0 and r [0] =rO and derive an equation for r' [s] that corresponds to an infalling particle. The proper time as a function of the radial position follows from integrating l/r' [s] over r. Integrate the equation to get an expression between s and r. How long does it take to fall from rO to the origin as measured by the proper time? b. An expression for the coordinate time follows from forming the ratio r' [t] = r' [s] It' [s] and integrating l/r' [t] over r. Integrate the expression. c. Plot r as a function of both the proper and coordinate times. Solution In [116J : = Clear ["Global' * "] ; a. Consider the equation for the radial variable, In[117J:= eql= '222m h 2 2h 2 m r (s) ==En +---+--1; res) r(s)2 r(s)3 Set h=O and solve for r' [s] In[118J:= eq2 = Solve [eql, r' [s]] /.h -+ 0/. Rule -+ Equal / . -.IX- >+ .y Simplify [x] / / Flatten Out[118J= { r' (s) == - I En 2 +  -1, r' (s) == I En 2 +  -1 } \j r(s) \j r(s) The inward moving path corresponds to the solution with the negative sign in front of the radical, so define In [119J := eq3 = eq2 [[1]] 
612 Chapter 10 Relativity and Cosmology Out[119]= r' (s) == _ ) En 2 + -1 r(s) The constant En can be expressed in terms of the initial velocity r' [0] =0 and initial position r[O] =rO if you evaluate eq3 at 8=0: In[120]:= eq4 = 0 == eq3 [[2]] I.s.... OI.r[O] .... rO Out[120]= O==_ ) En 2 + 2m _1 rO Solving eq3 and eq4 for r' [8] and En, you get In[121]:= rprimeru1e = Solve[{eq3,eq4}, {r'[s],En}] [[2]] II simp1ifyilExpandA11 Out[121]= {r' (s) ....-  _ 2m , En .... ) 1 _ 2m } r(s) rO rO Only the solution that corresponded to inward motion was kept. The radial equation is In[122]:= radia1eq = rprimeru1e [[1]] I.  >+ "' Factor [x] I I p01f8rExpand ...,fi.ym y rO-r(s) Out[122]=r'(s).... .= -y rO .yr(Sf An equation for the proper time as a function of the radial position follows from inte- grating l/r' [8] over r. In[123]:= Stime = Integrate [ +1.rprimeru1e, r [s] {r[s],rO,r}, Assumptions.... { rO > r > O} ] I I Apart Sin- 1 ( .fb r r o ) r03/2 VLU If r0 3 / 2 .yr -)1 - !i> rO Out[123]= - + + ...,fi.ym 2...,fi.ym ...,fi.ym Notice the time to fall to the origin (r=O) is GM In[124]:= Stime/.r.... Ol.m.... 211PowerExpand c elf r0 3 / 2 Out[124]= ."'.rr..h. 2-y2-yG-yM b. Let us now parameterize the position of the falling test particle by its coordinate time, i.e., the time read by a clock a long distance away from the black hole. The expression for r' [t] follows from the ratio , where the expression for t' [8] is 
10.3 General Relativity 613 En In [125] := trule = t' [s] -+; 1 - r(if The ratio  follows from In [126] := eq5 = ( r' (s) . ,----- I . trulel . rpr1merulel . t (s) r[s] -+ r[t]) I. x_ n - :-+ Factor [Together [x]] n I I PowerExpand I I Expand I I SiJDplify -12 -vm (2 m - r ( t) ) Y rO - r ( t) Out[126]= yrO - 2 m r (t) 3/2 The coordinate time as a function of the radial position follows from integrating 1/ eq5 over r. This integration simplifies if you change variables, In[127]:= change = {r(t) -+rOcos 2 (x), r' (x) -+ -2 rO Cos (x) sin (x) }; and then integrate over x where the integral becomes (XI d dr d dt dx. The integrand is J xo x r In[128] := eq6 = (  r' [x] I . Change ) I I sill1Plify I I eq5 PowerExpand Out[128]= -12 r0 2  Cos 4 (x) -vm (2 m - rO Cos 2 (x) ) Integrating eq6 from xO =0 to xf = arccos [], the expression for the coordinate time becomes In [129] := Ttime = ( Integrate [ eq6 , {x, 0, Cos- 1 (  ) } ] I. (2 m - rO -+ -t8ll1Pl }I IPowerExpand ) I. t8ll1Pl -+ rO - 2 m I I Sill1Plify 
614 Chapter 10 Relativity and Cosmology Out[129]= 1 2 -V'i -.[ffi [ [ -V'i-.[ffi  ) 8 -V'i Tanh. 1 \J  - ro m 3 / 2 + ....rr yrO - 2 m yrO - 2 m [2 (4 m +rO) Cos. 1 [ $0 ] + rO Sin [2 Cos. 1 [ $0 ) ] ) ] C. Plot the coordinate and proper times for the values: In[130]:= value = {m-+ 1, rO -+ 8}; The graphics for the coordinate and proper time curves are In[13i] := pt1 = Plot [Evaluate [(Ttime/ .value)], {r, 2, 8}, Displayl'unction -+ Identity]; pt2 = Plot [Evaluate [stime/ .value], {r, 0, 8}, Displayl'unction -+ Identity]; Define the text and markings for the graphics, In[132]:= text = {Line [{{2, O}, {2,40}}], Text [ styleForm [RProper Time n , FontFamily- > nTimes - Bold R , Fontsize -+ 10 ], {1. 2, 22} ] , Text [ styleForm[nCoordinate Time n , FontFamily- > nTimes - Bold n , Fontsize-+ 10], {4.5,30}], Text [ styleForm[Rr = 2m n , FontFamily- > RTimes - Bold n , FontSize -+ 10 ], {2. 6, 10}] } / / Graphics; If you combine the paths and add labels, then the graph for the coordinate and proper times follow from In[133]:= Show[{pt1, pt2, text}, AxesLabel -+ {nDistance n , nTime n }, DisplayFunction -+ $DisplayFunction, PlotRange -+ {O, 40}]; 
10.3 General Relativity 615 Time 40 35 30 2 2 oper 15 10 =2m 5 2 . PROBLEM 5 Circular Geodesics for the Schwarzschild Metric. Consider the time- like circular geodesics for the Schwarz schild metric. Assume the geodesics are in the plane e [s] = 1[/2 and the radius is a constant r [s] =rO. Start from the expressions for the geodesic given in Problem 3: En t' [ s ] = - 1- 2m ' r I ] h tP [s = ,1 ' -4h 2 m 2 + 4h 2 mr[s] - h 2 r[s]2 + mr[s]3(En 2 - r'[S]2) = , (2m - r[sDr[s]4 and 2h 2 m h 2 2m r'[S]2 = (En 2 - 1) + - - - + - r[sp r[s]2 r[s] You get circular orbits by replacing r [s] with the constant rO. Express the constants En and h in terms of rO and derive expressions for t [s] and tP [s] . Find the orbit periods as expressed in terms of the proper and coordinate times. Solution In [1341:= Clear [oGlobal' * 0]; The expressions for t' [s] and tP' [s] are I En In[1351:= teq=t (s) == --y-/.r[s] -+rO 1- r(:) 3 ' En Out[l 51= t (5) == 1- E:!! rO In[1361:= 4>eq= 4>'(s) == /.r[s] -+rO res) h Out[1361= (1/ (5) == r0 2 
616 Chapter 10 Relativity and Cosmology where we set r equal to a constant using the rule r [s] rO. The expressions for En and h follow from the equations for r' , [s] , In[1371 := ace = r" [s] (m (En 2 _ r' (S)2) r(s)3 _h 2 r(s)2+ 4h 2 m(r(s) -m»)1 (2m-r(S» r(S)4)/or -+ (rO&) En 2 m r0 3 - h 2 r0 2 + 4 h 2 m (rO - m) 0-- -- (2m-rO)r0 4 Out[1371= and for r'[S]2, In[1381:= vel = ,22 2m h 2 2h 2 m r (s) == En + - -  +  - 1 10 r(s) r(s) r(s) r -+ (rO&) 2m h 2 2h 2 m Out[1381= 0==En 2 +---+--1 rO r0 2 r0 3 where we set r equal to a constant using the rule r (rO&) . You can solve these two equations for En and h: In[1391:= eq2 = (Solve [(ace, vel}, (En, h} ] II simplify II PowerExpand) 10 {  -+ - -vroi_ 3J Out[1391= {{ En->- rO-2m h->- ...;mrO }  yrO-3m ' yrO-3m ' { rO - 2 m ...;m rO } En->-.=.,h-> , vrOvrO-3m yrO-3m { rO - 2 m ...;m rO } En-7 __,h-7-_ ' v rO V rO - 3 m v rO - 3 m { rO - 2m ...;mrO }} En-> ,h->  yrO - 3 m yrO - 3 m There are four solutions. We are interested only in the one where both En and h are posi- tive. In[1401:= Enhrule = eq2 [[4]] { rO - 2 m ...;m rO } Out[1401= En-> .=.,h->. v rO v rO - 3 m v rO - 3 m 
10.3 General Relativity 617 Apply DBol ve to t' [s] and <p' [s] to get expressions for t [s] and <p [s] In[141J:= aol = DSolve [{ teq, I/Ieq, t [0] == 0,1/1 [0] == O}, {t [a], 1/1 [a]}, a] I .EDhrulel I Flattenllsimplify { t(S) -7  ,cf;(S) -7  } rO - 3 m rO rO - 3 m Out[141J= The proper period follows from solving <p [s] =27T for s: In[142J:= a/. Solve [ (1/1 [a] I.aol) == 21£, a] [[1,1]] 2 li rO yrO - 3 m Out[142J= .ym The coordinate period follows from evaluating t [s] when <p [s] =27T: In [143 J : = period/. Solve [ {period== t[a],I/I[a] == 21£}/.aol, period, a] [[1,1]] 2 li r0 3 / 2 Out[143J= .ym . PROBLEM 6 Precession of the Perihelion. One of the most accurate tests of general relativity is the precession of the perihelion. The precession reflects the fact that bound or- bits are precessing ellipses. Consider the timelike geodesics for the Schwarz schild metric. Assume the orbit is in the e =  plane and consider the bound orbits. Make use of the expressions derived in Problem 3 for the conservation of angular momentum <p'[s] =  and the equation that followed from the timelike condition 1 = g/lYvI'v Y , 2h 2 m h 2 2m r'[s]2 = (En 2 - 1) + - - - + - r[s]3 r[s]2 r[s] a. Show the orbit equation can be expressed as m u"[<p] == 2" - u[<p] + 3mu[<p]2 h where u=  and the parameter s is replaced with <p. b. Assume a small perturbation about a circular orbit and show that the orbit can be expressed as a precessing ellipse where the perihelion shift is act!-:2) c. Make a numerical table of the precession values for Mercury, Venus, and Earth. Solution In [144J : = Clear [RGlobal' * R] ; a. The timelike condition gives the following expression for r'[S]2, 
618 Chapter 10 Relativity and Cosmology In[145]:= eql = , 22 2m h 2 2h 2 m r (s) == En + - - - + - - 1; r(s) r(s)2 r(s)3 Change the r parameterization from s to <jJ in eql. The change follows from noticing that dr[s] ds d<jJ[s] dr[<jJ[s]] = ds d<jJ[s] and d<jJ[s] _ h - ,2 ' This change is implemented with the rule { hr' (4)) } In[146]:=change= r'(s)....,r(s)....r(4»; r (4)) Replacing the parameter s with <jJ in eql, you find that In[147]:= eq2 = eql/.change h 2 r' (cf;)2 2m h 2 2h 2 m Out[147]= ==En 2 +---+--1 r(cf;)4 r(cf;) r(cf;)2 r(cf;)3 Further simplification occurs if the radial coordinate is changed to r= l/u. In[148]:= eq3 = eq2/. {r.... (l/u[#]&)} Out[148]= h 2 u'(cf;)2 ==2h 2 mu(cf;)3-h 2 u(cf;)2+2mu(cf;) +En 2 -1 Take the derivative of eq3 to convert this first-order differential equation to an equation for u' , [<jJ] In[149]:= uEq = (D[eq3, 4>] / / Solve [I, u" [4>] ] [[1, 1]]&) /. Rule.... Equal/ /ExpandAll m Out[149]= u"(cf;) == 3mu(cf;)2 -u(cf;) + 2" h b. Let us find the first-order perturbative solution of uEq. Assume the solution is of the form In[150]:= pertu= {u- > (uO+du[#]&)}; where uO corresponds to the circular orbit and du is a small perturbation about uO. Ex- pressing uEq in terms of du, you get In[151]:= uEq/.pertu//ExpandAll Out[151]= du" (cf;) == 3mu0 2 +6mdu(cf;)uO-uO+3mdu(cf;)2+  -du(cf;) h 
10.3 General Relativity 619 Since du is considered to be small we can drop the term du[iPf: In [152] := eq4 = (uEq/.pertuIIExpandAll) I. du[4>]-2.... 0 "2 m Out[152]= du (cf;) ==3muO +6mdu(cf;)uO-uO+ 2 -du(cf;) h We can eliminate the value of h by using the fact that the condition for the circular orbit follows from setting du and its derivative to zero: In[153]:= eq5=eq4/.du n [4>] ....OI.du[4>] ....011 simplify m Out[153]= 2+uO(3muO-l) ==0 h eq5 gives a relation between h and uO. If we use eq5 to eliminate h in eq4, then you get an equation for du expressed in terms uO. It follows that In[154]:= eq6 = Solve [{eq5, eq4}, dun [4>]] [ [1, 1]] I. {6 muO- > 1- y2}1 .Rule- > Equal I I ExpandAllllsimplify Out[154]= du" (cf;) == _y2 du(cf;) where we simplified the notation by defining y: In[155]:= yrule= y.... .y 1-6muO; Notice the value of y is less than one. The solution for this "oscillator equation" is In [156] := dusol = DSolve [{eq6 , du [0] == euO, du' [0] == O}, du [4>],4>] [[1, 1]] Out[156]= du(cf;) ....euO Cos(ycf;) where du [0] = e uO and the value of e is an arbittary small constant. The first-order solution for the orbit follows from uO+du: In [157] : = uSol = uO + du [4>] I.dusol Out[157]= e Cos(ycf;) uO+uO To agree with the parameterization of an ellipse, we identify uO with In[158]:= uOrule = uO.... 1 ; a (1_e 2 ) where a denotes the semi-major axis of the orbit and e is the eccentricity of the ellipse. The equation for the radial variable of the precessing ellipse becomes 
620 Chapter 10 Relativity and Cosmology In[1591:= r== (l/usol )/.uOrule II simplify Out[1591= a - a e 2 r == eCos(ycf;) +1 The factor y determines the rate of precession. The orbit does not return to the same point after <p goes from 0 to 2 1f but the next perihelion occurs at y cfJp=2 1f. Since y is less than one it follows that cfJp is greater than 21f. The advance of the angle beyond 21f is called the perihelion shift and is given by In[1601:= ec(1 = 21£1'1 - 21£; Evaluating y and keeping lowest-order terms in m, you get the advance after one orbit Out[1611= «ec(1 1 .yrulel .uOrule) + o [mr21 1 GM Normal) 1 .m.... c 2 6GMlr a c 2 (1 - e 2 ) In[1611 := We have replaced m with G . Denote the perihelion advance with /1, c 6GM7r In [1621: = '" = 2 2 ; ac (1 - e ) which is in units of radians per orbit. c. Let us evaluate the shift for the orbit of Mercury. The values of II and G are In[1631:= const = {M ....1.989 * 10 33 gm, c 2 em } G->7.42426*10-29 ; where II is the mass of the Sun, G is the gravitational constant, and c is the speed of light. The orbit parameters for Mercury are In[1641:= mercury = { a.... 0.3871AU, AU- > 1.49599 * 10 13 em, e- > 0.205614}; where AU is an asttonomical unit. We want the answer in arcsec so we define the con- version from radians to arcsec. In[1651:= radTosec = 360 * 60 * 60 1(2 1£) ; We also want the shift for a time period of 100 Earth years. To make this conversion you need to know how many orbits Mercury makes in 100 years, 100 In[1661:= MIlumber = 0.24085 ; 
10.4 Cosmology 621 where Mercury's orbital period is 0.24085 years. The perihelion shift for Mercury is In[1671:= (radTosec) {Mnumber)/.const//.mercury// NUmberFor.m[#,4]& Out[1671= 42.98 in units of arcsec per 100 years. What are the perihelion shifts for Venus and Earth? The orbit parameters for Venus are In[1681:= venus = {a....l0e.2 *10 11 cm,e....0.007}; and the number of orbits Venus makes in 100 years is 100 In[1691:= vnumber = - 0.62 The advance follows from In[1701:=  (radTosec) {vnumber)/.const//.venus// NUmberForm[#,2]& Out[1701= 8.6 For Earth, you find In[1711:= earth = {a....149.6 * 10 11 cm,e....0.017}; In[1721:=  (radTosec ) (100) / .const/ / . earth/ / NUmberForm[#,2]& Out[1721= 3.8 The observed values for Venus and Earth are 8.4 :!: 4.8 and 5.0:t 1.2, respectively. The experimental error increases rapidly as the distance from the Sun increases because the precession per revolution and the revolutions per century both decrease. . 10.4 . COSMOLOGY 10.4.1 . Overview of Friedmann, Robertson, and Walker Cosmology Cosmology is the study of the large-scale SITucture of the universe-what it is like now, what it was in the past, and what it will be in the future. Einstein's theory of general relativ- ity is the language used by cosmologists to describe the evolving universe. To understand every facet of the universe is too hard, so assumptions are made so that the finer details do not overshadow the relevant aspects of the large-scale sITucture of the universe. In particu- lar, the standard cosmological models are based on the Cosmological principle. The Cos- mological principle states that, on the average, the universe looks the same in all directions and from any point. This leads to the requirement that space is homogeneous and isottopic about each point. The universe is certainly not homogeneous on small scale where there 
622 Chapter 10 Relativity and Cosmology are irregularities like stars, galaxies, and clusters of galaxies; however, on scales of a few hundred million parsecs (Mpc) the homogeneity of space may be a good approximation. We begin this discussion of cosmology with the assumptions that space is homoge- neous and isottopic. These assumptions offer a useful simplification and, hopefully, a good approximation to the real universe. Homogeneous and isottopic models of spacetime fol- low from the work of Friedmann, Robertson, and Walker. In 1922, the Russian physicist and mathematician, Alexander Friedmann (1888-1925) consttucted three models that were consistent with general relativity, expanding space, and the Cosmological principle. In the 1930s Robertson and Walker extended Friedmann's work. These models are referred to as Friedmann-Robertson-Walker (FRW) spacetimes. The line element for such a universe can be written in the form ds 2 == dt 2 - R[t]2 ( 1 ,2 + ,2dff2 + ,2 sin[Ofdip2) where R[t] is a function to be determined by the Einstein equations. This metric is called the Friedmann-Robertson-Walker metric. The three types of models are distinguished by their curvature, which is parameterized by k, called the signature. The signature k has values + 1,0, and -1. These three models are called spherical (closed), Euclidean (flat), and hyperbolic (open), respectively. To formulate the geometty we assume that spacetime is filled with a fluid in which the galaxies are the fundamental points of the fluid. The cosmic fluid is at rest in the comoving coordinates so its conttavariant four-velocity is VJl = {l, 0, 0, O}. Assume there is an ob- server with an ideal clock on each galaxy that moves with the mean flow of the matter. The observer's clock measures the coordinate t, which plays the role of a cosmic time. Each spacelike slice at t = constant is homogeneous. There are no privileged points or directions about any point in the constant t slice. The behavior of R[t] follows from solving Einstein's equations G' y = + 87rGTJl y + Ag" y where G is the gravitational constant and A is the cosmological constant. The conservation of energy-momentum requires TJl y",/1 = 0, where the symbol ; stands for the covariant derivative: Tap = 8Tafi + fa Tlip + r{ Tali ;y 8x Y liy liy We must now model the source term TJl yon the right-hand side of the field equations. The majority of cosmological models assume that matter can be described as a perfect fluid. The sttess energy tensor for a perfect fluid is characterized by density and pressure, both of which are only functions of time. The sttess energy tensor for a perfect fluid is TJl y = (p + p)VJlV y - pg" y 
10.4 Cosmology 623 where p and p are the mass density and pressure, respectively. The field equations reduce to R"[t] = !A.R(t) - 4G7rp(t)R(t) - G7rp(t)R(t) 3 c 2 3 1 8 R'[tf = -kc 2 + 3A(R(t))2 + 3G7r(R(t))2 p (t) These are the two starting equations for most cosmological models. To get an explicit model you need a relation between the pressure and density, i.e., an equation of state. . PROBLEM 1 Field Equations for Friedmann-Robertson-Walker Cosmology. Con- sider the Friedmann-Robertson-Walker metric defined by the diagonal metric [ 10 R[tf 0-- g= l-kr2 o 0 o 0 o o -r2R[tf o -r'Rj ,;n[O]' ] Assume the model is described by the conttavariant energy-momentum tensor TJiv = _PgJiV + (P + p)VJiVV, where VV = {l, 0, 0, OJ. a. Use the user-defined procedures given below under Remarks and Outline to calculate the Christoffel symbol fp", the curvature tensor Rp"o, and the Einstein tensor GJiv' From the Einstein equations with cosmological constant GJiV = 81rGv + AgJiV show that R [t] obeys the following two equations: R[t]'2 =  (- 3k + A.R[t]2 + 8G7rR[tf p[t]) R" [t] 1 R[t] = 3(A - 12G7rP[t] - 4G7rp[t]) b. Assume that pressure and density are related by the equation of state p [ t] = ap [ t] . From the conservation of energy-momentum TJi V;j1 = 0, show that t _ ( Ro ) 3 C1 +a) p[ ] - po R[t] where po and Ro are the current values. c. Let a =0, which corresponds to a pressureless dust, and show that the equations for R'[tf and R"[t] can be written as R"[t] = !A.R[t] _ 4G7rR0 3 po 3 3R[t]2 R'[t]2 = -k + !A.R[tf + 8G7rR 0 3 po 3 3R[t] 
624 Chapter 10 Relativity and Cosmology Remarks and Outline The user-defined function to calculate the Christoffel symbol rpy, r a 1 a" (g ) py = "2 g yO,p + gf36,y - gPY," is In[173]:= christ[Il/.lV_,var_:{t,r,9,.}] := Module[{templ,imet}, templ = OUter[D,Il/.lV, var] ; i_t = Inverse[ll/.lv]//Simplify; 1/2 (Transpose [imet.templ, {l,3, 2}] + Transpose [imet.templ, {l,2,3}] - imet.Transpose[templ, {3,2,l}]} ] ; and the user-defined function to calculate the curvature tensor /th", KpJiY = rp",Ji - rpj1. Y + rJi - f1 y r;Ji follows from In[174]:= cu.rvR[r.,var_ :{t,r,9,.}] .- Module [{templ}, templ = OUter [D, r, var]; (Transpose[OUter[D,r,var], {l, 2, 4, 3}] - Transpose[OUter[D,r,var], {l, 2, 3, 4}] + Transpose[Inner[Times,r,r,plus,2], {l,3,4,2}]- Transpose [Inner [Times, r, r, Plus, 2], {l,4,3,2}]} 
10.4 Cosmology 625 The Einstein tensor G /lY is given by In [175] := einstein[curv_,Il/.lv_] := Module [{dem, tempi, temp2, i, j, s}, dem = Length [Il/.lv] ; tempi = Simplify [ ExpandAll [ Table [SUm [curv [ [s, i, s, j]], {s, dem}], {i, dem}, {j, dem}]]] ; temp2 = Simplify [ ExpandAll [ SUm [J:nverse [Il/.lv] [[j, i]] curv[ [s, i, s, j]], {s, dem}, {i, dem}, {j, dem}]]]; Simplify [ ExpandAll [ Table[templ[[i,j]]- (112) Il/.lV [[i, j]] temp2, {i, dem}, {j, dem}]]]] Solution In[176]:= Clear [oGlobal' *0]; a. The Friedmann-Robertson-Walker metric is In [177] : = Il/.lV = DiallODalMatrix [ { R (t) 2 2 2 1, -, -r R(t) , 1-kr _r 2 R(t)2 Sin 2 (9)}]; To derive Einstein's equations, first calculate the Christoffel symbol IPr and curvature tensor Rpyo. The Christoffel symbols follow from the user-defined function christ and the curvature tensor follows from the user-defined function curvR: In [178] : = r = christ [Il/.lv] ; In[179]:= Ra(3y6 = curvR[r] / /Siq>lify; The Einstein tensor G/l Y follows from the user-defined procedure einstein: In[180]:= G/.lV = einstein[Ra(3y6,Il/.lV]; The only nonzero elements of the Einstein tensor are the diagonal components. To get an expression for the sttess-energy tensor, first define the conttavariant V/l and covariant V/l four-velocities: 
626 Chapter 10 Relativity and Cosmology In[181]:= vel = {1, 0, 0, O}; (*Contravariant four - velocity*) covel = gv. {1, 0, 0, O}; (*Covariant four - velocity*) The expression for the covariant sttess-energy tensor T/l Y = -Pg/l Y + (P + p )V/l V y is In[182]:= T = Table [(p [t] + P [t]) covel [[i]] covel [[j]]- gv[ [i, j]]P[t], {i, 4}, {j, 4}] II Siq>1ify; The four nontrivial Einstein equations with a cosmological constant follow from In[183] := Out[183]= (eq1 = Map [Platten, Gv == 8 7fGT + AgV] II Threadll Select [#1, PreeQ[#, True]&:]&: II Siq>lify) IIColUDIDPorm 3 (R'(t)2 +k) 2 ==A+8G11"p(t) R(t) - (A - 8 G 11" P (t) ) R (t) 2 + 2 R" (t) R (t) + R' (t) 2 + k 2 == 0 kr -1 r 2 (A-8G11"P(t)) R(t)2 ==r 2 (R'(t)2 +k+2R(t) R" (t)) r 2 Sin 2 (e) (- (A-8G11"P(t)) R(t)2+2R"(t) R(t) +R'(t)2+k) ==0 Solving eql for R'[tf andR"[t], you get the desired solutions: Out[184]= (fieldeq = Solve [eq1/.R' [t] -+ Sqrt [x], {R n [t], x}] [[1] ]/.x-+R' [t] -21. Rule -+ EqualllExpandAll) II ColUDIDPorm ,,1 4 R (t) == - AR(t) - 4G11"P(t) R(t) - - G11"p(t) R(t) 3 1 8 3 R' (t) 2 == - A R(t) 2 + - G 11" P (t) R (t) 2 - k 3 3 In[184] := b. Consider the equations that follow from the conservation equation T/l Y:/l = o. The conttavariant sttess energy tensor is In[185] := conT = Table[(p[t] +p[t])vel[[i]] vel[[j]]- Inverse [gv] [[i, j]] P [t], {i, 4}, {j, 4}] P (t) 0 0 0 0 (1-kr2) PIt) 0 0 Out[185]= R(t)2 PIt) 0 0 r 2 R(t)2 0 Csc 2 (e) P (t) 0 0 0 r 2 R(t)2 
10.4 Cosmology 627 Next, create a user-defined function that will return the covariant derivative of a con- ttavariant tensor of rank two, T.,r:j = ar + ToP + ItTao: In [186J : = coder [{2, U, U}, conT_, christ_, var.] ._ outer[D,conT,var]+ Transpose [ :Inner [Times, christ, conT, Plus, 2], {1,3,2}]+ Transpose [:Inner [Times, christ, Transpose [conT, {2, 1}], Plus, 2], {2, 3, 1}] When coder is applied to a conttavariant tensor of rank two given by TJIA =conT, it returns its covariant derivative T!;/. The Christoffel symbol is given by christ and the coordinates are given by var. Applying coder to conT, you get T!;/: In[187J:= eq2 = coder [{2, U, U}, conT, r, {t, r, 9, }] II Slify ; Summing over the last two indices, 1faa, it follows that In [188J : = eq3 = Table [Sum [eq2 [[i, s, s] ], {s, 1, 4}], {i, 1, 4}] Out[188J= { 3 (P(t) +p(t}} R'(t} +p'(t}, 0, 0, O } R(t} The conservation equations follow from setting the four equations in eq3 to zero. The only nontrivial equation follows from the first element in the list: In[189J:= eq4=eq3[[1]] ==0 Out[189J= 3 (P(t) +p(t}}R'(t} +p'(t} ==0 R(t} Consider the equation of state defined with the rule In [190J := eqstate = {P[t] -+ ap[t]}; Using eqstate to eliminate the pressure in eq4 and solving for R [t], you can see that In [191J : = eq5 = DSolve [{eq41 .eqstate, R[to] == RO}, R[t],t] [[1,1]]/. {p[to] -+ po, Rule -+ Equal}IISlify II PowerExpand 1 1 Out[191J= R(t} ==Ropo1<'i+3" p(t} -30-3 
628 Chapter 10 Relativity and Cosmology If you solve eq5 for p [t], you get a rule for the behavior of p [t]: In[192]:= prule = Solve [eq5, p[t]] [[1,1]] IIPowerExpand II Simplify Out[192]= p(t) ->Ro 3 (a+l) pOR(t).3 (a+l) c. Eliminating the pressure and p in the field equations and setting a to zero, you get In[193]:= fieldeql .prulel .eqstate/.a- > O//EXpandAllllColumnForm " 1 4 G:rrRo 3 po Out[193]= R (t) == - AR(t) - 2 3 3 R(t) 8 G:rr po Ro 3 1 R'(t)2== +-AR(t)2_k 3 R(t) 3 . PROBLEM 2 Zero-Pressure (Dust) Cosmological Models. The equations for zero- pressure Friedmann-Robertson-Walker models can be written as R"[ ] ==  [ ] _ 4G7rR0 3 po t 3 A.R t 3R[t] or R' [ ] 2 == - k  W [ ] 3 _ 8G7rR 0 3 po t + 3 I\.ft t 3R[t] The parameters that are more directly related to observations are 1. the Hubble expansion rate, Ho = g:l ; 2. the dimensionless deceleration parameter, qo = - t] ; 3. the dimensionless density parameter, a- = C;;;;f ; 4. the dimensionless cosmological parameter, [ = 3:02 ' where to is the current cosmic time. a. Show that qo and k satisfy the following equations: qo = -[ + a- and k = -HoRo(1 - [- 2a-). b. Derive an analytical expression for the cosmological age as a function of qo when the cosmological parameter is zero. Plot the results. c. Consider models with a nonzero cosmological parameter and make a table of ages for different values of a- and qo. 
10.4 Cosmology 629 Remarks and Outline Relations for {qo, k} follow from evaluating the two field equa- tions at t = 0 and expressing the results in terms of {qo, Bo, (j, r}. The age of the model follows from integrating R}[t] from R =0 (beginning) to R=Ro (now). The integration can be analytically solved for the special case of zero cosmological constant. For the nonzero cosmological constant, use NJ:ntegrate to evaluate the ages. Solution In[194]:= Clear ["Global , *"]; a. The field equations for zero-pressure and nonzero cosmological models are 1 4 G7fR0 3 po In [ 195 ] :=e q l=R" ( t ) -- AR ( t ) . -- 3" - 3R(t)2 ' , 2 8 G7fpOR0 3 1 2 eq2 = R (t) == 3 R(t) + 3" AR(t) - k; Define the Hubble constant Bo, deceleration parameter qo, dimensionless cosmological parameter r, and dimensionless density (j with the rules: In[196]:= parameterrule = {R(tO) -+Ro,R'(to) -+EORO, " 2 3 Eo 2 a R (to) -+ -Eo qoRo,po-+-, 4G7f A -+ 3 Eo 2 r}; Relations for {qO, k} follow from evaluating the field equations at t=to. Evaluate eql and eq2 at t=to and express the results in terms of { qo, Bo, (j , r}. The relations for {qo, k} follow from the command Solve: In [197] : = qrule = Solve [{eql, eq2}/.t -+ tot .parameterrule, {qo, k}] / /Flatten/ /Siq>1ify Out[197]= {qo.-?a-r,k.-?Ho 2 R0 2 (r+2a-l)} b. The ages follow from eq2. Simplify the notation in eq2 by defining X [t] with the rule In [198] : = change = {R' [t] -+ x' [t] Ro, R[t] -+ X[t] Ro}; The variable X [t] is more convenient than R [t] because the present time occurs at X=l. Expressing eq2 in terms of X, you get In[199]:= (eq2/.parameterrule/.qrule/.change// Solve [I, x' [t]] 6i:) 
630 Chapter 10 Relativity and Cosmology Out[199]= {{ 2aHo2 } x' (t) -> - r x (t) 2 Ho 2 - r Ho 2 - 2 a Ho 2 + - + Ho 2 X(t) ,{X'(t) -> 2 aHo 2 }} r x (t) 2 Ho 2 - r Ho 2 - 2 a Ho 2 + - + Ho 2 X(t) Pick the positive solution and factor Bo In[200]:= eq3 = {X' [t] -+ Eo (1-r-2a+ (2a)/X[t] +rX[t]2) (112) } Ou t [ 200] = { X' (t) -> Ho I r x ( t) 2 - r - 2 a + 1 + 2..::... } 'If X(t) The ages follow from integrating x:[t] from x=o (beginning) to X=l (now). If you set Bo=l, then the time is in units of Jo (Hubble time units). The integration can be solved analytically for the special case of zero cosmological constant. Setting [=0 and Bo=l and integrating x'\t] from x=o to X=l, the age in Hubble units follows from eq3: In[201]:= integrand = (1/X' [t] / .eq3/. {r -+ 0, Eo -+ 1, a -+ qo} Out[201]= -J #:m- 2qo +1 1 where we used the fact that £T=qo when [=0. It follows from integrating that In [202] := eq4 = J:ntegrate[ integrand, {X[t], 0, 1} ]// Simplify Out[202]= If [ " OV 2: OVIm (  ) '" 0, 2 - 4 qo 1 - 2 qo 1 - 2 qo 2 Sinh- 1  1 -1 yqo [ qo _#) 2qo-l 1 1 1 dX(t) o -J2.9.£.-2qO+l ] X(t) The age follows from In[203]:= Clear[ageo] 
10.4 Cosmology 631 In [204] : = ageo [qL] : = eq4 [[2]] I .qo -+ ql II Chop; ageo[1/2] = 2/3; ageo[0.5] = 2/3; ageo[O] = 1; geo[O.] = 1; The special ages for qo=1/2 and qo=O are defined separately. Display the results by plotting the age as a function of qo. The labels for the curves are given by In [205] := label = {PointSize[0.03], Point[{0.5,ageo[0.5]}], Text [ StyleForm[nk = 0, Flat n , FontFamily- > nTimes - Bold n , FontSize -+ 10 ], {O. 9, 0.67}] , Text [ StyleForm [nk = 1, Closed n , FontFamily- > nTimes - Bold n , FontSize -+ 10], {1.4, 0.58}], Text [ StyleForm[nk = -1, Open n , FontFamily- > nTimes - Bold n , FontSize -+ 10 ], {0.5, 0.82}]}; Define a plot function to graph the age for different values of the Hubble constant: In [206] := ageplot[Eo_] := Plot [ageo [qo], {qo, 0.00001, 2}, Frame -+ True, PlotLabel -+ nAge for r = on, FrameLabel -+ {nl0- - 29 gm/cc n , n n, "goD,na}, FrameTicks -+ (1/10 Round [ 10 {{O, {112, 0.000196 EO-2}, {1, 2 * 0.000196 Eo-2}, {1. 5,3 * 0.000196 EO-2}}, {{0.5, 0.5 * 9.78 * (100/Ho)}, {0.6, 0.6 * 9.78 * (100/Ho)}, {0.7, 0.7 * 9.78 * (100/Eo)}, {0.8, 0.8 * 9.78 * (100/Eo)}, {0.9,O.9*9.78* (100/Eo)}, {1, 1 * 9.78 * (100/Ho)})} ] I IN), GridLines -+ Automatic, Epilog-+ label]; The labels were included with the option Epilog. The input Bo converts the time scale to units of billions of years. Displaying the results for a particular choice of Bo, you get In[207]:= ageplot[70]; 
632 Chapter 10 Relativity and Cosmology Age for r=o 14. 12.6 11.2 9.8 8.4 7. 1. 1.9 2.9 10 A -29 gm/cc C. Consider the cosmological age for models with nonzero r. The age can no longer be expressed in terms of elementary functions, so you must numerically evaluate the ages for different a- and qo. The age follows from integrating x![t] from x=o to X=l. Use NJ:ntegrate to evaluate the results that follow from eq3: In [20B] := ageL [qL, aL] := NIntegrate[ 1/X' [t] I .eq31 .Eo -+ 1/.r -+ 0'1- ql/. qo -+ ql/.a -+ al/.X[t] -+ x, {x, 0, 1}] The age is a function of the deceleration parameter called ql and the dimensionless density a- called a-l. Instead of just evaluating the age for one set of parameters, form a list of ages for different decelerations and dimensionless densities. Also, convert the age from Hubble units to billions of years. The table of age values for different Hubble constants follows from agetable: In[209]:= agetable[Eo_] .- 1/100 ROUDd[ 100 Table [ 9.78 * (100/Eo) ageL[q, a] , {q, 0, 2, O.S}, {a, 0, 2.5,0 .S}]] I IN; Displaying the result with TableFo:rm and a particular value of Ho, you get In [21 0] : = TableForm [agetable [70] , TableSpacing -+ {1}, TableEeadings -+ {{Oqo = 00, °qo = .5°, °qo = 10, °qo = 1.5°, 0qo = 20}, {Oao = 00, °.5°, 01°, °1.5°, °2°,02.S 0 }}] 
10.4 Cosmology 633 Out [210J = 0"0 = 0 13 .97 12.16 10.97 10.11 9.44 0.5 10.02 9.31 8.76 8.3 7.92 1 8.9 8.39 7.97 7.62 7.32 1.5 8.22 7.81 7.47 7.17 6.91 2 7.74 7.39 7.09 6.83 6.61 2.5 7.36 7.06 6.8 6.56 6.36 go = 0 go = .5 go = 1 go = 1. 5 go = 2 . PROBLEM 3 The Expansion and Age for the Friedmann-Robertson-Walker Models. The standard cosmological models are Friedmann-Robertson-Walker models with zero pressure and zero cosmological parameter. The scale factor obeys the equation R ' [ ] = -k + 2H 0 2 qo R0 3 t R[t] where HoRo =  -1:2qo for k not zero. a. Find the solution for R [t] and age for the model when k=O. Graph the results. b. Find the solution for R [t] and age for the model when k=l. Graph the results. c. Find the solution for R [t] and age for the model when k= -1. Graph the results. Remarks and Outline The solution for R[t] follows from applying DSolve to the scale factor equation. For k=l or -1, the solution is long. It is more ttansparent to change the variables and define the solution in parametric form. The graphics follow from Plot for the case k=O and from parametricPlot for the cases k=l and -1. Solution In[211J:= Clear [nGlobal ' * n]; a. The equation for the scale factor R [t] when k=O is 80 2 R0 3 In[212J:= eq1 = R' (t)2 == -; R(t) A solution for t follows directly from integrating 1 /R' [t] over R: In [213J := eq2 = t == Integrate [Sqrt [1/ eq1 [[2]] ], R [t]] / / PowerExpand 2R(t)3/2 Out [213J = t-- -- 3 Ho R03/2 The age for the model follows from setting R [t] =R [ 0] in eq2: In[214J:= eq2 [[2]] / .R[t] -+ Ro 2 Out[214J= - 3 Ho 
634 Chapter 10 Relativity and Cosmology The expression for R [t] follows from solving eq2 for R [t]: In[215]:= scaleO = solve[eq2,R[t]] [[2,1]]/. Rule -+ Equal ( 3 ) 2/3 Out[215]= R(t) =="2 H02/3 Ro t 2/3 Use Plot to graph R [t] : In[216]:= Plot [ Evaluate [scaleO [[2] ] /. {Ho -+ 1, Ro -+ 1}], {t, 0, 1}, I!'rame -+ 'l'rue, I!'rame'l'icks -+ {{{O, non}, {1/3, n1/(3HO)n}, {2/3, nNaw n}, {1, n1/Bo"}}, {O, {1/2, nRO/2 "}, {1, "RO"}}}, Epilog -+ Graphics[{pointSize[0.03], Point [{2/3, 1}] }] [[1]]]; Ro/2 Ro Ro/2 b. Consider the closed model with k=l (qo>1/2). The equation for the scale factor R [t] is In [2171 := eq3 = R' [t] 2 == -1 + 2 qoHo2 Ro3/(R[t]); The value of Ro expressed in terms of qo for k= 1, is In[218]:= Rorule = Ro -+ l/Bo Sqrt [1/(2 qo -1)]; Eliminating Ro in eq3, you get In[219]:= eq4 = eq3/.Roru1e//PowerExpand ,2 2 go Out[219]= R (t) == Ho (2go-1)3/2R(t) -1 A solution for t follows directly from eq4 by integrating l/R' [t] over R [t]. How- ever, do not solve eq4 this way; the solution is simpler if you express R [t] in parametric form. Define R in terms of the parameter x with the rule 
10.4 Cosmology 635 In [220] := change = R-+ «2 qol (80 (2qo - 1) A (3/2» Sin[x[#]]A2)&:); The parametric representation for R [x] is In [221] := scalel = R[x]/.change/.x[x] -+xll PowerExpand 2 qo Sin 2 (x) Out[221]= Ho (2 qo - 1) 3/2 An equation for x' [t] follows from using change to eliminate R in eq4: In [222] := eq5 = Solve [eq41 . change, x' [t]] [[2]] I I simplifyllPowerExpand { , Ho (2 qo -1) 312 Csc 2 (x(t)) } Out[222]= x (t) -> 4 qo The expression t [x] follows from integrating l/x' [t] over x[t]: In [223] := timel = :Integrate [(l/x' [t] I .eq5), {x[t],O,x}] 4 qo (  -1 Sin (2 x) ) Out[223]= 312 Ho(2qo-1) The model starts at x=O (t=O) and completes the cycle at the Big Crunch when x=n (R=O). To find the age, first find the value of x when scalel=Ro: In[224]:= xage = Solve [RO == scalel, x] [ [2]] I . Rorule I I ExpandAll I I PowerExpand Out[224]= {x->Sin.1 [ r j } 2 ..;qo where the positive solution was kept. When x=xage, you get the current values of R [x] and t [x] . The age for the model follows from evaluating timel at xage: In [225] := agel = timel/.xagellExpandAll II Simplify Out[225]= - qo (Sin (2 Sin. 1 ()) - 2 Sin. 1 ()) HO(2qo-1)3/2 
636 Chapter 1 a Relativity and Cosmology Plot R [t] for the particular values of qo and Ho given by In[226]:= value = {qo-+l,Ho-+l}; The plot for R follows from applying parametricPlot to {t [x] , R [x] }. Add to these graphics a point for the current value of {t [x] , R [x]} and a point at maximum expansion. The graphics for these points along with the text are given by label: In[227]:= label = {pointSize [0 .03], Text [ Stylel!'orm [ 1/100 Round [100 (timel/.xage/.value ) ]// N , I!'ontl!'amily- > "Times - Bold", l!'ontSize -+ 10 ], {2. 6, l}], Text [ Stylel!'orm ["age/Bo = " , I!'ontl!'amily- > "Times - Bold", l!'ontSize -+ 10], {1.4, l}], Point [{timel/.x -+ 7r/2/ .value, scalel/.x -+ 7r/2/ .value}], Point [{timel/.xage/.value, scalel/.xage/.value}]}; Applying parametricPlot to {timel, scalel}, you get the plot for the closed model: In[228]:= parametricPlot[ Evaluate[{timel,scalel}/.value], {x, 0, 7r}, I!'rame -+ True, PlotLabel-+ "Closed Model, qo = 1", I!'rameTicks -+ {{{O, "OR}, {agel/.value//N, "age"}, {3 agel/.value//N,"3 * age"}, {timel/ .value/.x -+ 7r/2, "Max"}, {9 agel/ .value/ /N, "9 * age"}}, {O, 1/2, {l, "Ron}, 1.5, 2}}, Epilog -+ label] ; Closed Model, qo=l a age 3* age Max 9* age 2 2 Ro Ro 1 2 1.5 1.5 a age Max 9* age 
10.4 Cosmology 637 The time has been expressed in units of the current age, and the current age is expressed in units of the Hubble age. c. Consider the open model with k=-l (qo<1/2). The equation for the scale factor R[t] is In [229] := eq6 = R' [t] -2 == 1 + 2qoBo-2RO-3/(R[t]); For k=-l, the value ofRo expressed in terms of qo and Ho is In [230] := Rorule = Ro -+ l/Bo sqrt [1/(1- 2 qo)]; Eliminating R [0] in eq6, you get In[231] : = eq7 = eq6/ . Rorule/ /powerExpand ,2 2 go Out[231]= R (t) == 3/2 + 1 Ho (1- 2 go) R(t) Solve eq7 in the same way that you solved for R [t] in part b. Express R in terms of the parameter x: In[232]:= change = R-+ «2 qo/ (Eo (1 - 2 qo) - (3/2» Sinh[x[#]]-2)&); The parametric representation for R [x] is In[233]:= 8cale2 = R[X] I.change/.x[x] -+ xii powerExpand 2 go Sinh 2 (x) Out[233]= Ho (1 - 2 go) 3/2 Next, change variables in eq7 and get an equation for x' [t]: In[234]:= eq8 = Solve [eq7/.change, x' [t]] [[2]] II SimplifyllpowerExpand { , HO(1-2g0)3/2CSCh2(X(t)) } Out[234]= x (t) -> 4 go The expression for t [x] follows from integrating 1 Ix I [t] over x [t] : In[235]:= time2 = Integrate [(1/x' [t] l.eq8), (x[t],O,x)] 4 go ( t Sinh (2 x) -  ) Ho (1 - 2 go) 3/2 Out[235]= ..>-- 
638 Chapter 10 Relativity and Cosmology The parametric expression for t is given by time2 and the parametric expression for R follows from scale2. The model starts at x=O (t=O), evolves to the present R [x] =Ro, and then keeps expanding. To find the age, first find the value of x when scale2=Ro: In [236] := xage = Solve [Ro == scale2, x] [[2]] I . Rorulel I PowerExpandl I Simplify Out[236]= {X-7Sinh.l[  )} where the positive solution was kept. The age for the model follows from In [237] := age2 = time2/.xage _ 4 qo [, sinh [2 sinh' [  )] - ! Sinh' [  ) ] Out[237]- 3/2 Ho (1 - 2 go) Plot R [t] for the particular values of qo and Ho given by In[238]:= value = {qo-+0.02,Ho-+l}; The plot for R follows from applying parametricPlot to {t [x] , R [x] }. Add to these graphics a point for the current value of {t [x] , R [x] }. The graphics for this point along with the text are given by label: In [239] := label = {pointSize [0 .03], 'l'ext[ Stylel!'orm[Aage/Bo = A I!'ontl!'amily- > D'l'imes - BoldA, l!'ontSize -+ 10 ] , {1.5 time21 .xagel .value, scale2/.xage/.value}], 'l'ext [ Stylel!'orm [ 1/100 Round [100 (tiDle2/.xage/.value ) ]11 N , I!'ontl!'amily- > A'l'imes - BoldA, l!'ontSize -+10], {1.9 time21 .xagel .value, scale2/.xage/.value}], Point [{time2/.xage/.value, scale2/.xage/.value}]}; Applying parametricPlot to {time2, scale2}, you get the plot for the open model: 
10.5 Exercises 639 In[240]:= parametricPlot[ Evaluate [{time2, Bcale2}/.value], {x, 0, 3}, I!'rame -+ True, PlotLabel-+ nOpenModel, qo = .02 n , I!'rameTickB -+ {{{O, non}, {0.5agel/.value//N, nage/2 n }, {agel/.value//N,nage R }, {2agel/.value//N,n2age n }, {3/2 agel/ . value/ /N, n3/2 age n }}, {O, 1/2, {l, nRO n }, 1.5, 2}}, Epilog -+ label] ; Open Model, qo=.02 o age/2 age 3/2 age 2age 2 1.5 1.5 Ro RO 1 2 o o age/2 age 3/2 age 2age The time has been expressed in units of the current age, which is expressed in units of the Hubble age. . 10.5 . EXERCISES The solutions to many of these exercises can be found on our web sites. 10.1 Lorentz Boosts (a) Show that two successive Lorentz boosts in the same direction are equivalent to a single Lorentz boost. Find the fonnula for the addition of velocities that follows from the product of two Lorentz boosts. (b) The electromagnetic three-vector fields E and B are elements of a second-rank contravari- ant tensor Fij. In frame, the second-rank tensor is defined as F'I = [ ;, -Ex -Ey a -Bz Ey Bz a Ez -By Bz -Ez J By -Bx a In a boosted reference frame, the three-vector fields are E' and B'. Find the relation be- tween the electric and magnetic fields in frames E and E'. 
640 Chapter 10 Relativity and Cosmology 10.2 Radioactive Decay of Moving Nucleus Consider a radioactive nucleus moving relative to the laboratory with a constant speed v. The nucleus decays and emits an electron with a speed v in a direction perpendicular to the motion as detennined by an observer at rest with respect to the nucleus. Find the velocity and the direction of motion for the electron as measured by an observer in the laboratory frame. 10.3 Schwarzschild Solution Consider spherical coordinates {t, r,9, ifJ} and assume the metric is diagonal with components given by {goo[r], gll[r], -,-2, -,-2 sin[lP}. Set the components ofthe Ricci tensor RJl1' to zero and solve for the metric components. Assume the boundary condition goo[r]- > 1 -  as r goes to infinity. 10.4 Potential Analysis for Timelike Geodesics Consider the Schwarzschild metric and illustrate the different kinds of time like geodesics by doing a potential analysis. There are sufficient symmetries that you do not have to use the geodesic equations. Assume the orbits are confined to the plane 9 = 1T/2. (a) If the effective potential V is defined by the equation r'[S]2 = (En 2 - 1) - V, show that V = -  +  - . The first tenn is the relativistic correction, the second is the centrifugal barrier, and the third is the gravity potential. (b) Show that the potential has two extrema if eZ 2 > 12m 2 . Graph the three parts of the effective potential for eZ 2 > 12m 2 . Also graph the effective potential for the three cases, eZ 2 > 12m 2 , eZ 2 = 12m 2 , and el 2 < 12m 2 . 10.5 Schwarzschild Solution in Null Coordinates Consider a spherically symmetric metric expressed in null coordinates {jl, r, 9, ifJ}. The metric is nondiagonal and is of the fonn g" = [ go)r] -1 a a -1 a a a a a -,-2 a -L] Find the solution of Einstein's vacuum equations with the boundary conditions that goo [r] - > 1 -  as r goes to infinity, 10.6 Null Geodesics for the Schwarzschild Metric Consider null geodesics for the Schwarzschild metric. Assume the orbit is in the 9 =  plane. Find the effective potential and describe the different kinds of paths. Plot the results. 10.7 Mercury's Anomalous Precession and Modification of Newton's Gravity Consider Newtonian motion and assume a small perturbation about a circular orbit. Calculate the perihelion shifts for the two potentials v=-  and v=-  . If the precession of Mercury is +43 sec of arc/century, which potential is co'rrect and wht is the value of 6 needed to ex- plain Mercury's precession? Using the value of 6 established from Mercury's orbit, what is the predicted value of the perihelion shift for Venus and Earth? How does this compare with the observed values for Venus = 8.4::1: 4.8" per century and for Earth = 5.0::1: 1.2" per century? 10.8 Cosmological Force and Mercury The potential for a Newtonian orbit in a gravitational field with a cosmological force is V = OM ,.2,\ ---T' 
10.5 Exercises 641 (a) Show that the orbit equation for u=l/r is u + u" = 11- , where u is a function of l/J and h is the conserved angular momentum. The orbit was assumed to be in the (J =  plane. (b) Show that the perihelion shift caused by the cosmological tenn is h 6 nil a 3 (1 - e 2 )3nil 1::.=  = m m (c) What is the value of il needed to produce a precession for Mercury of one second of arc per century? 
/.,4,9 / / .,9 /;,19 : >,11 ?,15 $DisplayFunction, 49, 56 &,5 ! !,4 Abs, 6, 295 animate, 34, 106 animation, 34, 106, 179,334, 536 Apart, 8 Attributes, 15 BesselJ, 14, 39,559,566 BesselY, 560, 565 boost, 580 boost along the x axis, 589 boostx, 589 canonical momentum, 345, 353, 361 canonical transformations, 365 Cartesian, 107,468,550 center-of-mass frame, 378, 584 christ, 601, 625 Christoffel symbols, 598, 603, 623 CoefficientList,490 Collect, 48 complex conjugate, 10, 589 rule, 10 Conj uga te, 6, 581 conjugate, 10 conjugateRule,10 Con text, 25 Index ContourPlot, 100, 140,202, 234,312,441,448 Contours, 202 Convert, 46 CoordinatesToCartesian, 24,105,372,380,446 covariantequations,580 Curl, 107-109 curvature tensor, 603, 625 curvR, 603, 625 Cylindrical, 110 CylindricalPlot3D, 37, 483, 487,504 Dashing, 31, 562, 593 Densi tyPlot, 296 derivative, 27 differential equation, 29 diffSeriesOne, 137,384 dimensionless cosmological parameter, 628 dimensionless deceleration, 628 dimensionless density, 628 dipole, 102 DisplayFunction 49, 196 Do, 106, 171 Doppler shift, 589 dot product, 381 double pendulum, 175 doublePlot, 131, 147, 156 DSolve, 29, 48, 45,134,145, 151,185,545,557 Duffing equation, 232 eigenfrequency, 166, 175 Eigensystem, 159, 181 Eigenvalues, 159, 181 eigenvalues, 158 eigenvalues and eigenvectors for small oscillating systems, 158 eigenvector, 166, 175 Eigenvectors, 159, 181 einstein, 604, 625 Einstein tensor, 598, 604 electric field, 94, 106,435, 495 electric field lines, 455, 489, 496 electric potential, 94 Eliminate, 12,590 Epilog, 49, 54, 136, 149, 189, 548,631 equilibrium, 130 equipotential,437 equipotentiallines, 102,452,489, 496 Evaluate, 31, 486 Expand, 7 Factor, 6 FilledPlot, 141 FindMinimum, 454 FindRoot, 40,519,526,536, 568 firstDiffSeries, 348 firstOrderPert,348,388 Flatten, 29, 48, 116,526 flux, 532, 540 flux, 532, 540 Fontform,57 Foucault pendulum, 85-93 four-vector, 126,581 Fourier spectrum, 209 of one-dimensional oscillating system, 185 64J 
644 Index Fourier Transform, 185, 187 fractals, 259, 291 Frame, 34, 586 FreeQ, 18 FullForm, 10 Function, 30, 50 Galilean transformation, 578-579 Gauss's Law, 94 GaussianIntegers,7 general relativity, 597 generalized coordinates, 299 generalized Doppler formula, 589 generalized force, 299 generalized momentum, 344 generalized Snell's law, 588 geodesic, 598, 607, 608 geodesic, 607, 608 geodesic equations, 598, 608 Global', 26 Grad, 95, 448, 458 Graphics, 23, 25, 316 Graphics'PlotField',35 Graphics'PlotField3D' ScaleFunction,36 GraphicsArray, 76,528,563 Gridlines, 118 Hamil ton, 344, 367 Hamilton's canonical equations, 344 Hamilton's characteristic functions, 372 Hamilton's equations, 344, 357, 365 Hamilton's principal function, 365 Hamilton-Jacobi, 365-367 Hamilton-Jacobi equations, 366 hamil tonian, 308, 361 Hamiltonian, 398 Hamil tonJacobi, 366, 372 harmonic oscillator, 131, 150, 191, 346,367,545 Hermite polynomials, 545 Hermite solution, 546 Hermi teH, 39, 546, 552 holonomic, 299 Hubble expansion rate, 628 Hue, 33 HypergeometriclFl,546, 552 HypergeometricU,573 Identity,49 Im,6 Integrate, 28, 95, 473 integrate, 28 InterpolatingFunction, 30,240 InverseLaplaceTransform, 137 Join, 84 Julia set, 291, 292, 294 Killing equation, 599 killingEq,600 laboratory frame, 583, 588 Lag, 335 Lagrange multipliers, 299, 355 Lagrange's equations, 299,335 Lagrangian, 298, 323 LaguerreL,39,573 Laplace transforms, 135 Laplace's equation, 435, 467, 488 LaplaceTransform, 134, 149, 187 Laplacian, 457, 468 Legendre polynomials, 439, 488, 499,508 Legendre solution, 508 LegendreP, 39, 465, 554, 557 Limi t, 54, 115 limit, 84 Listplot, 22,32,48,171,261 LogicalExpand,496 LogicExpand,496 Lorentz transformations, 579, 589 magnetic vector potential, 107 Mandelbrot set, 291, 292 Map, 48, 276, 469 metric, 580 Mod, 19 Module, 20, 41, 138, 180 Monopole, 438, 441, 452 monopole, 103 Mul tipoleP, 459, 460 Mul tipoleSH, 459 NDSolve, 30, 87, 211, 241, 314, 400 Needs, 24 Newton's second law, 44, 67, 78, 94 Newtonian motion, 45 non-inertial frame of reference, 77 nonholonomic,299,335,355 nonlinear pendulum, 195 normal modes, 157 NSol ve, 21 numOrbi t, 395 Options, 57 oscillations, 130, 157, 183 oscMovie,242 Outer, 75, 181,624 Packages, 23 parabolic coordinates, 376 ParametricPlot, 67, 69, 132, 163,213,633 ParametricPlot3D, 82, 84, 111, 132, 451 perturbative solution, 421 phase diagram, 140, 196,234 phase plane, 140 phase plot, 132 for one-dimensional system, 132 and time evolution for a one-dimensional system, 132 phase trajectories, 195,241,321, 331 phasePlot, 131, 132, 156 Plot, 32,48, 80,93, 163,235, 518 Plot3D, 151,235,489,534,542 Plot Gradient Field, 100 plotGradientField3D,101, 436 PlotRange, 155 PlotStyle,32 PlotVectorfield, 35,148, 211,217,243 
Index PlotVectorField3D,112 Point, 56,80,115 PointSize,22 PolarPlot, 384, 386, 393 potential diagrams, 130, 140, 234, 311,348 Power Expand, 9, 6, 95,454,489 Protect, 134 pseudo-Euclidean metric, 580, 597 pure forms, 29 pure functions, 17, 29 Quantum mechanics, 513 Random, 11,41 Re, 6, 570 Reduce, 12, 14, 161, 196,516 reflection, 542 Ricci scalar, 598 Ricci tensor, 598 Riemann metrics, 598 Robertson-Walker metric, 621 Roots, 12 rotating coordinate system, 77 Rule->Equal,68 scalar potential,45 ScaleFunction, 36, 104, 459 schrod, 516 SchrOdinger's equation, 514 Schwarzschild metric, 602, 607, 615 Select, 18, 122, 605 Series, 54, 70, 452 series expansion for second-order equation, 70 series expansion solution for second-order equation, 137 SetCoordinates,469, 550 shadowing, 26 ShadowPlot3D, 140 Show, 57,83 Sign, 64 Simplify, 6 small oscillations, 157 smallOsc, 158, 159, 162, 166, 172, 179 Snell's law, 175-179,588 Solve, 12,46,587 Spherical,492 spherical harmonics, 439 SphericalHarmonicY, 38, 558 SphericalPlot3D,38 stress-energy tensor, 622 Sum, 137 superposition of point charges, 440 645 Table, 41, 70,115,181,517,560 TableForm, 73, 117,561,569, 606,632 TableHeadings, 517, 527, 560 TableSpacing, 569, 606, 632 Text, 57, 59,98, 524,614 Thickness, 82 Thread, 23, 25, 81, 88, 492 three coupled harmonic oscillators, 165, 171 timePhasePlot, 131, 151, 156 Timing, 20, 131 Together, 6 transmission, 538 Transpose, 603, 624 TrigFactor,8 TrigTop, 438-440, 446 TrigToY, 438 two postulates for special relativity, 578 Union, 262 user-defined metric, boost, and velocity parameters, 599 van der Pole equation, 255 van der Pole oscillator, 255 vChange, 557 VectorQ,381 VEPlot, 436, 444, 451, 456, 465, 496 ViewPlot, 104 
Mathematica@ FOR PHYSICS Mathematica@ for Physics, Second Edition is tailored for advanced undergraduate and graduate students taking core courses in the physics curriculum. In this book, authors Robert 1. Zimmerman and Fredrick Olness show students how to use Mathematica@ to solve standard problems in physics. They cover the canonical problems from the core courses, allowing students to practice with the solutions they provide and modify these solutions to solve additional problems. This gives students the opportunity to focus on the physics and leave the algebraic manipulations to Mathematica@. In this way, the authors take the reader beyond the "textbook" solutions. They challenge students to cross-check their results using the wide variety of Mathematica@'s analytical, numerical, and graphical tools. Highlights Mathematica@ for Physics, Second Edition provides Mathematica@ solu- tions for canonical problems in the physics curriculum. The book uses Mathematica@ to help students develop their visualization skills in problem solving. The graphical capability of Mathematica@ is used to help students develop their intuition for the physics behind a given problem. Two new chapters on Nonlinear Oscillating Systems and Discrete Dynamical Systems have been added to bring the book right up to date. A large number of new exercises have been added to broaden the range of problem sets. Please visit us at www.aw.com/physics for more information. To order any of our products, contact our customer service department at (800) 824-7799, (201) 767-5021 outside of the U.S., or visit your campus bookstore. ISBN 0-8053-8700-5 Pearson Education -----