C++ and Object Oriented Numeric Computing for Scientists and Engineers
(A Chinese translation of the book was published by
People's Post and Telecommunications Publishing House, Beijing, China, 2002)
This book intends to be an easy, concise, but rather complete
introduction to the ISO/ANSI C++ language, with applications to
object oriented numeric computation for students and professionals
in science and engineering. It introduces concepts, techniques,
and standard libraries of C++ in a manner that is easy to understand
using examples such as vectors, matrices, complex numbers, and
which are familiar and useful to a typical student or professonal
in science and engineering.
Besides introducing basic and advanced features of C++, the book
contains an introduction and C++ programs for many numeric
methods such as polynomial interpolation, numerical integration,
direct and iterative algorithms for solving systems of linear equations
in real and complex domains, methods for solving nonlinear equations,
ordinary and partial differential equations
with real and complex coefficients. These methods are
fundamental in scientific and engineering computing.
This book gives numerous examples and techniques on how to reduce (C and Fortran
style) run-time overhead and improve program efficiency and elegancy.
Such techniques include
function objects, deferred evaluation for operator overloading, expression
templates, template metaprograms, and replacing certain virtual functions
It also introduces tools
on how to manage source files, create libraries, and debug and profile
The book can be used as a textbook for students in science and
engineering and a reference book
for experienced scientific C++ programmers.
C++, What a Programming Language Should Be!
C++'s object oriented and general programming features enable the
programmer to write few codes and support an evolving process of
code development. For example,
One version of C++ program of preconditioned conjugate gradient and GMRES
methods can be used for full (storing every entry of a matrix), banded
(zero entries outside of a band along the main diagonal are not stored to
save memory), and sparse (only non-zero entries of a matrix are stroed to
save memory) matrices, and for real and complex single, double,
long double precisions.
It would require 18 versions in Fortran 77 or Fortan 90.
Six versions of C code may do it, but will be much less efficient.
If one later decides to add a symmetric (only store lower triangular
part of a matrix to save memory) matrix storage format, then 6 more
versions of Fortan code (for real, complex, and single, double, long double
precisions) need be added. The same C++ program for conjugat gradient
and GMRES methods still can handle this situation without any change.
C++ code of preconditioned conjugat gradient and GMRES methods
are given in Chapter 11 (last chapter) of the book, which work
for full, banded, sparse, and other matrices in real and complex
C++ has features (compound assignment operators, templates,
function objects, high performance computing library such as valarray) that
can be faster than Fortran 77 and C.
For example, passing a pointer to a function as an argument to another
function can be avoided in many C++ programs by using templates, which
can improve the speed of execution by a factor of 2 on many compilers
Running time comparisons with C and Fortran style function
passing are done in various places of the book.
C++ provides standard libraries on data structures such as
vector, set, list, map, stack,
queue, valarray, and on algorithms such as sort() and find().
They come with any standard C++ compiler and
can be much more efficient, convenient, and portable than codes written a
typical or expert programmer. For example, using these libraries,
it is much easier to write finite element programs on unstructured grids and
grid generation programs in C++ than in Fortran and C.
A disussion of these standard libraries and algorithms are given in
various chapters of the book.
C++ programs resemble numerical algorithms more than
in Fortran or C. For exmaple, we can write v = v1 + v2 for vector addition
and v1 = m*v2 for (sparse, banded, or full) matrix-vector multiplication.
The C++ code for the conjugate gradient method (for solving linear systems of
algebraic equations) looks very much like the algorithm, which enhances
readibility and maintainability. Besides, such operator overloading from
built-in types to user-defined types can be done without sacrifice of
run-time speed (see Chapter 6 of the book).
C++ Books and Resources
The C++ Programming Language (Third Edition),
Addison-Wesley, 1997, ISBN 0-201-88954-4.
C++ Solutions Addison-Wesley,1998, ISBN 0-201-30965-3. (This book
provides answers to Bjarne Stroustrup's book above)
Lippman, Stanley B. and Josee Lajoie,
C++ Primer, 4rd ed. Reading, Mass. Addison-Wesley, 2005.
ISO/ANSI C++ Standards
ANSI C info