The Maxima Book
Total Page:16
File Type:pdf, Size:1020Kb
The Maxima Book Paulo Ney de Souza Richard J. Fateman Joel Moses Cliff Yapp 19th September 2004 1 Credits Paulo Ney de Souza Jay Belanger Richard Fateman Joel Moses Cliff Yapp Contents Preface 5 I The Maxima Program and Standard Packages 6 1 Introduction 7 1.1 What is Maxima? ............................................. 7 1.2 A Brief History of Macsyma ....................................... 8 2 Available Interfaces to Maxima 10 2.1 The Terminal Interface .......................................... 10 2.2 The Emacs Interface ........................................... 11 2.2.1 Installing the Maxima Emacs Mode ............................... 11 2.2.2 Maxima-mode .......................................... 12 2.2.3 Enhanced Terminal Mode .................................... 14 2.2.4 Emaxima Mode .......................................... 14 2.3 Xmaxima ................................................. 26 2.4 TEXmacs ................................................. 27 2.5 Other Interfaces .............................................. 27 3 The Basics - What you need to know to operate in Maxima 29 3.1 The Very Beginning ............................................ 29 3.1.1 Our first Maxima Session .................................... 29 3.1.2 To Evaluate or Not to Evaluate .................................. 33 3.1.3 The Concept of Environment - The ev Command ........................ 33 3.1.4 Clearing values from the system - the kill command ...................... 38 3.2 Common Operators in Maxima ...................................... 38 3.2.1 Assignment Operators ...................................... 38 4 Trig through Calculus 42 4.1 Trigonometric Functions ......................................... 42 4.2 Differentiation ............................................... 43 4.3 Integration ................................................. 45 4.3.1 The assume Command ...................................... 46 4.3.2 Definite Integrals ......................................... 47 4.3.3 changevar ............................................ 48 4.3.4 Behind the Black Box - Using Specific Approaches ....................... 48 4.3.5 Other Examples .......................................... 48 2 CONTENTS 3 5 Advanced Mathematics - ODEs and Beyond 50 5.1 Ordinary Differential Equations ..................................... 50 5.1.1 Defining Ordinary Differential Equations ............................ 50 5.1.2 Solving Ordinary Differential Equations: ode2 ......................... 51 5.1.3 Solving Ordinary Differential Equations: desolve ....................... 57 6 Matrix Operations and Vectors 60 7 Introduction to Maxima’s Programming Language 61 7.1 Some Examples .............................................. 61 7.2 Unconventional Conditionals ....................................... 62 7.3 Assumptions ............................................... 62 7.4 Arbitrary Numbers of Parameters ..................................... 63 7.5 Arrays ................................................... 63 7.6 Iteration .................................................. 64 7.7 Serious Business ............................................. 64 7.8 Hardcopy ................................................. 65 7.9 Return to Arrays and Functions ...................................... 65 7.10 More Useful Examples .......................................... 65 7.11 Part Hacking ............................................... 67 7.12 User Representation of Data ....................................... 68 8 Graphics and Forms of Output 70 8.1 Options on the Command Line ...................................... 70 8.1.1 1D vs. 2D ............................................. 70 8.1.2 TeX Strings as Output ...................................... 70 8.1.3 Writing a Session to a File .................................... 71 8.2 Graphics .................................................. 73 8.2.1 2D function plotting ....................................... 73 8.2.2 3D Function Plotting ....................................... 73 8.3 Plot Options ................................................ 74 9 Maxims for the Maxima User 80 10 Help Systems and Debugging 82 11 Troubleshooting 83 12 Advanced Examples 84 II External, Additional, and Contributed Packages 87 13 The Concept of Packages - Expanding Maxima’s Abilities 88 14 Algebra 89 15 Calculus 90 15.1 asympa .................................................. 90 15.2 pdiff - Positional Derivatives ....................................... 91 15.3 qual .................................................... 100 16 Combinatorics 101 17 Differential Equations 102 CONTENTS 4 18 Graphics 103 19 Integequations 104 20 Integration 105 21 Macro 106 22 Matrix 107 23 Numeric 108 24 Physics 109 24.1 dimen ................................................... 109 24.2 dimension - Advanced Dimensional Analysis .............................. 110 24.3 physconst - Definitions for Physical Constants .............................. 118 25 Simplification 119 26 Special Functions 120 27 Sym 121 28 Tensor 122 29 Trigonometry 123 30 Utils 124 31 Vector 125 III Installing, Resources, Misc. 126 32 Installing Maxima 127 32.1 Requirements ............................................... 127 32.2 Source Based Installation on Linux .................................... 127 32.2.1 Configure ............................................. 127 32.2.2 Make ............................................... 128 32.3 Source Based Installation on Windows .................................. 129 32.4 Source Based Installation on MacOSX .................................. 129 List of Figures 129 Index 130 Bibliography 132 CONTENTS 5 Many hands and minds have contributed to Macsyma, in developing it as a research program, and tuning it for use by others. We have enjoyed constructing Macsyma and we hope that you will enjoy using it. We hope you will consider contributing your carefully polished and documented application programs to libraries at your local installation and other sites. Examples 1. First Example 29 6. Evaluation Toggle 33 2. Quitting Maxima 30 7. Basic Use of ev Command 33 3. End of Entry Characters 31 8. ev’s Expand Option 34 4. Line Labels 31 9. Float Example ?? 5. Labeling an Example Equation 32 Part I The Maxima Program and Standard Packages 6 CHAPTER 1 Introduction 1.1 What is Maxima? Maxima (pronounced mæxim 1e ) is a large computer program designed for the manipulation of algebraic expressions. You can use Maxima for manipulation of algebraic expressions involving constants, variables, and functions. It can differentiate, integrate, take limits, solve equations, factor polynomials, expand functions in power series, solve differ- ential equations in closed form, and perform many other operations. It also has a programming language that you can use to extend Maxima’s capabilities. The Dangers of Computer Algebra With all this marvelous capability, however, you must bear in mind the limitations inherent in any such tool. Those considering the use of computers to do mathematics, particularly students, must be warned that these systems are no substitute for hands on work with equations and struggling with concepts. These systems do not build your mathematical intuition, nor will they strengthen your core skills. This will matter a great deal down the road, especially to those of you who wish to break new ground in theoretical mathematics and science. Do not use a computer as a substitute for your basic education. By the same token, however, proficiency with computers and computer based mathematics is crucial for attacking the many problems which literally cannot be solved by pencil and paper methods. In many cases problems which would take years by hand can be reduced to seconds by powerful computers. Also, in the course of a long derivation, it is sometimes useful for those who have already mastered the fundamentals to do work in these systems as a guard against careless errors, or a faster means than a table of deriving some particular result. Also, in case of an error, fixing the resulting error can often be much quicker and simpler courtesy of a mathematical notebook, which can be reevaluated with the correct parameters in place. But just as a computer can guard against human error, the human must not trust the computer unquestioningly. All of these systems have limits, and when those limits are reached it is quite possible for bizarre errors to result, or in some cases answers which are actually wrong, to say nothing of the fact that the people who programmed these systems were human, and make mistakes. To illustrate the limits of computer algebra systems, we take the following example: when given the integral Integrate 1/sqrt(2-2*cos(x)) from x=-pi/2 to pi/2, Mathematica 4.1 gives, with no warnings, \!\(2\ Log[4] - 2\ Log[Cos[\[Pi]\/8]] + 2\ Log[Sin[\[Pi]\/8]]\) which N[%] evalutates numerically to give 1.00984. Maxima 5.6 returns the integral unevaluated, the commercial Macsyma says the integral is divergent, and Maple 7 says infinity. (Cite Maxima Email list here.) Had the person who wished to learn the result 1The acronym Maxima is the corruption of the main project name MACSYMA, which stands for Project MAC’s SYmbolic MAnipulation System. MAC itself is an acronym, usually cited as meaning Man and Computer or Machine Aided Cognition. The Laboratory for Computer Science at the Massachusetts Institute of Technology was known as Project MAC during the initial development of MACSYMA. The name MACSYMA is now trademarked by Macsyma Inc. 7 CHAPTER 1. INTRODUCTION