A primer on scientific programming with python

736 149 0
A primer on scientific programming with python

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Texts in Computational Science and Engineering Editors Timothy J Barth Michael Griebel David E Keyes Risto M Nieminen Dirk Roose Tamar Schlick Hans Petter Langtangen A Primer on Scientific Programming with Python 2nd Edition 123 Hans Petter Langtangen Simula Research Laboratory Martin Linges vei 17 1325 Lysaker, Fornebu Norway hpl@simula.no On leave from: Department of Informatics University of Oslo P.O Box 1080 Blindern 0316 Oslo, Norway http://folk.uio.no/hpl ISSN 1611-0994 ISBN 978-3-642-18365-2 e-ISBN 978-3-642-18366-9 DOI 10.1007/978-3-642-18366-9 Springer Heidelberg Dordrecht London New York Library of Congress Control Number: 2011925575 Mathematics Subject Classification (2000): 26-01, 34A05, 34A30, 34A34, 39-01, 40-01, 65D15, 65D25, 65D30, 68-01, 68N01, 68N19, 68N30, 70-01, 92D25, 97-04, 97U50 © Springer-Verlag Berlin Heidelberg 2009, 2011 This work is subject to copyright All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilm or in any other way, and storage in data banks Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer Violations are liable to prosecution under the German Copyright Law The use of general descriptive names, registered names, trademarks, 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 Cover design: deblik, Berlin Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com) Preface The aim of this book is to teach computer programming using examples from mathematics and the natural sciences We have chosen to use the Python programming language because it combines remarkable power with very clean, simple, and compact syntax Python is easy to learn and very well suited for an introduction to computer programming Python is also quite similar to Matlab and a good language for doing mathematical computing It is easy to combine Python with compiled languages, like Fortran, C, and C++, which are widely used languages for scientific computations A seamless integration of Python with Java is offered by a special version of Python called Jython The examples in this book integrate programming with applications to mathematics, physics, biology, and finance The reader is expected to have knowledge of basic one-variable calculus as taught in mathematics-intensive programs in high schools It is certainly an advantage to take a university calculus course in parallel, preferably containing both classical and numerical aspects of calculus Although not strictly required, a background in high school physics makes many of the examples more meaningful Many introductory programming books are quite compact and focus on listing functionality of a programming language However, learning to program is learning how to think as a programmer This book has its main focus on the thinking process, or equivalently: programming as a problem solving technique That is why most of the pages are devoted to case studies in programming, where we define a problem and explain how to create the corresponding program New constructions and programming styles (what we could call theory) is also usually introduced via examples Special attention is paid to verification of programs and to finding errors These topics are very demanding for mathematical software, because the unavoidable numerical approximation errors are possibly mixed with programming mistakes v vi By studying the many examples in the book, I hope readers will learn how to think right and thereby write programs in a quicker and more reliable way Remember, nobody can learn programming by just reading – one has to solve a large amount of exercises hands on The book is therefore full of exercises of various types: modifications of existing examples, completely new problems, or debugging of given programs To work with this book, I recommend to use Python version 2.7 (although version 2.6 will work for most of the material) For Chapters 5–9 and Appendices A–E you also need the NumPy, Matplotlib, SciTools packages There is a web page associated with this book, http://www.simula.no/intro-programming, which lists the software you need and explains briefly how to install it On this page, you will also find all the files associated with the program examples in this book Download book-examples.tar.gz, store this file in some folder of your choice, and unpack it using WinZip on Windows or the command tar xzf book-examples.tar.gz on Linux and Mac This unpacking yields a folder src with subfolders for the various chapters in the book Python version or 3? A common problem among Python programmers is to choose between version or 3, which at the time of this writing means choosing between version 2.7 and 3.1 The general recommendation is to go for version 3, but programs are then not compatible with version and vice versa There is still a problem that much useful mathematical software in Python has not yet been ported to version Therefore, scientific computing with Python still goes mostly with version A widely used strategy for software developers who want to write Python code that works with both versions, is to develop for v2.7, which is very close to v3.1, and then use the ranslation tool 2to3 to automatically translate the code to version 3.1 When using v2.7, one should employ the newest syntax and modules that make the differences beween version and very small This strategy is adopted in the present book Only two differences between version and are expected to be significant for the programs in the book: a/b implies float division in version if a and b are integers, and print ’Hello’ in version must be turned into a function call print(’Hello’) in version None of these differences should lead to any annoying problems when future readers study the book’s v2.7 examples, but program in version Anyway, running 2to3 on the example files generates the corresponding version code Contents Chapter introduces variables, objects, modules, and text formatting through examples concerning evaluation of mathematical formulas Chapter presents programming with while and for loops as well as with lists, including nested lists The next chapter deals with two other fundamental concepts in programming: functions and Preface Preface vii if-else tests Successful further reading of the book demands that Chapters 1–3 are digested How to read data into programs and deal with errors in input are the subjects of Chapter Chapter introduces arrays and array computing (including vectorization) and how this is used for plotting y = f (x) curves and making animation of curves Many of the examples in the first five chapters are strongly related Typically, formulas from the first chapter are used to produce tables of numbers in the second chapter Then the formulas are encapsulated in functions in the third chapter In the next chapter, the input to the functions are fetched from the command line, or from a question-answer dialog with the user, and validity checks of the input are added The formulas are then shown as graphs in Chapter After having studied Chapters 1- 5, the reader should have enough knowledge of programming to solve mathematical problems by “Matlab-style” programming Chapter explains how to work with files and text data Class programming, including user-defined types for mathematical computations (with overloaded operators), is introduced in Chapter Chapter deals with random numbers and statistical computing with applications to games and random walks Object-oriented programming, in the meaning of class hierarchies and inheritance, is the subject of Chapter The key examples here deal with building toolkits for numerical differentiation and integration as well as graphics Appendix A introduces mathematical modeling, using sequences and difference equations We also treat sound as a sequence Only programming concepts from Chapters 1–5 are used in this appendix, the aim being to consolidate basic programming knowledge and apply it to mathematical problems Some important mathematical topics are introduced via difference equations in a simple way: Newton’s method, Taylor series, inverse functions, and dynamical systems Appendix B deals with functions on a mesh, numerical differentiation, and numerical integration A simple introduction to ordinary differential equations and their numerical treatment is provided in Appendix C Appendix D shows how a complete project in physics can be solved by mathematical modeling, numerical methods, and programming elements from Chapters 1–5 This project is a good example on problem solving in computational science, where it is necessary to integrate physics, mathematics, numerics, and computer science How to create software for solving systems of ordinary differential equations, primarily using classes and object-oriented programming, is the subject of Appendix E The material in this appendix brings together many of the programming concepts from Chapters 1–9 in a mathematical setting and ends up with a flexible and general tool for solving differential equations viii Appendix F is devoted to the art of debugging, and in fact problem solving in general, while Appendix G deals with various more advanced technical topics Most of the examples and exercises in this book are quite compact and limited However, many of the exercises are related, and together they form larger projects in science, for example on Fourier Series (3.7, 4.18–4.20, 5.29, 5.30), Taylor series (3.21, 5.20, 5.27, A.16, A.17, 7.23), falling objects (E.5, E.6, E.7, E.25, E.26), oscillatory population growth (A.21, A.22, 6.25, 7.34, 7.35), analysis of web data (6.22, 6.28–6.30), graphics and animation (9.20–9.23), optimization and finance (A.23, 8.42, 8.43), statistics and probability (4.24–4.26, 8.22– 8.24), hazard games (8.8–8.13), random walk and statistical physics (8.33–8.40), noisy data analysis (8.44–8.48), numerical methods (5.13, 5.14, 7.9, A.12, 7.22, 9.16–9.18, E.15–E.23), building a calculus calculator (7.36, 7.37, 9.24, 9.25), and creating a toolkit for simulating vibrating engineering systems (E.30–E.37) Chapters 1–9 and Appendix E have, from 2007, formed the core of an introductory first-semester course on scientific programming, INF1100, at the University of Oslo (see below) Changes to the First Edition Besides numerous corrections of misprints, the second edition features a major reorganization of several chapters Chapter in the first edition, Basic Constructions, was a comprehensive chapter, both with respect to length and topics This chapter has therefore been split in two for the second edition: a new Chapter Loops and Lists and a new Chapter Functions and Branching A new Chapter 2.1.4 explicitly explains how to implement a summation expression by a loop, and later examples present alternative implementations All text and program files that used the getopt module to parse command-line options in the first edition now make use of the simpler and more flexible argparse module (new in Python v2.7/3.1) The material on curve plotting in Chapter has been thoroughly revised Now we give an introduction to plotting with Matplotlib as well as SciTools/Easyviz Both tools are very similar from a syntax point of view Much of the more detailed information on Easyviz plotting in the first edition has been removed, and the reader is directed to the online manuals for more details While the first edition almost exclusively used “star import” for convenience (e.g., from numpy import * and from scitools.std import *), the second edition tries to adhere to the standard import numpy as np However, in mathematical formulas that are to work with scalar and array variables, we not want an explicit prefix Avoiding the namespace prefixes is important for making formulas as close to the mathematical notation as possible as well as for making the transition Preface Preface ix from or to Matlab smooth The two import styles have different merits and applications The choice of style in various examples is carefully thought through in the second edition Chapter in the first edition, Sequences and Difference Equations, has now become Appendix A since the material is primarily about mathematical modeling, and no new basic programming concepts are introduced Chapter in the first edition, Files, Strings, and Dictionaries, has been substantially revised Now, Chapter 6.4, on downloading and interpreting data from web pages, have completely new examples Many of the exercises in this chapter are also reworked to fit with the new examples The material on differential equations in chapters on classes (Ch and in the first edition) has been extracted, reworked, slightly expanded, and placed in Appendix E This restructuring allows a more flexible treatment of differential equations, and parts of this important topic can be addressed right after Chapter 3, if desired Also, the changes make readers of Chapters and less disturbed with more difficult mathematical subjects To distinguish between Python’s random module and the one in numpy, we have in Chapter changed practice compared with the first edition Now random always refers to Python’s random module, while the random module in numpy is normally invoked as np.random (or occasionally as numpy.random) The associated software has been revised similarly Acknowledgments First, I want to express my thanks to Aslak Tveito for his enthusiastic role in the initiation of this book project and for writing Appendices B and C about numerical methods Without Aslak there would be no book Another key contributor is Ilmar Wilbers His extensive efforts with assisting the book project and help establishing the associated course (INF1100) at the University of Oslo are greatly appreciated Without Ilmar and his solutions to numerous technical problems the book would never have been completed Johannes H Ring also deserves a special acknowledgment for the development of the Easyviz graphics tool, which is much used throughout this book, and for his careful maintenance and support of software associated with this book Several people have helped to make substantial improvements of the text, the exercises, and the associated software infrastructure The author is thankful to Ingrid Eide, Arve Knudsen, Tobias Vidarssønn Langhoff, Solveig Masvie, H˚ akon Møller, Mathias Nedrebø, Marit Sandstad, Lars Storjord, Fredrik Heffer Valdmanis, and Torkil Vederhus for their contributions Hakon Adler is greatly acknowledged for his careful reading of various versions of the manuscript The pro- G.6 Evaluating Program Efficiency in a specific function, while cumtime reflects the total time spent in the function and all the functions it calls The CPU time of a Python program typically increases with a factor of about five when run under the administration of the profile module Nevertheless, the relative CPU time among the functions are probably not much affected by the profiler overhead 691 References [1] D Beazley Python Essential Reference SAMS, 2nd edition, 2001 [2] J E Grayson Python and Tkinter Programming Manning, 2000 [3] D Harms and K McDonald The Quick Python Book Manning, 1999 [4] D E Knuth Theory and practice EATCS Bull., 27:14–21, 1985 [5] H P Langtangen Python Scripting for Computational Science, volume of Texts in Computational Science and Engineering Springer, third edition, 2009 [6] L S Lerner Physics for Scientists and Engineers Jones and Barlett, 1996 [7] M Lutz Programming Python O’Reilly, second edition, 2001 [8] M Lutz and D Ascher Learning Python O’Reilly, 1999 [9] A Martelli Python in a Nutshell O’Reilly, 2003 [10] J D Murray Mathematical Biology I: An Introduction Springer, 3rd edition, 2007 [11] F M White Fluid Mechanics McGraw-Hill, 2nd edition, 1986 693 Index **kwargs, 686 *=, 54 *args, 683 +=, 54 -=, 54 /=, 54 \n, 13 allocate, 185 animate, 413 API, 345 aplotter (from scitools), 203 append (list), 58 application, 14 application programming interface, 345 argparse module, 141 array (from numpy), 184 array (datatype), 184 array computing, 184 array shape, 216, 217 array slicing, 185 asarray (from numpy), 214 attribute (class), 310 average, 380 backend (Easyviz), 195, 198 base class, 438 bin (histogram), 378 binomial distribution, 175 bits, 249 blank lines in files, 269 blanks, 17 body of a function, 92 boolean expressions, 55 break, 246 bytes, 249 callable objects, 325 callback function, 587 check an object’s type, 28, 215, 346, 441 check file/folder existence (in Python), 682 class hierarchy, 437 class relationship derived class, 438 has-a, 442 inheritance, 438 is-a, 442 subclass, 438 superclass, 438 closure, 456 cmath module, 33 command-line arguments, 137 commands module, 682 comments, 10 comparing floating-point numbers, 87 objects, 87 real numbers, 87 complex numbers, 31 concatenate (from numpy), 517 console (terminal) window, 695 696 constructor (class), 309 convergence rate, 492, 641 convert program, 412 copy files (in Python), 682 copy folders (in Python), 682 CPU time measurements, 688 cumulative sum, 426 curve plotting, 188 datetime module, 500, 689 debugger tour, 655 del, 58 delete files (in Python), 202, 369, 682 delete folders (in Python), 682 derived class, 438 dictionary, 252 comprehensions, 256 functionality, 290 nested, 258 difference equations, 498 nonlinear, 514 differential equations, 561, 603, 604, 613 dir function, 350 directory, 1, 4, 681 doc strings, 103 dtype, 214 duck typing, 348 dynamic binding, 449 dynamic typing, 347 editor, efficiency, 688 efficiency measure, 405 elapsed time, 688 enumerate function, 65, 366 environment variables, 681 eval function, 131, 450 event loop, 150 except, 143 Exception, 147 exceptions, 143 execute programs (from Python), 682 execute Python program, 7, 29, 673 expression, 16 factorial, 56 Index factorial function, 120 factory function, 451 find (string method), 266 first-order ODEs, 570 float_eq, 87 Forward Euler scheme, 606 Fourier series, 118 function arguments keyword, 101 named, 101 positional, 101 function body, 92 function header, 92 function inside function, 624 functional programming, 456 Gaussian function, 45 glob.glob function, 369, 681 global, 94 globals function, 93, 211, 592 grid, 530 has-a class relationship, 442 Heaviside function, 122 heterogeneous lists, 183 histogram (normalized), 378 Idle, immutable objects, 254, 335 in-place array arithmetics, 213 IndexError, 144, 145 information hiding, 345 initial condition, 498, 562, 582 input (data), 17 insert (list), 58 instance (class), 310 integer random numbers, 382 interactive sessions IPython, 29 session recording (logging), 46 standard Python shell, 26 interpolation, 231 interval arithmetics, 355 IPython, 29 is, 100 is-a class relationship, 442 Index isdigit (string method), 268 isinstance function, 75, 215, 346, 441 isspace (string method), 268 join (string method), 269 keys (dictionaries), 253 keyword arguments, 101, 683 Lagrange’s interpolation formula, 231 lambda functions, 107, 110 least squares approximation, 295 len (list), 58 line break, 13 linspace (from numpy), 185, 216 list comprehension, 65, 68 list files (in Python), 681 list functionality, 75 list, nested, 66 lists, 57 logical expressions, 55 loops, 52 lower (string method), 268 lstrip (string method), 269 Mac OS X, 18 main program, 106 make a folder (in Python), 681 making graphs, 188 making movie, 412 math module, 23 mean, 380 mean (from numpy), 381, 415 measure time in programs, 405 mesh, 530 method (class), 60 method (in class), 310 mod function, 115, 381 module folders, 159 modules, 151 Monte Carlo integration, 401 Monte Carlo simulation, 391 move to a folder (in Python), 681 multiple inheritance, 491 mutable objects, 254, 335 named arguments, 101 697 NameError, 145 namespace, 318 nested dictionaries, 258 nested lists, 67 nested loops, 72 newline character (line break), 13 Newton’s method, 327, 509 None, 100 nonlinear difference equations, 514 normal (from numpy.random), 382 normally distributed random numbers, 381 not, 55 np prefix (numpy), 184 np.array function, 184 np.linspace function, 185 np.zeros function, 184 Numerical Python, 184 NumPy, 184 numpy, 184 numpy.lib.scimath module, 33 object-based programming, 437 object-oriented programming, 437 objects, 20 ODE, 561, 603 operating system (OS), 18 optimization of Python code, 690 option-value pairs (command line), 140 OrderedDict class, 254 ordinary differential equations, 561, 603, 604 os module, 681 os.chdir function, 681 os.listdir function, 682 os.makedirs function, 681 os.mkdir function, 681 os.pardir, 159 os.path.isdir function, 682 os.path.isfile function, 682 os.path.join function, 159, 681 os.path.split function, 683 os.remove function, 202, 369, 682 os.rename function, 681 os.system function, 682 oscillating systems, 570, 577, 584, 629 698 output (data), 17 overloading (of methods), 460 parent class, 438 pass, 345 plot (from scitools), 195 plotting, 188 Poisson distribution, 176 polymorphism, 460 positional arguments, 101, 683 pprint.pformat, 69 pprint.pprint, 68 pprint2 (from scitools), 68 pretty print, 68 private attributes (class), 345 probability, 390 profiler.py, 690 profiling, 690 protected attributes (class), 335, 345 pydoc program, 80 pyreport program, 42, 233 r_ (array creation), 216 raise, 147 randint (from numpy.random), 410 randn (from numpy.random), 382 random (from numpy.random), 379 random (from numpy), 379 random module, 376 random numbers, 375 histogram, 378 integers, 382 integration, 401 Monte Carlo simulation, 391 normal distribution, 381 random walk, 406 statistics, 380 uniform distribution, 377 vectorization, 379 random walk, 406 random.normalvariate function, 382 random_integers (from numpy.random), 410 raw_input function, 130 refactoring, 167 remove files (in Python), 202, 369, 682 remove folders (in Python), 682 Index rename file/folder (in Python), 681 replace (string method), 267 resolution (mesh), 530 round function, 29 round-off errors, 25 rounding float to integer, 29 rstrip (string method), 269 run programs (from Python), 682 run Python program, 7, 29, 673 scalar (math quantity), 180 scalar code, 187 scalar differential equation, 604 scalar differential equations, 570 scalar function, 604 scaling, 505 scitools.pprint2 module, 68 scitools.pprint2.pprint, 69 scitools.std, 194 search for module files, 159 Secant method, 525 second-order ODEs, 570, 581, 629 seed, 376 sequence (data type), 76 sequence (mathematical), 497 shape (of an array), 216, 217 shutil.copy function, 682 shutil.copytree function, 682 shutil.rmtree function, 682 notation, 76 slicing, 69, 266 sort (list), 123 source code, 14 special methods (in classes), 324 split (string method), 267 split filename, 683 spread of a disease (model), 573 standard deviation, 380 standard error, 282 standard input, 281 standard output, 281 statements, 15 static class attributes, 351 static class methods, 352 static class variables, 351 Index 699 static typing, 347 std (from numpy), 381, 415 str2obj (from scitools), 160 string, 11 case change, 268 joining list elements, 269 searching, 266 splitting, 267 stripping leading/trailing blanks, 269 substitution, 267 substrings, 266 testing for number, 268 string slicing, 266 StringFunction (from scitools), 136 strip (string method), 269 strong typing, 347 subarrays, 185 subclass, 438 sublist, 69 subprocess module, 682 substitution (in text), 267 substrings, 266 sum (from numpy), 384 superclass, 438 syntax, 17 SyntaxError, 145 sys module, 137 sys.argv, 137 sys.exit function, 142 sys.path, 159 sys.stderr, 283 sys.stdin, 281 sys.stdout, 281 system time, 688 systems of differential equations, 570, 613 timing utilities, 688 triple-quoted strings, 13 try, 143 tuples, 73 type function, 28 type conversion, 28 TypeError, 146 terminal window, test block (in module files), 153 time CPU, 688 elapsed, 688 system, 688 user, 688 time module, 87, 111, 405, 407, 688 timeit module, 689 xrange function, 83, 186, 384 UML class diagram, 309 uniform (from numpy.random), 379 uniformly distributed random numbers, 377 Unix, 18 upper (string method), 268 user (of a program), 18 user time, 688 user-defined datatype (class), 310 using a debugger, 655 _v1 (version numbering), 19 ValueError, 144, 145 var (from numpy), 381, 415 variable no of function arguments, 683 variance, 380 vector computing, 179 vectorization, 184, 186 vectorized drawing of random numbers, 379 vectors, 178 weak typing, 347 whitespace, 17, 268 widgets, 149 Windows, 18 wrap2callable function, 365 wrapper code, 329 ZeroDivisionError, 145 zeros (from numpy), 184 zip function, 66 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: http://www.springer.com/authors/book+authors?SGWID= 0-154102-12-417900-0 (for monographs, textbooks and similar) 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 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 and Department of Applied Physics and Applied Mathematics Columbia University 500 W 120 th Street New York, NY 10027, USA kd2112@columbia.edu Risto M Nieminen Department of Applied Physics Aalto University School of Science and Technology 00076 Aalto, Finland risto.nieminen@tkk.fi Dirk Roose Department of Computer Science Katholieke Universiteit Leuven Celestijnenlaan 200A 3001 Leuven-Heverlee, Belgium dirk.roose@cs.kuleuven.be 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 Editor for Computational Science and Engineering at Springer: Martin Peters Springer-Verlag Mathematics Editorial IV Tiergartenstrasse 17 69121 Heidelberg, Germany martin.peters@springer.com 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 3rd 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 2nd Edition A Tveito, H P Langtangen, B F Nielsen, X Cai, Elements of Scientific Computing B Gustafsson, Fundamentals of Scientific Computing 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 PDE-Constrained 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 Jean-Claude 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 Lisbona (eds.), BAIL 2010- Boundary and Interior Layers, Computational and Asymptotic Methods For further information on these books please have a look at our mathematics catalogue at the following URL: www.springer.com/series/3527 ... Make a class for drawing an arrow Make a class for drawing a person Animate a person with waving hands Make a class for drawing a car Make... mathematical formulas that are to work with scalar and array variables, we not want an explicit prefix Avoiding the namespace prefixes is important for making formulas as close to the mathematical... Python with compiled languages, like Fortran, C, and C++, which are widely used languages for scientific computations A seamless integration of Python with Java is offered by a special version

Ngày đăng: 19/04/2019, 08:59

Từ khóa liên quan

Mục lục

  • Cover

  • Texts in Computational Science and Engineering 6

  • A Primer on Scientific Programming with Python, 2nd Edition

  • ISBN 9783642183652

  • Preface

  • Contents

    • List of Exercises

    • 1. Computing with Formulas

      • 1.1 The First Programming Encounter: A Formula

        • 1.1.1 Using a Program as a Calculator

        • 1.1.2 About Programs and Programming

        • 1.1.3 Tools for Writing Programs

        • 1.1.4 Using Idle to Write the Program

        • 1.1.5 How to Run the Program

        • 1.1.6 Verifying the Result

        • 1.1.7 Using Variables

        • 1.1.8 Names of Variables

        • 1.1.9 Reserved Words in Python

        • 1.1.10 Comments

        • 1.1.11 Formatting Text and Numbers

        • 1.2 Computer Science Glossary

        • 1.3 Another Formula: Celsius-Fahrenheit Conversion

          • 1.3.1 Potential Error: Integer Division

          • 1.3.2 Objects in Python

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan