Scott Maple® for Environmental Sciences Springer-Verlag Berlin Heidelberg GmbH Bill Scott Maple® for Environmental Seienees a Helping Hand t Springer Bill Scott Murdoch University School of Environmental Science Perth, Western Australia,61S0 Australia e-mail: [email protected] Cip data applied for Die Ikul"h~ Bibliothek· C[P-Einh~itsaufuahme ScOlt, B~I: Maple foren"ironmentaJ .ociences:. hdping hud /Sill Sco1t .. Ikrlin; Heidelberg; New York; BarcelOO\ll; Hong Kong; London; Milan; P,ris; Singapore; T<>kyo: Springer,1OO1 ISBN 978-3-540-65826-9 ISBN 978-3-642-56685-1 (eBook) DOI 10.1007/978-3-642-56685-1 Mathem'lics Subiect Cla ••i fiUlion (2000): 92F<15, 68W30 ISBN 978-3-540-65826-9 Mapl~ i• • ...gislerNIlrademark ofWaterloo Maple In<. Thi.lndemark i. ~ing used with kind ~rmi ..i on of Mapl. Inc. This work i. subjecltO copyright. Ali rigii" a~ rHtrved, whelher Ihe whole or pati of lhe material i. oon«rned• • ""cifiCllUy the righu of Ir. ...l al;.,n, reprinting. reuse ofillu$(rations, recitalion,broadc""ting, reproduclion on microfilm <>r in .nyo'her way,and "oroge in data banks. DDp~C1Ition of thi. publicatioo Of part. thereof i. ~rmitted only under th. provisions of the Germlll1 Copyright L.o.w of Seplembcr 9, 1965, in its cur~nl "" ..i on,and ~rm"'ion fur uo< mUit always "" obtained (rom Springer-Yerlag. Violati,,", a~ liable fur prosecution under the German Copyright law. hllp-J/www .•p ringer.de O Sprin~r·Vtrl.g Berlin Heidelberg 2001 Originally published by SpriDger-Verlag Berlin Heidelberg New York in 1001 The use of genenl descripti"" names. rogiitOfed nam .., trademarks etc. in thi, publiC1ltion do", not imply, even in th~ at.s~nce ai. specific statement,lhat.uch nam .. areelempt from th~ ~Ie-vant protective laws and regul.tionslll1d the~fu .. free fur general u..,. Cover design: de,ign6-producrio", H~ldtl""rg 1'ypt~ting by th~ oul hor Pnnled on acid-fIN p.""r SPIN I070S56J 4O/3142ck·S43210 Preface What is this book about? Please take this book as it is, a working docu ment. It started as an ideathat has grown. Itwill never becorrect but should be self-correcting. In the limit, if there is one, the book should approach a 'correct' state. It is not the detail, and the numbers, that matter, but the structuresandtheorder. Thesestructuresareinherentlylinkedwiththemany minds that have made Maple, the minds ofperhaps the best mathematicians, certainly some of the most useful. Our environment is not separate from mathematics; mathematics is but one tool, of several, to help with understanding the environment. It is a harshtoolthatrequiresnumbersandsymbolism; Maplehandlesthesymbolism superbly; numbers need more consideration. We have included a substantial amount onreading and writing numbers, data, and dealingwithfloating point numbers. It is the 'devil in the detail' that continually comes back to us in working with Mathematics and Maple. It becomes 'raw' and defined. Many of the things we do have rational and logical bases, but we don't know what they are. Often, in following the code and 'talking' withan input line to Maple, the detailed way ofperforminga task becomes clear. But not without frustration; the task is invariably simple, though. Complexity comes from the simple, redone. Hopefully, this book reveals how one can work with the simplest of operations. This somehow grows, forming anddefiningthestructureofthe problem; thephysics, boundariesand interconnections. And Maple does the grunge work, accurately and robustly. This book starts at the basics and interleaves applications with an ever growinglevelofmathematics. At thestart, the material will be toosimple; at theend,thematerialwillseemtoosimple. Inbetween, therewillbedifficulties, some that require a deal of thought and perhaps background reading. But all should be viewed as examples of what can be done. Some examples are full applications to ordinary environmental problems; many are simplified to reduce the number of pages required. The Maple input to the computer needs to be tolerated. It is a little cryptic, but mostly English and logical. Ifyou don't like the particulars, you canalwaysdefine your own. Mapleas a language is powerful; manyofthe raw commands can be viewed and even altered to suit your needs. You can use the maths mode that allows the input to look like mathematical symbolisms and this is agreeable to the eye. But, remember, you need brief, quick and unambiguous words to communicate with maths. The rather harsh Maple words may be a little too massaged in mathematical squiggles. Presentation always comes into scientific endeavor; on paper, on screens, and over the Internet. There are many adequate ways of doing these things and Maple wouldn't be one of the best. But Maple does these things and may do admirably. Especially with graphical information, it seems there are always betterways. Importantly, Maplemakesit possibletomakeand massage a graph to do 'what you want' the 'way you want'. The view in this book is that graphical techniquesareessential, at thefirst andat the last ofa problem and not just for presentation. The graph leads the scientist to a better view, or at least a different or broader view ofwhat is happening. Report writingisprobablythe lastthingMapleshouldbeasked todo. But Maple can. The reason for this is three-fold: One is the interlacing with La TeX; the second is the ability to generate mathematical constructs to present graphicaldata; the third is the necessity, thesedays, for an 'active' worksheet. The worksheet can be prepared and converted into LaTeX or HTML for near to-realtimeviewingasa .dvior .psfile orwithNetscape. Allofthesedocument handling schemes are available through nearly free software and allow anyone to prepare an active, professional document. Who is this book intended for? It is for anyone who needs a tool to help come to grips with complex environmental matters. Maple is good at doing difficult and tedious work. Environmental sciences are many and varied. The examples and problems displayed here exemplify this variety. Therefore, whoever you are, the whole ofthis book is not for you - at least, not now. Some ofit is for someone else now and perhaps for you later. Because this is a book about Maple and how it is applied in the environ mentalsciences, basicprinciplesofthesciencesarenotdiscussed; it isassumed that the reader will have acquired the necessary foundations elsewhere. This book can be used, at least initially, as a cookbook to do certain things, to allow you to absorb the science through rote learning, without knowledge as to why. The reality is that it will be necessary to read into and around the material ofinterest. How should I read this book? The answer is: Don't. Take this book as a game to be played, or a reference book; or, better, a basis for learning, a helpful source of working information. Thumb through the pages, look for somethingofinterestor need. Use the tableofcontentsorindextofind a topic or wordofinterest. Read asyou want and when you want. The material is not particularly dependent on what went before, nor is it necessarily coherent. It shouldallowyou tobeadventurous, to have ago; Mapleis that way. Itdoesn't respondasyouexpect but, through a Trial andError process, youcancutand amend the examples from the help or out ofthe worksheet; then append, plot and most ofall thinkabout the problem, the dataor thestructure, or the way or destroys them it is presented, or the way it massages your thoughts; the limit to a problem, the way it can be expanded or delayed in evaluation; the way mathematics and, at least, the Maple mathematicians think. These thoughts will usually be consistent, unlike the fuzzy way many thoughts seem to be. The answer is: use the book as a tool to formulate a problem; Maple will do the solution, or at least prepare the information so that you are further along. Importantly, enjoy yourselfand Maple. Whatever is a symbol, anyway? Itisusualtotripoverthewaystrings, symbols and unevaluation are handled in recent versions of Maple. Unless converted or parsed into symbols or names, a string can not be evaluated and remains as a word or sentence to be used as, perhaps, a file name or a title on a graph; in recent versions of Maple strings are enclosed in double quotes " ". A symbol can be manipulated mathematically, multiplied and divided, and haveanother identity; it may beevaluated to become an expressionor list or set ofother symbols; you type its name but it can be more than simply a name. In Maple, most operations are done with symbols; specific designation of a symbol encloses the object in single backward quotes' '. In contrast, Maple uses single forward quotes ' , to delay evaluation or use the name one more time. Sinceevaluation usually occurs with executionofa statement, the forward quotes around an object are fragile and disappear after a single use. How can I proceed? This is not a book to be read from cover-to cover. First, get a copy ofMaple and install it on your computer. Second, lay the book beside your computer, turn on your computer and stoke up Maple. Follow your nose from there, with the book's help. You will find that you fumble through the material and will need to backtrack. The first three Doing the chapters are mostly introductory and begin with thesimplest ofstatements to exercises is a promote interest; each chapter then grows into a comprehensive, sometimes good idea, as a tedious crescendo of detail in Maple. You may find starting with Chapter 3 selfassessment valuable, or Chapter 4, or even Chapter 5 ifyou are mathematically inclined. and further Whatever approach you take, scan through what precedes: Chapter 1 has a learning listing of common errors and the end of the chapter contains valuable one line references. Set up an appropriate initialization file for yourself; the last section ofChapter 1should get you started. Should you need help, the latter part of Chapter 2 contains extensive self-help; you can go on to generate your own help files with Appendix AAArgh. Chapter 3 lists the details of plot options, operands to procedures and shows how to manipulate PLOT structures. Chapter 4 applies the methods ofMaple to real data, display and analysis. More usual mathematicalsolutionsappear in Chapter5, particularly considering turbulence and kidney stones. Could this book make a course of study? Certainly, at four levels; considering roughly 12 weeks ofstudy or a broken 80 hours offull-time study. 1 At primary school, secondary school or the 'complete idiot'; take the book in its given layout, leaving out sections 1.4-1.6, 2.3.3-2.4, 2.5.4-3.4, 3.6-3.7.2, 4.2-4.3,4.4.2-4.4.7, 5.5-5.7.9, and the Exercises with *. 2 At first year university, cover sections 1.2-1.4, 2.2-2.4, 3.1-3.7, 4.1-4.4, 5.1.3-5.5, and 6.1-6.4. The Exercises with *can be considered as projects. 3 Second and third year of university, cover 1.5, 2.2-2.4, 3.1-3.7, 4.2-4.4, 5.1-5.6, 6.1-6.5 . Complete two Exercises with a *. 4 Last year at university, postgraduates or computer-oriented individuals, cover 2.2-2.4, 3.1-3.9, 4.3-4.4, 5.3-5.7, 6.1-6.5, and appendix AAArgh, to Exercise A.2. In all, you should be able to generate your own, independent, self-driven course ofstudy. Is the material up to date? The book has been tested on Maple ver sions up to Maple V, Release 5.1; it is set up for use with that version. The main updates that will affect the users ofMaple 6 are the use of II for cate nating strings and symbols, as well as the use of end do; end if; and end proc; in the place of od; fi; and end; These syntax changes are noted in the marginal notes and workarounds are quick and transparent; see Maple Initialization, section 1.6, page 52. The material in this book is introductory and should be timeless and valid for most versions of Maple. The compan ion CD has been specifically updated to Maple 6; the material in many cases is different and offers a helpful compatibility with the material in the printed book. The real powerofMaple6isinits preprocessingcapability, interactions with other languages, faster and enhanced numerical capability, handling of largeexpressions, errorcheckingfeatures aswellas compliancewithothersoft ware in the exchange offigures and data. The material in this book has been testedonIBMcompatible, Macintosh, andUnix (Linux) versionsofMapleand has grown with teaching and tutorial experience since the earliest versions of Maple. Who helped put this book together? This is a montage of material gatheredthroughtheyearsinteachingandresearchbytheauthor. Someofthe material is from the multitude ofbooks available and the MapleTech Journal. Ifsome part is not properly acknowledged, please accept my apologies. The philosophy behind this book comes from the Symbolic Manipulation Group, in Waterloo, Ontario. A visit by the author, in 1992, started the thoughts rolling. Particularly important were the interactions with Stan De vitt, both in Waterloo and Saskatoon, where the idea of an active book was presented by Stan. A book intended to be replaced by the student, a book that continues to grow into more than ever seemed possible. I hope this is that book. Bill Scott 15JunOO Acknowledgements This bookis dedicated to my wife, Pat, and my boys, Josh, 'athan anti Evan. Suggestions and drawings from Pat, Nathan and Evan are included. Without Pat's continued support, particularly in foreign lands, this book would not be. Greg Fee and John Ogilvie were there at Simon Fraser University, at a turning point, and helped keep many ideas flowing. Stewart Greenhill and John Horgan have given unerring advice, written software and script files. Helen Cockerill and Leon Harrissaved much ofthe material from oblivion and rebuilt various computer systems to make this book possible. Contents 1 Turning On: Hints 1 1.1 The Semicolon 2 1.2 Using Help ... 17 1.3 Helpful Hints . . 19 1.4 Frequent Errors . 20 1.5 Reference Material: types and commands 30 1.6 Your own Environment: .ini and interface 52 2 Structures and Analysis: Help 61 2.1 Pulling Maple Apart . . . . . 62 2.1.1 Functions and Assignment. 63 2.1.2 Lists, Sets and Sequences 66 2.1.3 Convert.......... 68 2.1.4 Set Operations and Types 70 2.1.5 Catenation . . . 72 2.2 Area ofa Lake . . . . . 76 2.3 Environmental Numbers 78 2.3.1 Units Conversion 78 2.3.2 Calibration ofPermeation Tubes 80 2.3.3 Greenhouse Atmospheres 83 2.4 Worksheets and Documents 89 2.4.1 Worksheets........ 89 2.4.2 Execution Groups .... 90 2.4.3 Sections and Subsections 90 2.4.4 Headings and Listing. . . 90 2.4.5 Cross Referencing, HyperLinks 91 2.4.6 Exporting: ASCII, LaTeX and HTML 91 2.4.7 Transferring: Powerpoint, Word, Scientific Workplace and Excel . . . . . . . . 94 2.4.8 Getting into the System 94 2.4.9 Command Line Maple . 96 2.5 AAArgh->Self Help . . . . . . 97 2.5.1 Help through a simple readme file 97