Programming Projects in C
for students of
Engineering, Sciences and Mathematics
Rouben Rostamian
2014
Resources for Project Finite Differences in 1D
Notes and errata
-
The equation displayed at the bottom of the page 252 is missing
a factor of 1/2 in its last term. The corrected equation is:
\[
u(x,t_k)
= u(x_j, t_k)
+ \frac{\partial u}{\partial x}\Big|_{(x_j, t_k)} (x - x_j)
+ \frac{1}{2} \frac{\partial^2 u}{\partial x^2}\Big|_{(x_j, t_k)} (x - x_j)^2 + \cdots.
\]
The next two equations (page 253) are also missing the 1/2 factors.
The corrected equations are:
\begin{align*}
u(x_{j-1},t_k)
&= u(x_j, t_k)
+ \frac{\partial u}{\partial x}\Big|_{(x_j, t_k)} (x_{j-1} - x_j)
+ \frac{1}{2} \frac{\partial^2 u}{\partial x^2}\Big|_{(x_j, t_k)} (x_{j-1} - x_j)^2 + \cdots,
\\
u(x_{j+1},t_k)
&= u(x_j, t_k)
+ \frac{\partial u}{\partial x}\Big|_{(x_j, t_k)} (x_{j+1} - x_j)
+ \frac{1}{2} \frac{\partial^2 u}{\partial x^2}\Big|_{(x_j, t_k)} (x_{j+1} + x_j)^2 + \cdots.
\end{align*}
-
Page 255, equation (20.9) should be
\[
\lambda_j
=
1 - 2r \big( 1 - \cos \frac{j\pi}{n+1} \big),
\quad
j = 1,2,\ldots,n.
\]
-
Page 256, equation (20.11):
$u_{j+1}^{j+1}$
should be
$u_{j+1}^{k+1}$.
-
Page 258, the first displayed equation should be
\[
\lambda_j
=
\frac{1}{
1 + 2r \big( 1 - \cos \frac{j\pi}{n+1} \big)},
\quad
j = 1,2,\ldots,n.
\]
-
Page 264, equation (20.20): The $\frac{1}{2}$ in the exponent
should be $\frac{1}{4}$, that is, the correct equation is
\[
u_\text{ex}(x,t) = e^{-\frac{1}{4}\pi^2 t} \cos\frac{1}{2}\pi x
\]
-
Page 265, second line from the bottom: $x=0$ should be $x=1$.
-
On page 267, line 4, we have:
max error at time 0.2 is 0.00999372
That should be
max error at time 0.2 is 0.00799498
-
In the graphs shown on pages 268 and 269, the orientations
of the graphs in the rightmost column
are inconsistent with those of the first three columns.
For consistency, they should have been rotated about their
vertical axes by 90 degrees clockwise (as viewed from above.)
-
Page 275, Listing 20.5, line 1: It would be a good style to add
const
qualifiers to the parameters
a
and
c
, as in:
static void trisolve(int n, const double *a, double *d,
const double *c, double *b, double *x)
These assure the compiler that the vectors
a
and
c
will not be changed in this function.
New version!
The implemenation of this chapter's programs can be significantly
streamlined. For that reason, I have written an alternative
presetnation which I recommend that you follow instead of the one in
the printed book. Should there be a second edition of the book
some day, this version will replace the old.
Replacement for Chapter 20:
finite-differences.pdf
Auxiliary files for Chapter 20:
plot3d.h
plot3d.c