Python Scripting for Computational Science (3rd ed.) [Langtangen 2009-02-13].pdf

(6095 KB) Pobierz
Texts in Computational Science
and Engineering
Editors
Timothy J. Barth
Michael Griebel
David E. Keyes
Risto M. Nieminen
Dirk Roose
Tamar Schlick
3
Hans Petter Langtangen
Python Scripting
for Computational
Science
Third Edition
With 62 Figures
123
Hans Petter Langtangen
Simula Research Laboratory
Martin Linges vei 17, Fornebu
P.O. Box 134
1325 Lysaker, 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
The author of this book has received financial support from the NFF – Norsk faglitterær
forfatter- og oversetterforening.
ISBN 978-3-540-73915-9
DOI 10.1007/978-3-540-73916-6
e-ISBN 978-3-540-73916-6
Texts in Computational Science and Engineering ISSN 1611-0994
Library of Congress Control Number: 2007940499
Mathematics Subject Classification (2000): 65Y99, 68N01, 68N15, 68N19, 68N30, 97U50, 97U70
© 2008, 2006, 2004 Springer-Verlag Berlin Heidelberg
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, broad-
casting, 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.
Typesetting: by the author using a Springer TEX macro package
Cover design: WMX Design GmbH, Heidelberg
Production: LE-TEX Jelonek, Schmidt & Vöckler GbR, Leipzig
Printed on acid-free paper
9 87654321
springer.com
Preface to the Third Edition
Numerous readers of the second edition have notified me about misprints and
possible improvements of the text and the associated computer codes. The
resulting modifications have been incorporated in this new edition and its
accompanying software.
The major change between the second and third editions, however, is
caused by the new implementation of Numerical Python, now called
numpy
.
The new
numpy
package encourages a slightly different syntax compared to
the old
Numeric
implementation, which was used in the previous editions.
Since Numerical Python functionality appears in a lot of places in the book,
there are hence a huge number of updates to the new suggested
numpy
syntax,
especially in Chapters 4, 9, and 10.
The second edition was based on Python version 2.3, while the third
edition contains updates for version 2.5. Recent Python features, such as
generator expressions (Chapter 8.9.4), Ctypes for interfacing shared libraries
in C (Chapter 5.2.2), the
with
statement (Chapter 3.1.4), and the
subprocess
module for running external processes (Chapter 3.1.3) have been exemplified
to make the reader aware of new tools. Regarding Chapter 3.1.3,
os.system
is not used in the book anymore, instead we recommend the
commands
or
subprocess
modules.
Chapter 4.4.4 is new and gives a taste of symbolic mathematics in Python.
Chapters 5 and 10 have been extended with new material. For example,
F2PY and the Instant tool are very convenient for interfacing C code, and
this topic is treated in detail in Chapters 5.2.2, 10.1.1, and 10.1.2 in the
new edition. Installation of Python itself and the many add-on modules have
become increasingly simpler over the years with
setup.py
scripts, which has
made it natural to simplify the descriptions in Appendix A.
The
py4cs
package with software tools associated with this book has un-
dergone a major revision and extension, and the package is now maintained
under the name
scitools
and distributed separately. The name
py4cs
is still
offered as a nickname for
scitools
to make old scripts work. The new
scitools
package is backward compatible with
py4cs
from the second edition.
Several people has helped me with preparing the new edition. In par-
ticular, the substantial efforts of Pearu Peterson, Ilmar Wilbers, Johannes
H. Ring, and Rolv E. Bredesen are highly appreciated.
The Springer staff has, as always, been a great pleasure to work with.
Special thanks go to Martin Peters, Thanh-Ha Le Thi, and Andrea K¨hler
o
for their extensive help with this and other book projects.
Oslo, September 2007
Hans Petter Langtangen
Zgłoś jeśli naruszono regulamin