15 Svein Linge · Hans Petter Langtangen Programming for Computations – Python Editorial Board T J.Barth M.Griebel D.E.Keyes R.M.Nieminen D.Roose T.Schlick Texts in Computational Science and Engineering Editors Timothy J Barth Michael Griebel David E Keyes Risto M Nieminen Dirk Roose Tamar Schlick 15 More information about this series at http://www.springer.com/series/5151 Svein Linge Hans Petter Langtangen Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python Svein Linge Department of Process, Energy and Environmental Technology University College of Southeast Norway Porsgrunn, Norway Hans Petter Langtangen Simula Research Laboratory Lysaker, Norway On leave from: Department of Informatics University of Oslo Oslo, Norway ISSN 1611-0994 Texts in Computational Science and Engineering ISBN 978-3-319-32427-2 ISBN 978-3-319-32428-9 (eBook) DOI 10.1007/978-3-319-32428-9 Springer Heidelberg Dordrecht London New York Library of Congress Control Number: 2016945368 Mathematic Subject Classification (2010): 26-01, 34A05, 34A30, 34A34, 39-01, 40-01, 65D15, 65D25, 65D30, 68-01, 68N01, 68N19, 68N30, 70-01, 92D25, 97-04, 97U50 © The Editor(s) (if applicable) and the Author(s) 2016 This book is published open access Open Access This book is distributed under the terms of the Creative Commons Attribution-NonCommercial 4.0 International License (http://creativecommons.org/licenses/by-nc/4.0/), which permits any noncommercial use, duplication, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, a link is provided to the Creative Commons license and any changes made are indicated The images or other third party material in this book are included in the work’s Creative Commons license, unless indicated otherwise in the credit line; if such material is not included in the work’s Creative Commons license and the respective action is not permitted by statutory regulation, users will need to obtain permission from the license holder to duplicate, adapt or reproduce the material This work is subject to copyright All commercial rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed The use of general descriptive names, registered names, trademarks, service marks, etc in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication Neither the publisher nor the authors or the editors give a warranty, express or implied, with respect to the material contained herein or for any errors or omissions that may have been made Printed on acid-free paper Springer International Publishing AG Switzerland is part of Springer Science+Business Media (www.springer.com) Preface Computing, in the sense of doing mathematical calculations, is a skill that mankind has developed over thousands of years Programming, on the other hand, is in its infancy, with a history that spans a few decades only Both topics are vastly comprehensive and usually taught as separate subjects in educational institutions around the world, especially at the undergraduate level This book is about the combination of the two, because computing today becomes so much more powerful when combined with programming Most universities and colleges implicitly require students to specialize in computer science if they want to learn the craft of programming, since other student programs usually not offer programming to an extent demanded for really mastering this craft Common arguments claim that it is sufficient with a brief introduction, that there is not enough room for learning programming in addition to all other must-have subjects, and that there is so much software available that few really need to program themselves A consequence is that engineering students often graduate with shallow knowledge about programming, unless they happened to choose the computer science direction We think this is an unfortunate situation There is no doubt that practicing engineers and scientists need to know their pen and paper mathematics They must also be able to run off-the-shelf software for important standard tasks and will certainly that a lot Nevertheless, the benefits of mastering programming are many Why learn programming? Ready-made software is limited to handling certain standard problems What you when the problem at hand is not covered by the software you bought? Fortunately, a lot of modern software systems are extensible via programming In fact, many systems demand parts of the problem specification (e.g., material models) to be specified by computer code With programming skills, you may extend the flexibility of existing software packages by combining them For example, you may integrate packages that not speak to each other from the outset This makes the work flow simpler, more efficient, and more reliable, and it puts you in position to attack new problems v vi Preface It is easy to use excellent ready-made software the wrong way Insight in programming and the mathematics behind is fundamental for understanding complex software, avoiding pitfalls, and become a safe user Bugs (errors in computer code) are present in most larger computer programs (also in the ones from the shop!) What you when your ready-made software gives unexpected results? Is it a bug, is it wrong use, or is it the mathematically correct result? Experience with programming of mathematics gives you a good background for answering these questions The one who can program, can also make tailored code for a simplified problem setting and use that to verify the computations done with off-the-shelf software Lots of skilled people around the world solve computational problems by writing their own code and offer their code for free on the Internet To take advantage of this truly great source of software in a reliable way, one must normally be able to understand and possibly modify computer code offered by others It is recognized world wide that students struggle with mathematics and physics Too many find such subjects difficult and boring With programming, we can execute the good old subjects in a brand new way! According to the authors’ own experience, students find it much more motivating and enlightening when programming is made an integrated part of mathematics and physical science courses In particular, the problem being solved can be much more realistic than when the mathematics is restricted to what you can with pen and paper Finally, we launch our most important argument for learning computer programming: the algorithmic thinking that comes with the process of writing a program for a computational problem enforces a thorough understanding of both the problem and solution method We can simply quote the famous Norwegian computer scientist Kristen Nyggaard: “Programming is understanding” In the authors’ experience, programming is an excellent pedagogical tool for understanding mathematics: “You think you know when you can learn, are more sure when you can write, even more when you can teach, but certain when you can program” (Alan Perlis, computer scientist, 1922-1990) Consider, for example, integration A numerical method for integration has a much stronger focus on what the integral actually is and means compared to analytical methods, where much time and effort must be devoted to integration by parts, integration by substitution, etc Moreover, when programming the numerical integration formula, it becomes evident that it works for “all” mathematical functions and that the implementation should be in terms of a general function applicable to “all” integrals In this way, students learn to recognize a special problem as belonging to a class of problems (e.g., integration, differential equations, root finding), for which we have general numerical methods implemented in widely applicable software When they write this software, as we in this book, they learn how to generalize and increase the abstraction level of the mathematical problem When they use this software, they learn how a special case should be attacked by general methods and software for the class of problems that comprises the special case at hand This is the power of mathematics in a nutshell, and it is paramount that students understand this way of thinking Preface vii Target audience and background knowledge This book was written for students, teachers, engineers and scientists that know nothing about programming and numerical methods from before, but who seek a minimum of the fundamental skills required to get started with programming as a tool for solving scientific and engineering problems Some knowledge of one- and multi-variable calculus is assumed The basic programming concepts are presented in only 50 pages (Chapters and 2), before practical applications of these concepts are demonstrated in important mathematical subjects addressed in the remaining parts of the book (Chapters 3-6) Each chapter is followed by a set of exercises that cover a wide range of application areas, e.g biology, geology, statistics, physics and mathematics The exercises were particularly designed to bring across important points from the text The reader will realize that the modest content of the first 50 pages can in fact bring you quite far in powerful problem solving! Learning the very basics of programming should not take long, but as with any other craft, mastering the skill requires continued and extensive practice Some beginning practice is gained through Chapters 3-6, but the authors strongly emphasize that this is only a start Students should continue to practice programming in subsequent courses, while those who exercise self-study, should keep up the learning process through continued application of the craft The book is a good starting point when teaching computer programming as an integrated part of standard university courses in mathematics and physical sciences In our experience, such an integration is doable and indeed rewarding Numerical methods An overall goal with this book is to motivate computer programming as a very powerful tool for doing mathematics All examples are related to mathematics and its use in engineering and science However, to solve mathematical problems through computer programming, we need numerical methods Explaining basic numerical methods is therefore an integral part of the book Our choice of topics is governed by what is most needed in science and engineering, as well as in the teaching of applied physical science courses Mathematical models are then central, with differential equations constituting the most frequent type of models Consequently, the numerical focus in this book is on differential equations As a soft pedagogical starter for the programming of mathematics, we have chosen the topic of numerical integration There is also a chapter on root finding, which is important for the numerical solution on nonlinear differential equations We remark that the book is deliberately brief on numerical methods This is because our focus is on implementing numerical algorithms, but to develop reliable, working programs, the programmer must be confident about the basic ideas of the numerical approximations involved The computer language: Python We have chosen to use the programming language Python, because this language gives very compact and readable code that closely resembles the mathematical recipe for solving the problem at hand Python also has a gentle learning curve There is a MATLAB/Octave companion of this book in case that language is preferred Comparing these two versions of the book provides an excellent demonstration of how similar these languages are Other computer languages, like Fortran, C, and C++, have a strong position in science and engineering During the last two decades, however, there has been a significant viii Preface shift in popularity from these compiled languages to more high-level and easier-toread languages like Matlab, Python, R, Maple, Mathematica, and IDL, for instance This latter class of languages is computationally less efficient, but superior with respect to overall human problem solving efficiency This book emphasizes how to think like a programmer, rather than focusing on technical language details Thus, the book should put the reader in a good position for learning other programming languages later, including the classic ones: Fortran, C, and C++ How this book is different There are numerous texts on computer programming and numerical methods, so how does the present one differ from the existing literature? Compared to books on numerical methods, our book has a much stronger emphasis on the craft of programming and on verification We want to give students a thorough understanding of how one thinks about programming as a problem solving method and how one can be sure that programs are correct (well, you can never be completely sure, but we show how you can provide convincing evidence for correctness) Even though there are lots of books on numerical methods where many algorithms have a corresponding computer implementation (see, e.g., [1, 3–6, 11, 16– 18, 21, 24, 26–31] – the latter two are the only texts we know that apply Python), it is assumed that the reader “can program” beforehand The present book teaches the craft of structured programming along with the fundamental ideas of numerical methods Furthermore, we have so far not found any other numerical methods book that has a strong emphasis on verifying implementations In this book, unit testing and corresponding test functions are introduced early on We also put much emphasis on coding algorithms as functions, as opposed to “flat programs”, which often dominate in the literature and among practitioners Functions are reusable because they utilize the general formulation of a mathematical algorithm such that it becomes applicable to a large class of problems There are also numerous books on computer programming, but to our knowledge only one [13] that aims to teach how to think about programming in the context of numerical methods and scientific applications That book [13] has its primary focus on teaching Python and is a very comprehensive introduction to Python as a language and the thinking about programming as a computer scientist Sometimes one needs a text that does not go so deep into the language-specific details, but instead targets the shortest path to reliable mathematical problem solving through programming With this attitude in mind, a lot of topics were left out of the present book, simply because they were not strictly needed in the mathematical problem solving process Examples of such topics are object-oriented programming and Python dictionaries (of which the latter omission is possibly subject to more debate) If you find the present book too shallow, [13] might be the right choice for you That source should also work nicely as a more in-depth successor of the present text Whenever the need for a structured introduction to programming arises in science and engineering courses, this book may be your option, either for self-study or for use in organized teaching The thinking, habits, and practice covered in a couple of hundred pages will put readers in a firm position for utilizing and understanding the power of computers for problem solving in science and engineering Preface ix Supplementary materials All program and data files referred to in this book are available from the book’s primary web site: http://hplgit.github.io/prog4comp/ Acknowledgments First of all, we want to thank all students who attended the courses FM1006 Modelling and simulation of dynamic systems, FM1115 Scientific Computing, FB1012 Mathematics I and FB2112 Physics at the University College of Southeast Norway over the last couple of years They worked their way through early versions of this text and gave us constructive and positive feedback that helped us correct errors and improve the book in so many ways Special acknowledgement goes to Guandong Kou and Edirisinghe V P J Manjula for their careful reading of the manuscript and constructive suggestions for improvement The careful proof reading by Yapi Donatien Achou is also highly appreciated We thank all our good colleagues at the University College of Southeast Norway, University of Oslo, and Simula Research Laboratory for their continued support and interest, enlightening discussions, and for providing such an inspiring environment for teaching and science In particular, Svein Linge is thankful to Marius Lysaker for their fruitful collaboration on introducing programming as an integral part of mathematics and physics bachelor courses at the University College of Southeast Norway Finally, the authors must thank the Springer team with Dr Martin Peters, Thanh-Ha Le Thi, and Yvonne Schlatter for the effective editorial and production process The text was written in the DocOnce1 [12] markup language, which allowed us to work with a single text source for both the Python and the Matlab version of this book, and to produce various electronic versions of the book December 2015 https://github.com/hplgit/doconce Svein Linge and Hans Petter Langtangen A.5 Writing IPython Notebooks 217 Executing these statements results in a plot in the browser, see Fig A.2 It was popular to start the notebook by ipython notebook –pylab to import everything from numpy and matplotlib.pyplot and make all plots inline, but the –pylab option is now officially discouraged18 If you want the notebook to behave more as MATLAB and not use the np and plt prefix, you can instead of the first three lines above write %pylab Fig A.2 Example on an IPython notebook 18 http://carreau.github.io/posts/10-No-PyLab-Thanks.ipynb.html References L Baochuan Introduction to Numerical Methods 2015 Introduction_to_Numerical_Methods http://en.wikibooks.org/wiki/ O Certik et al SymPy: Python library for symbolic mathematics http://sympy.org/ S D Conte and C de Boor Elementary Numerical Analysis - An Algorithmic Approach McGraw-Hill, third edition, 1980 I Danaila, P Joly, S M Kaber, and M Postel An Introduction to Scientific Computing Springer, 2007 C Greif and U M Ascher A First Course in Numerical Methods Computational Science and Engineering SIAM, 2011 D W Harder and R Numerical Analysis for Engineering 2015 https://ece.uwaterloo.ca/ ~dwharder/NumericalAnalysis/ ScientificPython software package http://starship.python.net/crew/hinsen J D Hunter Matplotlib: a 2D graphics environment Computing in Science & Engineering, 9, 2007 J D Hunter et al Matplotlib: Software package for 2D graphics http://matplotlib.org/ 10 E Jones, T E Oliphant, P Peterson, et al SciPy scientific computing library for Python http://scipy.org 11 J Kiusalaas Numerical Methods in Engineering with Python Cambridge, second edition, 2014 12 H P Langtangen DocOnce publishing platform https://github.com/hplgit/doconce 13 H P Langtangen A Primer on Scientific Programming with Python Texts in Computational Science and Engineering Springer, fifth edition, 2016 14 H P Langtangen and J H Ring SciTools: Software tools for scientific computing https:// github.com/hplgit/scitools 15 R LeVeque Finite Difference Methods for Ordinary and Partial Differential Equations: Steady-State and Time-Dependent Problems SIAM, 2007 16 T Lyche and J.-L Merrien Exercises in Computational Mathematics with MATLAB Springer, 2014 17 C Moler Numerical Computing with MATLAB SIAM, 2004 http://se.mathworks.com/ moler/chapters.html 18 S Nakamura Numerical Analysis and Graphic Visualization with Matlab Prentice Hall, second edition, 2002 19 T E Oliphant Python for scientific computing Computing in Science & Engineering, 9, 2007 219 220 References 20 T E Oliphant et al NumPy array processing package for Python http://www.numpy.org 21 S Otto and J P Denier An Introduction to Programming and Numerical Methods in MATLAB Springer, 2005 22 F Perez and B E Granger IPython: a system for interactive scientific computing Computing in Science & Engineering, 9, 2007 23 F Perez, B E Granger, et al IPython software package for interactive scientific computing http://ipython.org/ 24 W H Press, S A Teukolsky, W T Vetterling, and B P Flannery Numerical Recipes Cambridge, 1992 http://www.nrbook.com/a/bookcpdf.php 25 Python programming language http://python.org 26 G Recktenwald Numerical Methods with MATLAB: Implementations and Applications Prentice-Hall, 2000 http://web.cecs.pdx.edu/~gerry/nmm/ 27 G Sewell The Numerical Solution of Ordinary and Partial Differential Equations Wiley, 2005 28 T Siauw and A Bayen An Introduction to MATLAB Programming and Numerical Methods for Engineers Academic Press, 2014 http://www.sciencedirect.com/science/book/ 9780124202283 29 L N Trefethen Spectral Methods in MATLAB SIAM, 2000 30 L N Trefethen Approximation Theory and Approximation Practice SIAM, 2012 31 T Young and M J Mohlenkamp Introduction to Numerical Methods and MATLAB Programming for Engineers 2015 https://www.math.ohiou.edu/courses/math3600/book.pdf Index 2nd-order Runge-Kutta method, 131 A algorithm, allocate, 17 argument, 31 keyword, 34 named, 34 ordinary, 34 positional, 34 array, 11, 17 element, 17 index, 17 slice of, 18 sorting, 47 asarray (function), 118 assert (function), 72 assignment, atan, axis (plot), 20 B boolean, 29 expression, 29 False, 29 True, 29 boundary conditions, 162 brute force method, 186 bug, 2, 3, 68 C C, C++, calculator, cell, 164 class, 168 closure, 168 code, exception, 195 re-use, 63, 80 robust, 193 try-except, 195 colon, 29 comment, commenting code, 25 compartment model, 111 composite midpoint method, 65 composite trapezoidal rule, 57 computational speed (measuring), 77 computer program, convergence rate, 70 copy, 18 Crank-Nicolson method, 140, 156 D debugger, 22 debugging, 2, 3, 22 def, 31 default, 15 demo function, 105 difference absolute, 72 backward, 130 centered, 131 forward, 99, 130 relative, 72 differential equation first-order, 96 second-order, 125 diffusion equation, 161 discontinuous coefficient, 123 divergence, 194 doc string, 35 DocOnce, ix domain, 78, 82, 84, 162 complex, 84 double integral midpoint, 78 double sum, 79 dynamical system, 95 221 222 E elif, 29 else, 29 Emacs, 6, 212 error asymptotic, 70 function (erf), 64 message, 21 rounding, 71 tolerance, 71 Euler pi, 48 Euler’s method, 101 exception handling, 22 execute (a program), exit (sys), 200 exp math notation, 98 F False, 29 fast code, 25 finite difference method, 99 finite precision (of float), 71 flat program, 63 float, 13 floating point number (float), 71 for loop, 37 format png, 20 Fortran, forward difference approximation, 99 Forward Euler scheme, 101 Fourier series, 51 from, function, 7, 31 asarray, 118 assert, 72 call, definition, 31 global, 36 handle, 35 input parameter, local, 36 nested, 36 output parameter, return, take a parameter, G garbage collection, 25 Gauss quadrature, 68 Gedit, 6, 212 graph, 18 H hardcopy (plot), 20 heat equation, 161 Heun’s method, 131 hold (on/off), 19 I Idle, 212 if, 29 implement (a program), implementation general, 60 specific, 60 import, 12 math, matplotlib.pyplot, 10 module, 62 numpy, 10 random (function), 30 indent, 29 indexing one based, 17 zero based, 17 initial conditions, 162 input, 23 instability, 170 instruction, int, 13 integer division, 14 integral analytically, 55 approximately, 55 exact, 55 numerically, 55 integration points, 57 interactive use (of Python), 12 IPython, 6, 12 K keyboard arrow up/down, 12 L lambda function, 36 language computer, programming, Laplace equation, 182 least squares method, 50 legend (plot), 20 Leibniz pi, 48 library, function, SymPy, 23 linear algebra, 21, 39 linear interpolation, 49 linspace, 10 list, 23, 41 Index Index append, 41 comprehension, 42 convert to array, 41 create, 41 delete, 41 loadtxt, 44 logistic model carrying capacity, 107 long lines (splitting of), 25 loop double, 39 for, 37 index, 37, 40 infinite, 40 iteration, 37, 40 multiple, 39 nested, 39 while, 40 M main program, 33 Maple, math, Mathematica, 2, 24 mathematical modeling, 116 MATLAB, matplotlib.pyplot, 10 matrix, 21 mat, 21 tridiagonal, 177 vector product, 21 mesh, 99 points, 99, 164 uniform, 99 method of lines, 163, 164 Midpoint method, 65 model computational, 97 differential equation, 96 mathematical, 3, 96 module, 8, 62 MOL, 163 forward Euler, 163 Monte Carlo integration, 84 N NameError, Newton starting value, 196 nonlinear algebraic equation, 132 nose (testing), 72 Notepad++, 6, 212 numerical scheme, 101 numpy, 10 O object, 13 223 Octave, ODE scalar, 116 vector, 116 operator Arithmetic, 13 Logical, 30 P package, parameter input, 31 output, 31 parentheses, 13 PDE, 161 plot, 9, 11 figure, 20 Poisson equation, 182 print, printf formatting, 15 printing formatted, 15 program crash, 22 execute, 4, flat, 63 input, 23 output, 23 run, 4, statement, testing, 22 typing, verification, 22 programming, game, 49 prompt, 6, 12 pseudo code, 29 py.test, 72 Python, documentation, 25 installation, shell, 12 zero-based indexing, 18 R random (function), 30 random walk, 29 range, 37 rate of convergence, 70, 201 raw input, 23 read (from file), 43 reserved words, 13 resonance, 146 return, 31 None, 200 value, 33 RK2, 131 224 root finding, 186 rounding error, 13, 14 Runge-Kutta, 2nd-order method, 131 Runge-Kutta-Fehlberg, 137 S Sage (symbolic package), 25 savetxt, 44 scalar ODE, 116 scaling, 144, 170 scheme, 96 script (and scripting), second-order ODE rewritten as two first-order ODEs, 126 seed (random generators), 87 simple pendulum, 125 Simpson’s rule, 68 simulation, SIR model, 110 source term, 161 spring damping of, 124, 141 linear, 144 nonlinear, 141 oscillations, 124 Spyder, stability criterion, 170 stop program (Ctrl+c), 41 str, 13 symbolic computations, 23 operations, 23 simplifications, 23 SymPy, 23 syntax, sys.exit, 200 system of ODEs, 116 T Taylor series, 157 test block, 62 test function, 72 testing, 22 testing procedures, 69 text editor, TextWrangler, 6, 212 theta rule, 179 title (plot), 20 transpose (of matrix), 21 Trapezoidal rule, 57 tridiagonal matrix, 177 triple integral midpoint, 81 True, 29 try-exception, 22 tuple, 23, 41 type conversion, 13 automatic, 14 U unit tests, 69 unstable solutions, 170 V validation, 22 variable, assignment, 13 delete, 25 float, 13 global, 34 int, 13 local, 34 name, 13 str, 13 type, 13 vector, 21 vector ODE, 116 vectorization, 76, 172 verification, 22 Verlet integration, 150 Vim, 6, 212 W WARNING, while loop, 40 WolframAlpha, 24 write (to file), 43 X xlabel, 11 Y ylabel, 11 Z zeros, 17 Index Editorial Policy §1 Textbooks on topics in the field of computational science and engineering will be considered They should be written for courses in CSE education Both graduate and undergraduate textbooks will be published in TCSE Multidisciplinary topics and multidisciplinary teams of authors are especially welcome §2 Format: Only works in English will be considered For evaluation purposes, manuscripts may be submitted in print or electronic form, in the latter case, preferably as pdf- or zipped ps-files Authors are requested to use the LaTeX style files available from Springer at: https://www.springer.com/gp/authors-editors/bookauthors-editors/manuscript-preparation/5636 (Click on ! Templates ! LaTeX ! monographs) Electronic material can be included if appropriate Please contact the publisher §3 Those considering a book which might be suitable for the series are strongly advised to contact the publisher or the series editors at an early stage General Remarks Careful preparation of manuscripts will help keep production time short and ensure a satisfactory appearance of the finished book The following terms and conditions hold: Regarding free copies and royalties, the standard terms for Springer mathematics textbooks hold Please write to martin.peters@springer.com for details Authors are entitled to purchase further copies of their book and other Springer books for their personal use, at a discount of 33.3% directly from Springer-Verlag Series Editors Timothy J Barth NASA Ames Research Center NAS Division Moffett Field, CA 94035, USA barth@nas.nasa.gov Michael Griebel Institut für Numerische Simulation der Universität Bonn Wegelerstr 53115 Bonn, Germany griebel@ins.uni-bonn.de Risto M Nieminen Department of Applied Physics Aalto University School of Science and Technology 00076 Aalto, Finland risto.nieminen@aalto.fi Dirk Roose Department of Computer Science Katholieke Universiteit Leuven Celestijnenlaan 200A 3001 Leuven-Heverlee, Belgium dirk.roose@cs.kuleuven.be David E Keyes Mathematical and Computer Sciences and Engineering King Abdullah University of Science and Technology P.O Box 55455 Jeddah 21534, Saudi Arabia david.keyes@kaust.edu.sa Tamar Schlick Department of Chemistry and Courant Institute of Mathematical Sciences New York University 251 Mercer Street New York, NY 10012, USA schlick@nyu.edu and Editor for Computational Science and Engineering at Springer: Martin Peters Springer-Verlag Mathematics Editorial IV Tiergartenstrasse 17 69121 Heidelberg, Germany martin.peters@springer.com Department of Applied Physics and Applied Mathematics Columbia University 500 W 120 th Street New York, NY 10027, USA kd2112@columbia.edu Texts in Computational Science and Engineering H P Langtangen, Computational Partial Differential Equations Numerical Methods and Diffpack Programming 2nd Edition A Quarteroni, F Saleri, P Gervasio, Scientific Computing with MATLAB and Octave 4th Edition H P Langtangen, Python Scripting for Computational Science 3rd Edition H Gardner, G Manduchi, Design Patterns for e-Science M Griebel, S Knapek, G Zumbusch, Numerical Simulation in Molecular Dynamics H P Langtangen, A Primer on Scientific Programming with Python 5th Edition A Tveito, H P Langtangen, B F Nielsen, X Cai, Elements of Scientific Computing B Gustafsson, Fundamentals of Scientific Computing M Bader, Space-Filling Curves 10 M Larson, F Bengzon, The Finite Element Method: Theory, Implementation and Applications 11 W Gander, M Gander, F Kwok, Scientific Computing: An Introduction using Maple and MATLAB 12 P Deuflhard, S Röblitz, A Guide to Numerical Modelling in Systems Biology 13 M H Holmes, Introduction to Scientific Computing and Data Analysis 14 S Linge, H P Langtangen, Programming for Computations – A Gentle Introduction to Numerical Simulations with MATLAB/Octave 15 S Linge, H P Langtangen, Programming for Computations – A Gentle Introduction to Numerical Simulations with Python For further information on these books please have a look at our mathematics catalogue at the following URL: www.springer.com/series/5151 Monographs in Computational Science and Engineering J Sundnes, G.T Lines, X Cai, B.F Nielsen, K.-A Mardal, A Tveito, Computing the Electrical Activity in the Heart For further information on this book, please have a look at our mathematics catalogue at the following URL: www.springer.com/series/7417 Lecture Notes in Computational Science and Engineering D Funaro, Spectral Elements for Transport-Dominated Equations H.P Langtangen, Computational Partial Differential Equations Numerical Methods and Diffpack Programming W Hackbusch, G Wittum (eds.), Multigrid Methods V P Deuflhard, J Hermans, B Leimkuhler, A.E Mark, S Reich, R.D Skeel (eds.), Computational Molecular Dynamics: Challenges, Methods, Ideas D Kröner, M Ohlberger, C Rohde (eds.), An Introduction to Recent Developments in Theory and Numerics for Conservation Laws S Turek, Efficient Solvers for Incompressible Flow Problems An Algorithmic and Computational Approach R von Schwerin, Multi Body System SIMulation Numerical Methods, Algorithms, and Software H.-J Bungartz, F Durst, C Zenger (eds.), High Performance Scientific and Engineering Computing T.J Barth, H Deconinck (eds.), High-Order Methods for Computational Physics 10 H.P Langtangen, A.M Bruaset, E Quak (eds.), Advances in Software Tools for Scientific Computing 11 B Cockburn, G.E Karniadakis, C.-W Shu (eds.), Discontinuous Galerkin Methods Theory, Computation and Applications 12 U van Rienen, Numerical Methods in Computational Electrodynamics Linear Systems in Practical Applications 13 B Engquist, L Johnsson, M Hammill, F Short (eds.), Simulation and Visualization on the Grid 14 E Dick, K Riemslagh, J Vierendeels (eds.), Multigrid Methods VI 15 A Frommer, T Lippert, B Medeke, K Schilling (eds.), Numerical Challenges in Lattice Quantum Chromodynamics 16 J Lang, Adaptive Multilevel Solution of Nonlinear Parabolic PDE Systems Theory, Algorithm, and Applications 17 B.I Wohlmuth, Discretization Methods and Iterative Solvers Based on Domain Decomposition 18 U van Rienen, M Günther, D Hecht (eds.), Scientific Computing in Electrical Engineering 19 I Babuška, P.G Ciarlet, T Miyoshi (eds.), Mathematical Modeling and Numerical Simulation in Continuum Mechanics 20 T.J Barth, T Chan, R Haimes (eds.), Multiscale and Multiresolution Methods Theory and Applications 21 M Breuer, F Durst, C Zenger (eds.), High Performance Scientific and Engineering Computing 22 K Urban, Wavelets in Numerical Simulation Problem Adapted Construction and Applications 23 L.F Pavarino, A Toselli (eds.), Recent Developments in Domain Decomposition Methods 24 T Schlick, H.H Gan (eds.), Computational Methods for Macromolecules: Challenges and Applications 25 T.J Barth, H Deconinck (eds.), Error Estimation and Adaptive Discretization Methods in Computational Fluid Dynamics 26 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations 27 S Müller, Adaptive Multiscale Schemes for Conservation Laws 28 C Carstensen, S Funken, W Hackbusch, R.H.W Hoppe, P Monk (eds.), Computational Electromagnetics 29 M.A Schweitzer, A Parallel Multilevel Partition of Unity Method for Elliptic Partial Differential Equations 30 T Biegler, O Ghattas, M Heinkenschloss, B van Bloemen Waanders (eds.), Large-Scale PDEConstrained Optimization 31 M Ainsworth, P Davies, D Duncan, P Martin, B Rynne (eds.), Topics in Computational Wave Propagation Direct and Inverse Problems 32 H Emmerich, B Nestler, M Schreckenberg (eds.), Interface and Transport Dynamics Computational Modelling 33 H.P Langtangen, A Tveito (eds.), Advanced Topics in Computational Partial Differential Equations Numerical Methods and Diffpack Programming 34 V John, Large Eddy Simulation of Turbulent Incompressible Flows Analytical and Numerical Results for a Class of LES Models 35 E Bänsch (ed.), Challenges in Scientific Computing – CISC 2002 36 B.N Khoromskij, G Wittum, Numerical Solution of Elliptic Differential Equations by Reduction to the Interface 37 A Iske, Multiresolution Methods in Scattered Data Modelling 38 S.-I Niculescu, K Gu (eds.), Advances in Time-Delay Systems 39 S Attinger, P Koumoutsakos (eds.), Multiscale Modelling and Simulation 40 R Kornhuber, R Hoppe, J Périaux, O Pironneau, O Wildlund, J Xu (eds.), Domain Decomposition Methods in Science and Engineering 41 T Plewa, T Linde, V.G Weirs (eds.), Adaptive Mesh Refinement – Theory and Applications 42 A Schmidt, K.G Siebert, Design of Adaptive Finite Element Software The Finite Element Toolbox ALBERTA 43 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations II 44 B Engquist, P Lötstedt, O Runborg (eds.), Multiscale Methods in Science and Engineering 45 P Benner, V Mehrmann, D.C Sorensen (eds.), Dimension Reduction of Large-Scale Systems 46 D Kressner, Numerical Methods for General and Structured Eigenvalue Problems 47 A Boriỗi, A Frommer, B Joú, A Kennedy, B Pendleton (eds.), QCD and Numerical Analysis III 48 F Graziani (ed.), Computational Methods in Transport 49 B Leimkuhler, C Chipot, R Elber, A Laaksonen, A Mark, T Schlick, C Schütte, R Skeel (eds.), New Algorithms for Macromolecular Simulation 50 M Bücker, G Corliss, P Hovland, U Naumann, B Norris (eds.), Automatic Differentiation: Applications, Theory, and Implementations 51 A.M Bruaset, A Tveito (eds.), Numerical Solution of Partial Differential Equations on Parallel Computers 52 K.H Hoffmann, A Meyer (eds.), Parallel Algorithms and Cluster Computing 53 H.-J Bungartz, M Schäfer (eds.), Fluid-Structure Interaction 54 J Behrens, Adaptive Atmospheric Modeling 55 O Widlund, D Keyes (eds.), Domain Decomposition Methods in Science and Engineering XVI 56 S Kassinos, C Langer, G Iaccarino, P Moin (eds.), Complex Effects in Large Eddy Simulations 57 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations III 58 A.N Gorban, B Kégl, D.C Wunsch, A Zinovyev (eds.), Principal Manifolds for Data Visualization and Dimension Reduction 59 H Ammari (ed.), Modeling and Computations in Electromagnetics: A Volume Dedicated to JeanClaude Nédélec 60 U Langer, M Discacciati, D Keyes, O Widlund, W Zulehner (eds.), Domain Decomposition Methods in Science and Engineering XVII 61 T Mathew, Domain Decomposition Methods for the Numerical Solution of Partial Differential Equations 62 F Graziani (ed.), Computational Methods in Transport: Verification and Validation 63 M Bebendorf, Hierarchical Matrices A Means to Efficiently Solve Elliptic Boundary Value Problems 64 C.H Bischof, H.M Bücker, P Hovland, U Naumann, J Utke (eds.), Advances in Automatic Differentiation 65 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations IV 66 B Engquist, P Lötstedt, O Runborg (eds.), Multiscale Modeling and Simulation in Science 67 I.H Tuncer, Ü Gülcat, D.R Emerson, K Matsuno (eds.), Parallel Computational Fluid Dynamics 2007 68 S Yip, T Diaz de la Rubia (eds.), Scientific Modeling and Simulations 69 A Hegarty, N Kopteva, E O’Riordan, M Stynes (eds.), BAIL 2008 – Boundary and Interior Layers 70 M Bercovier, M.J Gander, R Kornhuber, O Widlund (eds.), Domain Decomposition Methods in Science and Engineering XVIII 71 B Koren, C Vuik (eds.), Advanced Computational Methods in Science and Engineering 72 M Peters (ed.), Computational Fluid Dynamics for Sport Simulation 73 H.-J Bungartz, M Mehl, M Schäfer (eds.), Fluid Structure Interaction II – Modelling, Simulation, Optimization 74 D Tromeur-Dervout, G Brenner, D.R Emerson, J Erhel (eds.), Parallel Computational Fluid Dynamics 2008 75 A.N Gorban, D Roose (eds.), Coping with Complexity: Model Reduction and Data Analysis 76 J.S Hesthaven, E.M Rønquist (eds.), Spectral and High Order Methods for Partial Differential Equations 77 M Holtz, Sparse Grid Quadrature in High Dimensions with Applications in Finance and Insurance 78 Y Huang, R Kornhuber, O.Widlund, J Xu (eds.), Domain Decomposition Methods in Science and Engineering XIX 79 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations V 80 P.H Lauritzen, C Jablonowski, M.A Taylor, R.D Nair (eds.), Numerical Techniques for Global Atmospheric Models 81 C Clavero, J.L Gracia, F.J Lisbona (eds.), BAIL 2010 – Boundary and Interior Layers, Computational and Asymptotic Methods 82 B Engquist, O Runborg, Y.R Tsai (eds.), Numerical Analysis and Multiscale Computations 83 I.G Graham, T.Y Hou, O Lakkis, R Scheichl (eds.), Numerical Analysis of Multiscale Problems 84 A Logg, K.-A Mardal, G Wells (eds.), Automated Solution of Differential Equations by the Finite Element Method 85 J Blowey, M Jensen (eds.), Frontiers in Numerical Analysis – Durham 2010 86 O Kolditz, U.-J Gorke, H Shao, W Wang (eds.), Thermo-Hydro-Mechanical-Chemical Processes in Fractured Porous Media – Benchmarks and Examples 87 S Forth, P Hovland, E Phipps, J Utke, A Walther (eds.), Recent Advances in Algorithmic Differentiation 88 J Garcke, M Griebel (eds.), Sparse Grids and Applications 89 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations VI 90 C Pechstein, Finite and Boundary Element Tearing and Interconnecting Solvers for Multiscale Problems 91 R Bank, M Holst, O Widlund, J Xu (eds.), Domain Decomposition Methods in Science and Engineering XX 92 H Bijl, D Lucor, S Mishra, C Schwab (eds.), Uncertainty Quantification in Computational Fluid Dynamics 93 M Bader, H.-J Bungartz, T Weinzierl (eds.), Advanced Computing 94 M Ehrhardt, T Koprucki (eds.), Advanced Mathematical Models and Numerical Techniques for Multi-Band Effective Mass Approximations 95 M Azaïez, H El Fekih, J.S Hesthaven (eds.), Spectral and High Order Methods for Partial Differential Equations ICOSAHOM 2012 96 F Graziani, M.P Desjarlais, R Redmer, S.B Trickey (eds.), Frontiers and Challenges in Warm Dense Matter 97 J Garcke, D Pflüger (eds.), Sparse Grids and Applications – Munich 2012 98 J Erhel, M Gander, L Halpern, G Pichot, T Sassi, O Widlund (eds.), Domain Decomposition Methods in Science and Engineering XXI 99 R Abgrall, H Beaugendre, P.M Congedo, C Dobrzynski, V Perrier, M Ricchiuto (eds.), High Order Nonlinear Numerical Methods for Evolutionary PDEs – HONOM 2013 100 M Griebel, M.A Schweitzer (eds.), Meshfree Methods for Partial Differential Equations VII 101 R Hoppe (ed.), Optimization with PDE Constraints – OPTPDE 2014 102 S Dahlke, W Dahmen, M Griebel, W Hackbusch, K Ritter, R Schneider, C Schwab, H Yserentant (eds.), Extraction of Quantifiable Information from Complex Systems 103 A Abdulle, S Deparis, D Kressner, F Nobile, M Picasso (eds.), Numerical Mathematics and Advanced Applications – ENUMATH 2013 104 T Dickopf, M.J Gander, L Halpern, R Krause, L.F Pavarino (eds.), Domain Decomposition Methods in Science and Engineering XXII 105 M Mehl, M Bischoff, M Schäfer (eds.), Recent Trends in Computational Engineering – CE2014 Optimization, Uncertainty, Parallel Algorithms, Coupled and Complex Problems 106 R.M Kirby, M Berzins, J.S Hesthaven (eds.), Spectral and High Order Methods for Partial Differential Equations – ICOSAHOM’14 107 B Jüttler, B Simeon (eds.), Isogeometric Analysis and Applications 2014 108 P Knobloch (ed.), Boundary and Interior Layers, Computational and Asymptotic Methods – BAIL 2014 109 J Garcke, D Pflüger (eds.), Sparse Grids and Applications – Stuttgart 2014 110 H.P Langtangen, Finite Difference Computing with Exponential Decay Models 111 A Tveito, G.T Lines, Computing Characterizations of Drugs for Ion Channels and Receptors Using Markov Models For further information on these books please have a look at our mathematics catalogue at the following URL: www.springer.com/series/3527 ... meant for Python to read and execute, but rather for a human that reads the code and tries to understand what is going on Therefore, one rule in Python says that whenever Python encounters 1.2 A Python. .. invisible to us, with information on how to format the text (e.g., the font size and type) Such extra information is necessary for the text to be nicely formatted for the human eye Python, however,... Roose Tamar Schlick 15 More information about this series at http://www.springer.com/series/5151 Svein Linge Hans Petter Langtangen Programming for Computations – Python A Gentle Introduction