Skip to main content
main-content

Über dieses Buch

The book serves as a first introduction to computer programming of scientific applications, using the high-level Python language. The exposition is example- and problem-oriented, where the applications are taken from mathematics, numerical calculus, statistics, physics, biology, and finance. The book teaches "Matlab-style" and procedural programming as well as object-oriented programming. High school mathematics is a required background, and it is advantageous to study classical and numerical one-variable calculus in parallel with reading this book. Besides learning how to program computers, the reader will also learn how to solve mathematical problems, arising in various branches of science and engineering, with the aid of numerical methods and programming. By blending programming, mathematics and scientific applications, the book lays a solid foundation for practicing computational science.

Inhaltsverzeichnis

Frontmatter

1. Computing with Formulas

Abstract
Our first examples on computer programming involve programs that evaluate mathematical formulas. You will learn how to write and run a Python program, how to work with variables, how to compute with mathematical functions such as e x and sinx, and how to use Python for interactive calculations.
Hans Petter Langtangen

2. Loops and Lists

Abstract
This chapter shows how repetitive tasks in a program can be automated by loops. We also introduce list objects for storing and processing collections of data with a specific order. Loops and lists, together with functions and if-tests from Chapter 3, lay the fundamental programming foundation for the rest of the book.
Hans Petter Langtangen

3. Functions and Branching

Abstract
This chapter introduces and exemplifies two fundamental and extremely useful concepts in Python programming: user-defined functions and branching of program flow (“if” tests).
Hans Petter Langtangen

4. Input Data and Error Handling

Abstract
This chapter exemplifies various techniques for reading data into a program. Most emphasis is put on reading data from the command line. We introduce the concept of exceptions for dealing with invalid input or erroneous conditions in a program. The chapter also explains how to organize your Python code in your own modules (libraries).
Hans Petter Langtangen

5. Array Computing and Curve Plotting

Abstract
Arrays represent perhaps the most useful object in numerical computing. This chapter gives a brief introduction to arrays, how they are created and what they can be used for. Array computing usually ends up with a lot of numbers, which are hard to understand unless they are visualized in a proper way. This chapter concentrates on visualizing one-dimensional array data as curves of the form y=f(x). We describe Python tools for plotting such curves.
Hans Petter Langtangen

6. Files, Strings, and Dictionaries

Abstract
Files are used for permanent storage of information on a computer. This chapter tells you how Python programs can access information in files and also how to create new files. We show how file information can be mapped on to data in a program, and for this purpose dictionaries are particularly convenient. Interpreting and extracting data from files often imply sophisticated operations on text. We demonstrate how this is done by using the rich functionality of Python strings. There are also examples showing how to read World Wide Web pages as files and extract information from them.
Hans Petter Langtangen

7. Introduction to Classes

Abstract
A class packs a set of data (variables) together with a set of functions operating on the data. This allows the programmer to compose new objects with content and behavior designed for the problem at hand. Most of the mathematical computations in this book can easily be coded without using classes, but classes often offer more elegant solutions or code that is easier to extend at a later stage. This chapter gives an introduction to the class concept in Python with emphasis on applications to numerical computing. We cover in particular constructions that allow user-designed objects to enter arithmetic expressions.
Hans Petter Langtangen

8. Random Numbers and Simple Games

Abstract
Random numbers have many applications in science and computer programming, especially when there are significant uncertainties in a phenomenon of interest. The purpose of this chapter is to look at some practical problems involving random numbers and learn how to program with such numbers. We shall make several games and also look into how random numbers can be used in physics. A particularly important topic is Monte Carlo simulation for estimating probabilities.
Hans Petter Langtangen

9. Object-Oriented Programming

Abstract
This chapter introduces object-oriented programming in Python, in the meaning of designing and implementing class hierarchies. Subclasses inherit data and functionality from superclasses and tailor data structures and methods to the needs in the subclasses. We present several examples on how to utilize object-oriented programming for numerical computing. There is also a more comprehensive example on object-oriented implementation of a drawing program, where recursive traversal of tree structures is illustrated.
Hans Petter Langtangen

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise