This website is associated with the book Programming Projects in C SIAM, 2014
The URL
〈http://www.siam.org/books/cs13〉
redirects here
What readers are saying about this book…
Computing Reviews #1505–0335, May 15, 2015, pp. 267–268
This text is extraordinary in many respects. In terms of
precision and detail, it benefits from Professor Rostamian’s
mathematical background as well as from his deep appreciation
for a wide range of scientific and engineering applications. The
book's title may mislead some, as almost everything presented
has real substance and is not for the timid. There is an
assumption that the student is comfortable with programming,
preferably using the C language, and with linear algebra and
mathematical analysis at a relatively sophisticated level. The
programming projects are from the physical sciences and related
engineering disciplines. Someone who completes a course based
on this text will have significant skills.
There are two parts: a relatively brief set of chapters to
build a common background in C and its operating environment,
followed by the many projects. With some variation, the project
chapters are in pairs to give background and a starter project,
followed by a more sophisticated application that builds on its
predecessor. Some of the projects also help build a library of
useful routines for several later projects. To give a flavor
of the range of projects, a few are sparse matrices, Haar
wavelets, image analysis, evolution of species, Nelder–Mead
downhill simplex, trusses, finite differences for the heat
equation, porous medium, Gaussian quadrature, triangulation and
integration on triangles, and the finite element method. C code
segments, illustrative figures, and data displays are given
when helpful. The bibliography lists 84 key publications for
delving deeper and includes the page number of this text where
that publication is cited (a very nice touch).
For those practitioners of scientific computation in a C and
Unix/Linux environment, it has much to offer as either a text
or a reference. Those more interested in computational biology
will not find as much here as those interested in the physical
science side of things. Although this is a particularly good
treatment of its target—detailed programming at a fairly low
level with strong control—it feels a little dated as many
choose a language with a full range of modern features (for
example, C++) or a high-level software system and environment
(for example, MATLAB) for scientific computation. Even so,
Rostamian's text is a valuable contribution to the scientific
computing literature and to developing new practitioners.
I have recently come across a fantastic book published
by SIAM. It’s titled “Programming projects in C for
Students of Engineering, Science and Mathematics” by Rouben
Rostamian. I will be posting some of my codes for projects
from this book as well. This book has been an excellent
resource for learning C. I would highly recommend it to the
other engineering undergraduates who would like to develop
their programming skills beyond what is required in a typical
undergraduate degree.
David's Blog, May 25, 2015
It's good to see that some new C programming books still get published.
These days they are quite rare, but it's great to see when one does appear.
At the moment I am enjoying this one:
Programming projects in C for Students of Engineering, Science and Mathematics.
I bought mine when I found a copy whilst browsing the
Cambridge University Press bookshop. As I flipped through the
book in the store I stumbled on the chapter about makefiles,
and realised that it was going to be good there and then. I
liked the iterative way that the makefiles were presented—as
a series of layered enhancements.
It even motivated me to go away and improve some of my
makefiles, which were already working fine… but could be
done even better. The advantage is that now I have more of a
chance to reuse them on other projects.
But now, I've had an opportunity to read more of this book,
and have really enjoyed it. There are lots of little gems
tucked away which would be worth taking note of. I reckon that
most C programmers would find something interesting in this
book, not just developers working in the fields of science,
mathematics and engineering.
The C programming language has been around for a long time now,
I think that even the author admitted to using certain blocks
of code for 30 years or so. But for me, that's part of the
beauty of it. There are not many languages where you could
have written a block of code decades ago and find that it's
just as good today.
If you're doing C programming and are curious to see how
somebody else uses the language then you'll probably enjoy
reading this book.
This book is written for graduate and advanced undergraduate
students of sciences, engineering, and mathematics as a tutorial
on how to think about, organize, and implement programs in
scientific computing. The goal is to provide an interesting
and instructive set of
well-developed programming projects
(problems), each of which begins with the presentation of a
problem and an algorithm for solving it and implementing the
algorithm in C, and compiling and testing the results. The
ultimate goal of the author, however, is pedagogy, not
programming per se. This book aims to bridge a gap between
what students learn in an undergraduate course dedicated
to programming and what is required to implement algorithms
of scientific computing in a coherent fashion. The book is
organized in two parts with 25 chapters. Part I, consisting of
Chapters 1–6, provides all necessary information for Part
II, whose chapters consist of individual projects. Part II
consists of projects, one per chapter, on a diverse selection
of topics. Each topic begins with the presentation of a problem
and an algorithm. Every project comes with an outline that
shows how the program is broken into multiple files, and how
each file is broken into individual functions. This part is
definitely not intended for linear/sequential reading. A chart
on a flyleaf page shows the chapter interdependencies. There
is a good balance between providing too much versus too little
information on each project. The author has done a good job
on how to structure modular programs for scientific computing
applications while giving instructions in an engaging way. The
book will also be of interest to professionals who wish to
exercise their skills in programming mathematical algorithms
in C.
Valentina Dagiené
Vilnius
SIAM Reviews, vol. 57, no. 4, December 2015
This is a textbook for a scientific computing
course for graduate students and advanced
undergraduates. It can also be used for self
study. Why C? C is relatively old and well
established; it’s not this week’s fashionable
language. Compilers are
freely available for
every platform. C has been standardized.
C gives the programmer a great deal of
control, especially with respect to memory
management. C is a small language. What
are the drawbacks? Mainly the steep learning curve.
The author tells us in the preface
that his students generally have already had
a one-semester introduction to C or some
similar language. That would seem to be almost necessary,
as the learning curve would otherwise be too steep.
The book is in two parts. The short
first part consists of common background
information, including material about file
management, streams and the UNIX shell,
pointers and arrays, and the use of makefiles.
The second part, which is the heart of
the book, consists of the projects. The first
are quite simple and address common needs
such as memory allocation. The complexity
builds from there. The last two projects
produce finite element code for solving
elliptic PDE on unstructured triangular meshes.
Modularity and reuse of code are emphasized,
but that does not mean that the
projects have to be done strictly in order.
The dependencies are clearly specified in a
table. For example, to get to the two finite
element projects one would first have
to complete the projects on memory allocation,
dynamic allocation of vectors and matrices,
a data structure for sparse matrices,
UMFPACK for solving sparse linear systems,
two projects on numerical quadrature,
and triangulation with the Triangle
library. Another independent (except for
memory allocation) sequence of projects
progresses from Haar wavelets to image I/O
to image analysis. There is a fun project
that simulates the evolution of an asexually
reproducing species. (Sexual reproduction
would surely have been even more fun but
would also have made the programming task
much more difficult.) The evolution project
relies on earlier projects on random number
generation and linked lists. Other chapters
include the Nelder–Mead simplex method,
trusses, finite difference schemes for the heat
equation, and the porous medium equation.
This is quite a nice variety of topics.
The mathematics behind each project is
discussed, but not in great technical detail.
For example, the discussion of the Galerkin
method in the finite element chapters does
not mention Sobolev spaces. A lot of code
is included in the book, but there are no
complete programs. It is the student’s task
to understand each code fragment and figure
out how to put the pieces together to
make working code.
The author maintains a book website,
which provides additional resources.
The student who successfully works
through this book will have learned a great
deal about programming and will also have
been exposed to several important methods
for attacking scientific computing problems.
David S. Watkins
Washington State University
Table of Contents
Links marked [resources]
lead to pages containing notes, comments, and known errata, if any.
If you encounter other typos or errors of any nature, please let me know.
[Supplemental chapter] Neural networks for solving ODEs
[resources]
[Supplemental chapter] Neural networks for solving PDEs
[resources]
Appendix: Barycentric coordinates
Chapter 17: Simulated Evolution
Bugs (red dots) evolve into two distinct species in response to
environmental factors.
A region where food (green dots) is plentiful (near
the center) leads to the emergence of a sluggish species that
tends to stay in one place.
A region where food is scarce (away from the center) leads to the
emergence of a species that tends to move about a lot.
Chapter 18: The Nelder–Mead minimization algorithm
The Nelder–Mead algorithm is a gradient-free method
for minimization of functions of the type $f : R^n \to R$.
It works through a moving
and deforming adaptive simplex (a triangle in 2D) that “sniffs around” for
the location of the minimum.
Chapter 19: Large deformations of trusses
Our truss solver handles statically indeterminate trusses
with nonlinear elastic members and large
deformations (assuming that no buckling occurs).
Large deformations of a Pratt truss under variable load
large deformations of a cantilever truss under variable load
Chapters 26 & 27: A finite element solver
Our finite element implementation solves the elliptic PDE
$\nabla ( A \nabla u ) + f = 0$ over a polygonal domain
(possibly with holes) in $R^2$, subject to mixed Dirichlet and Neumann
boundary conditions. The functions $A$ and $f$ are given.
We partition the domain into an unstructured triangular mesh,
and approximate the solution $u$ by linear functions within
the triangular elements.
Example 1:
A sequence of solutions to the Poisson problem
$\nabla^2 u + 1 = 0$
on an L-shaped domain with zero
Dirichlet boundary data, and a progressively refined mesh:
Example 2:
The solution of the Poisson problem
$\nabla^2 u + f = 0$ on an annular domain, where $f(r,\theta) = \cos \theta\,$
in polar coordinates. The boundary conditions are $u=0$ on the outer boundary,
$\partial u/\partial n=0$ on the inner boundary:
Chapter 15: Image analysis through Haar wavelets
A grayscale image sample
The following sequence depicts a 512×512 grayscale image
at various levels of resolution.
Each image is constructed through a superposition Haar of wavelets.
The lowest resolution is made of merely 113 wavelets.
The highest resolution requires the superposition of 241,570
(about a quarter million!) wavelets.
A color image sample
The original 256×256 image was transformed via Haar wavelets.
Then the least significant coefficients were dropped and the
image was reconstructed with the remaining coefficients. The
relative L2 errors of truncation in the three
reconstructed images are 2, 3, and 6 percent. The information
from the original image retained are 10%, 5%, and 1%, respectively.
Original image
...with 10% of the original information
...with 5% of the original information
...with 1% of the original information
Chapters 20 & 21: Finite difference schemes for PDEs
We introduce various finite difference schemes for solving the initial/boundary value problem
of the heat equation
\begin{align}
&\frac{\partial u}{\partial t}
=
\frac{\partial^2 u}{\partial x^2},
&
&x \in (a,b), \; t > 0,
\\
&u(x,0) = u_0(x), && x \in (a,b),
\\
&u(a,t) = u_L(t),
\quad
u(b,t) = u_R(t), && t > 0.
\end{align}
Here is a graph of the solution $u(x,t)$ produced by one of the schemes:
An improper application of a finite difference scheme can lead to numerical instabilities:
We extend one of the schemes to solve
the highly nonlinear and degenerate
porous medium equation
\begin{align*}
&\frac{\partial u}{\partial t}
=
\frac{\partial^2 \phi(u)}{\partial x^2},
&
&x \in (a,b), \; t > 0,
\\
&u(x,0) = u_0(x), && x \in (a,b),
\\
&u(a,t) = u_L(t),
\quad
u(b,t) = u_R(t), && t > 0,
\end{align*}
where we take $\phi(u) = u^3$, but the method may be applied to arbitrary monotonically
increasing $\phi$.
Here is a sample solution:
Coding style (by Linus Torvalds)
The Linux kernel coding style
is written by Linus Torvalds as a style-guide
for his collaborators on developing and maintaining the Linux
kernel. The advice in chapters 1–9 is generic and applies
to any C programming project. I do follow that style myself,
and recommend that you do it too.