Book contents
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
10 - Robust Implementation of Several Simple Algorithms
Published online by Cambridge University Press: 05 July 2012
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
Summary
Computer programs sometimes exhibit unexpected behavior. They may function correctly for years and then, suddenly, they fail. Computer programs that solve numerical problems are no exception. The unexpected behavior, perhaps a division by zero, is often the consequence of input that does not conform to the hidden assumptions and restrictions ofthe program. For example, a Gauss elimination procedure to solve systems oflinear equations requires the matrix to be non-singular. If the matrix is numerically singular or ill-conditioned, the mathematical problem of solving the system is still well-defined, but the numerical counterpart may have a hard time delivering a decent approximation to the exact solution. The conclusion that the matrix is ill-conditioned is only drawn while solving the system.
Sometimes there is a mismatch between the specification and the actual implementation. The part of the program that reads the data accepts input that conforms to the specification, but there are a few tacit assumptions, like line-endings for a text file containing the coefficients of the matrix for the Gauss elimination program.
Subtle bugs may lurk in an otherwise well-written and well-behaved program. Can you avoid them altogether? The unsatisfying answer is probably not, but that does not mean you cannot make an effort to understand the source of these bugs. That is the intention of this chapter – to examine three simple mathematical algorithms and their implementation in Fortran.
The idea is that a straightforward implementation contains all manners of hidden assumptions about the problem that needs solving.
- Type
- Chapter
- Information
- Modern Fortran in Practice , pp. 135 - 162Publisher: Cambridge University PressPrint publication year: 2012