Dr. Dobb's Journal July 2002
When I look for books on mathematics, I expect them to include theory, some numerical applications of the theory with error estimates, and references. If it's a textbook, it needs to have end-of-chapter exercises, along with the answers. If the book also involves C++, it should be modern (post 1998), as standard as possible, and use the library and templates. It might take a shot at using std::valarray<>, but if not, it will at least use std::vector<> for the pedestrian tasks. Finally, it will provide plug-in sample code from a CD-ROM or web site, where "sample" is to be read "cheap code that I don't have to write."
Oliver Aberth is an emeritus professor at the Texas A&M University Mathematics Department, and his Precise Numerical Methods Using C++ is the more "mathy" of the books I examine here. It's a good intro to numerical work that concentrates first on the standard mathematical functions, viz., sin(), cos(), and so on, and then moves on to derivatives, integrals, finding zeroes, optimization, and linear algebra.
I particularly liked the idea of solvable and nonsolvable problems in numerical analysis. As an example of a nonsolvable problem: For any real number a, decide whether or not a equals 0. Notwithstanding Seymour Cray's hardwiring of 0.0 into his machines (he knew that there was a zero), the ramifications of Aberth's idea is that floating-point calculations should be done to a specified precision, and that computational problems should be stated such that nonsolvability is avoided. The book uses range arithmetic to avoid the difficulty, but such approaches seem too slow for production number-crunching work.
If you teach from this book, you'll want to read more than a day ahead so you can prepare exercises for your students there are none suggested.
The source code accompanying Precise Numerical Methods Using C++ consists of 21,834 lines of C++ on a CD-ROM that's bundled with the book. The same code can be downloaded from the author's web site, the only difference being an additional TEX document file. The code introduces classes for rational arithmetic that allow for long integers. The format of some modules leads me to believe that C++ is not the author's native tongue: Files are "chained" like those ancient Basic programs on paper tape; the last lines in some files are #include "someotherfile.cpp". I spent a couple of hours trying to get the code to compile with Borland C++Builder 5 to no avail, and finally gave up. You will need some patience to deduce the structure of the code: Namespaces aren't used, the Standard Library complex and string classes are rewritten, and the C++ memory allocation system is replaced. In short, this book is a keeper for the mathematics, but fails the code test.
An Introduction to Numerical Methods in C++, by Brian Hilton Flowers, is a revision of the 1995 edition of the book. Lord Flowers, fellow and former Rector of the Imperial College at the University of London, is a man of some curiosity, and likes to get his hands dirty finding out how things work. His chosen subset of C++ omits virtual functions (and hence polymorphism) and exceptions. The Standard Library is almost completely ignored; <math.h> is as far as it goes. Templates are used in the generation of a linked list class. For the mathematical details, you are often referred to the text by K.E. Atkinson, so Flowers's text is more of an applied than theoretical treatment.
The first two chapters define the C++ language subset to be used. Thence the text discusses typical introductory numerical material: errors, finding zeroes, differential equations, matrix operations, and so on. A class for rational arithmetic is also presented, but it is limited to the accuracy of long. Vector and matrix classes are also presented, but the destructor is incorrect.
Flowers's chosen implementation is Borland's DOS-based Turbo C++, which is, at this time, far from the "standard." On the other hand, this choice is what I would expect from a "hobbyist programmer" someone who works alone, and as Flowers mentions in the Preface "someone who wants to know how things work, rather than simply using a black box." Since the reference is to Turbo C++PL Edition 1, the text code is very close to C. The code is copious in the text, but it is old code. There is no CD-ROM or web site.
DDJ