A Primer on Scientific Programming with Python
Abstract
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 expressive 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.
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. Particular 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.
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.