(Ebook PDF) A First Course On Numerical Methods 5th Edition Download
(Ebook PDF) A First Course On Numerical Methods 5th Edition Download
https://ebooksecure.com/product/ebook-pdf-a-first-course-on-
numerical-methods-5th-edition/
http://ebooksecure.com/product/ebook-pdf-business-statistics-a-
first-course-first-canadian-edition/
http://ebooksecure.com/product/ebook-pdf-new-perspectives-on-
microsoft-office-2013-first-course-enhanced-edition/
http://ebooksecure.com/product/ebook-pdf-a-first-course-in-
coding-theory/
http://ebooksecure.com/product/ebook-pdf-electric-power-systems-
a-first-course/
(eBook PDF) First Course in Statistics A 11th Edition
http://ebooksecure.com/product/ebook-pdf-first-course-in-
statistics-a-11th-edition/
http://ebooksecure.com/product/ebook-pdf-business-statistics-a-
first-course-7th-edition/
http://ebooksecure.com/product/ebook-pdf-a-first-course-in-
probability-9th-edition/
http://ebooksecure.com/product/ebook-pdf-business-statistics-a-
first-course-8th-edition/
http://ebooksecure.com/product/ebook-pdf-business-statistics-a-
first-course-3rd-edition/
A First Course in
Numerical Methods
CS07_Ascher-Greif_FM-a.indd
Downloaded1 17 Feb 2012 to 129.174.55.245. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php 5/13/2011 1:43:24 PM
✐ ✐
✐ ✐
Contents ix
✐ ✐
✐ ✐
✐ ✐
✐ ✐
x Contents
Bibliography 539
Index 543
✐ ✐
✐ ✐
✐ ✐
✐ ✐
List of Figures
2.1 A double word (64 bits) in the standard floating point system. The blue bit is for
sign, the magenta bits store the exponent, and the green bits are for the fraction. 19
2.2 The “almost random” nature of roundoff errors. . . . . . . . . . . . . . . . . . 21
2.3 Picture of the floating point system described in Example 2.8. . . . . . . . . . . 26
3.1 Graphs of three functions and their real roots (if there are any): (i) f (x) = sin(x)
on [0, 4π], (ii) f (x) = x 3 −30x 2 +2552 on [0, 20], and (iii) f (x) = 10 cosh(x/4)−
x on [−10, 10]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.2 Fixed point iteration for x = e−x , starting from x 0 = 1. This yields x 1 = e−1 ,
−1
x 2 = e−e , . . . . Convergence is apparent. . . . . . . . . . . . . . . . . . . . . . 47
3.3 The functions x and 2 cosh(x/4) meet at two locations. . . . . . . . . . . . . . 48
3.4 Newton’s method: the next iterate is the x-intercept of the tangent line to f at the
current iterate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.5 Graph of an anonymous function; see Exercise 18. . . . . . . . . . . . . . . . . 63
4.1 Intersection of two straight lines: a11 x 1 + a12 x 2 = b1 and a21 x 1 + a22 x 2 = b2 . . 66
4.2 Eigenvalues in the complex plane, Example 4.5. Note that the complex ones
arrive in pairs: if λ is an eigenvalue, then so is λ̄. Also, here all eigenvalues have
nonpositive real parts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.3 The “unit circle” according to the three norms, 1 , 2 , and ∞ . Note that the
diamond is contained in the circle, which in turn is contained in the square. . . . 75
xi
✐ ✐
✐ ✐
✐ ✐
✐ ✐
5.1 Gaussian elimination for the case n = 4. Only areas of potentially nonzero entries
are shown. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.2 LU decomposition for the case n = 10. Only areas of potentially nonzero entries
in the square matrices L and U are shown. . . . . . . . . . . . . . . . . . . . . 102
5.3 Compressed row form of the matrix in Example 5.14. Shown are the vectors i, j, v.
The arrows and the “eof” node are intended merely for illustration of where the
elements of the vector i point to in j and correspondingly in v. . . . . . . . . . . 118
5.4 A banded matrix for the case n = 10, p = 2, q = 3. Only areas of potentially
nonzero entries are shaded in green. . . . . . . . . . . . . . . . . . . . . . . . . 120
5.5 Graphs of the matrices A (left) and B (right) of Example 5.15. . . . . . . . . . 125
5.6 Sparsity pattern of a certain symmetric positive definite matrix A (left), its RCM
ordering (middle), and approximate minimum degree ordering (right). . . . . . 126
5.7 Sparsity pattern of the Cholesky factors of A (left), its RCM ordering (middle),
and approximate minimum degree ordering (right). . . . . . . . . . . . . . . . 127
5.8 Stretching the unit circle by a symmetric positive definite transformation. . . . . 133
6.1 Matrices and vectors and their dimensions in 2 data fitting. . . . . . . . . . . . 143
6.2 Discrete least squares approximation. . . . . . . . . . . . . . . . . . . . . . . . 145
6.3 Linear regression curve (in blue) through green data. Here, m = 25, n = 2. . . . 148
6.4 The first 5 best polynomial approximations to f (t) = cos(2πt) sampled at 0 : .05 :
1. The data values appear as red circles. Clearly, p4 fits the data better than p2,
which in turn is a better approximation than p0 . Note p2 j +1 = p2 j . . . . . . . . 150
6.5 Ratio of execution times using QR vs. normal equations. The number of rows for
each n is 3n + 1 for the upper curve and n + 1 for the lower one. . . . . . . . . 157
6.6 Householder reflection. Depicted is a 20 × 5 matrix A after 3 reflections. . . . . 160
✐ ✐
✐ ✐
✐ ✐
✐ ✐
7.6 Sparsity patterns for the matrix of Example 7.1 with N = 8: top left, the IC
factor F with no fill-in (IC(0)); top right, the product F F T ; bottom left, the full
Cholesky factor G; bottom right, the IC factor with drop tolerance .001. See
Figure 7.3 for the sparsity pattern of the original matrix. . . . . . . . . . . . . . 189
7.7 Iteration progress for CG, PCG with the IC(0) preconditioner and PCG with the
IC preconditioner using drop tolerance tol= 0.01. . . . . . . . . . . . . . . . 190
7.8 Convergence behavior of restarted GMRES with m = 20, for a 10,000 × 10,000
matrix that corresponds to the convection-diffusion equation on a 100 × 100 uni-
form mesh. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.9 The polynomials that are constructed in the course of three CG iterations for the
small linear system of Examples 7.9 and 7.14. The values of the polynomials at
the eigenvalues of the matrix are marked on the linear, quadratic, and cubic curves. 202
7.10 An illustration of the smoothing effect, using damped Jacobi with ω = 0.8 applied
to the Poisson equation in one dimension. . . . . . . . . . . . . . . . . . . . . 205
7.11 Convergence behavior of various iterative schemes for the Poisson equation (see
Example 7.17) with n = 2552. . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
7.12 Example 7.17: number of iterations (top panel) and CPU times (bottom panel)
required to achieve convergence to tol= 1.e-6 for the Poisson problem of Exam-
ple 7.1 (page 168) with N = 2l − 1, l = 5, 6, 7, 8, 9. . . . . . . . . . . . . . . . . 209
8.1 Convergence behavior of the power method for two diagonal matrices, Exam-
ple 8.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
8.2 A toy network for the PageRank Example 8.3. . . . . . . . . . . . . . . . . . . 224
8.3 Things that can go wrong with the basic model: depicted are a dangling node
(left) and a terminal strong component featuring a cyclic path (right). . . . . . . 225
8.4 Convergence behavior of the inverse iteration in Example 8.4. . . . . . . . . . . 229
8.5 Original 200 × 320 pixel image of a clown. . . . . . . . . . . . . . . . . . . . . 232
8.6 A rank-20 SVD approximation of the image of a clown. . . . . . . . . . . . . . 232
8.7 The result of the first stage of a typical eigensolver: a general upper Hessenberg
matrix for nonsymmetric matrices (left) and a tridiagonal form for symmetric
matrices (right). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
8.8 The result of the first stage of the computation of the SVD is a bi-diagonal matrix
C (left). The corresponding tridiagonal matrix C T C is given on the right. . . . . 243
8.9 Mandrill image and a drawing by Albrecht Dürer; see Example 11. . . . . . . . 248
✐ ✐
✐ ✐
✐ ✐
✐ ✐
9.10 One equality constraint and the level sets of φ. At x∗ the gradient is orthogonal to
the tangent of the constraint. . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9.11 Center path in the LP primal feasibility region. . . . . . . . . . . . . . . . . . . 278
9.12 Two minimum norm solutions for an underdetermined linear system of equations.
The 1 solution is nicely sparse. . . . . . . . . . . . . . . . . . . . . . . . . . . 286
9.13 A depiction of the noisy function (in solid blue) and the function to be recovered
(in red) for Exercise 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
10.1 Different interpolating curves through the same set of points. . . . . . . . . . . 296
10.2 Quadratic and linear polynomial interpolation. . . . . . . . . . . . . . . . . . . 299
10.3 The quadratic Lagrange polynomials L 0 (x), L 1 (x), and L 2 (x) based on points
x 0 = 1, x 1 = 2, x 2 = 4, used in Example 10.2. . . . . . . . . . . . . . . . . . . 303
10.4 The Lagrange polynomial L 2 (x) for n = 5. Guess what the data abscissae x i are. 304
10.5 The interpolating polynomials p2 and p3 for Example 10.4. . . . . . . . . . . . 310
10.6 Global polynomial interpolation at uniformly spaced abscissae can be bad. Here
the blue curve with one maximum point is the Runge function of Example 10.6,
and the other curves are polynomial interpolants of degree n. . . . . . . . . . . 317
10.7 Polynomial interpolation at Chebyshev points, Example 10.6. Results are much
improved as compared to Figure 10.6, especially for larger n. . . . . . . . . . . 317
10.8 Top panel: the function of Example 10.7 is indistinguishable from its polynomial
interpolant at 201 Chebyshev points. Bottom panel: the maximum polynomial
interpolation error as a function of the polynomial degree. When doubling the
degree from n = 100 to n = 200 the error decreases from unacceptable (> 1) to
almost rounding unit level. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
10.9 A quadratic interpolant p2 (x) satisfying p2 (0) = 1.5, p2 (0) = 1, and p2 (5) = 0. . 320
10.10 The osculating Hermite cubic for ln(x) at the points 1 and 2. . . . . . . . . . . . 322
10.11 Quadratic and linear polynomial interpolation. . . . . . . . . . . . . . . . . . . 324
✐ ✐
✐ ✐
✐ ✐
✐ ✐
List of Figures xv
12.1 The first five best polynomial approximations to f (x) = cos(2π x). The approxi-
mated function is in solid green. Note the similarity to Figure 6.4 of Example 6.3. 369
12.2 The first five Legendre polynomials. You should be able to figure out which curve
corresponds to which polynomial. . . . . . . . . . . . . . . . . . . . . . . . . . 372
12.3 Chebyshev polynomials of degrees 4, 5, and 6. . . . . . . . . . . . . . . . . . . 378
13.1 A linear combination of sines and cosines with various k-values up to 110 (top
panel), filtered by taking its best least squares trigonometric polynomial approx-
imation with l = 10 (bottom panel). This best approximation simply consists of
that part of the given function that involves the first 20 basis functions φ j ; thus
the higher frequency contributions disappear. . . . . . . . . . . . . . . . . . . . 385
13.2 For the discrete Fourier transform, imagine the red mesh points located on a blue
circle with x 0 = x n+1 closing the ring. Thus, x n is the left (clockwise) neighbor
of x 0 , x 1 is the right (counterclockwise) neighbor of x n+1 , and so on. . . . . . . 390
13.3 Trigonometric polynomial interpolation for the hat function with p3(x). . . . . 391
13.4 Trigonometric polynomial interpolation for a smooth function with p3 (x) (top
left), p7 (x) (top right), p15 (x) (bottom left), and p31(x) (bottom right). The ap-
proximated function is plotted in dashed green. . . . . . . . . . . . . . . . . . . 393
13.5 Trigonometric polynomial interpolation for the square wave function on [0, 2π ]
with n = 127. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
13.6 The unit circle in the complex plane is where the values of eıθ reside. The m = 8
roots of the polynomial equation θ 8 = 1, given by e−ı2 j π/8 , j = 0, 1, . . ., 7, are
displayed as red diamonds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
13.7 Example 13.9: an observed blurred image b, and the result of a deblurring algo-
rithm applied to this data. (Images courtesy of H. Huang [43].) . . . . . . . . . . 402
13.8 Cosine basis interpolation for the function ln(x + 1) on [0, 2π] with n = 31. . . 404
14.1 Actual error using the three methods of Example 14.1. Note the log-log scale
of the plot. The order of the methods is therefore indicated by the slope of the
straight line (note that h is decreased from right to left). . . . . . . . . . . . . . 413
14.2 The measured error roughly equals truncation error plus roundoff error. The for-
mer decreases but the latter grows as h decreases. The “ideal roundoff error” is
just η/ h. Note the log-log scale of the plot. A red circle marks the “optimal h”
value for Example 14.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
14.3 Numerical differentiation of noisy data. On the left panel, sin(x) is perturbed by
1% noise. On the right panel, the resulting numerical differentiation is a disaster. 425
14.4 An image with noise and its smoothed version. Numerical differentiation must
not be applied to the original image. . . . . . . . . . . . . . . . . . . . . . . . 426
14.5 Maximum absolute errors for the first and second derivatives of f (x) = e x sin(10x)
on the interval [0, π] at the Chebyshev extremum points, i.e., using the Chebyshev
differentiation matrix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Maximum absolute errors for the first and second derivatives of f (x) = e−5x on
2
14.6
the interval [−2π, 2π]. The two left subplots use FFT, and the right subplots use
the Chebyshev differentiation matrix. The errors are evaluated at the correspond-
ing data locations (also called collocation points). . . . . . . . . . . . . . . . . 431
14.7 This “waterfall” plot depicts the progress of two initial pulses in time; see Ex-
ample 14.14. The two solitons merge and then split with their form intact. Rest
assured that they will meet (and split) again many times in the future. . . . . . . 434
✐ ✐
✐ ✐
✐ ✐
✐ ✐
15.1 Area under the curve. Top left (cyan): for f (x) that stays nonnegative, I f equals
the area under the function’s curve. Bottom left (green): approximation by the
trapezoidal rule. Top right (pink): approximation by the Simpson rule. Bottom
right (yellow): approximation by the midpoint rule. . . . . . . . . . . . . . . . 444
15.2 Composite trapezoidal quadrature with h = 0.2 for the integral of Figure 15.1. . 448
15.3 Numerical integration errors for the composite trapezoidal and Simpson methods;
see Example 15.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
15.4 Numerical integration errors for the composite trapezoidal and Simpson methods;
see Example 15.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
15.5 The discontinuous integrand of Example 15.10. . . . . . . . . . . . . . . . . . 459
15.6 The integrand f (x) = 2x200 20 2
3 −x 2 (5 sin( x )) with quadrature mesh points along the
✐ ✐
✐ ✐
✐ ✐
✐ ✐
16.14 The two solutions of Examples 16.22 and 9.3 obtained using simple shooting
starting from two different initial guesses c0 for v (0). Plotted are the trajectories
for the initial guesses (dashed magenta), as well as the final BVP solutions (solid
blue). The latter are qualitatively the same as in Figure 9.3. Note the different
vertical scales in the two subfigures. . . . . . . . . . . . . . . . . . . . . . . . 524
16.15 Hyperbolic and parabolic solution profiles starting from a discontinuous initial
value function. For the advection equation the exact solution is displayed. For the
heat equation we have integrated numerically, using homogeneous BC at x = ±π
and a rather fine discretization mesh. . . . . . . . . . . . . . . . . . . . . . . . 526
16.16 “Waterfall” solutions of the classical wave equation using the leapfrog scheme;
see Example 16.25. For α = 1 the solution profile is resolved well by the dis-
cretization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
✐ ✐
✐ ✐
✐ ✐
✐ ✐
List of Tables
7.1 Errors for basic relaxation methods applied to the model problem of Example 7.1
with n = N 2 = 225. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
9.1 Convergence of Newton’s method to the two roots of Example 9.1. . . . . . . . 256
9.2 Example 9.5. The first three columns to the right of the iteration counter track
convergence starting from x0 = (8, .2)T : Newton’s method yields the minimum
quickly. The following (rightmost) three columns track convergence starting from
x0 = (8, .8)T : Newton’s method finds a critical point, but it’s not the minimizer. . 262
9.3 Example 9.14. Tracking progress of the primal-dual LP algorithm. . . . . . . . . 284
16.1 Absolute errors using the forward Euler method for the ODE y = y. The values
ei = y(ti ) − ei are listed under Error. . . . . . . . . . . . . . . . . . . . . . . . . 487
16.2 Errors and calculated observed orders (rates) for the forward Euler, the explicit
midpoint (RK2), and the classical Runge–Kutta (RK4) methods. . . . . . . . . . 496
16.3 Example 16.12: errors and calculated rates for Adams–Bashforth methods; (s, q)
denotes the s-step method of order q. . . . . . . . . . . . . . . . . . . . . . . . 503
16.4 Example 16.12: errors and calculated rates for Adams–Moulton methods; (s, q)
denotes the s-step method of order q. . . . . . . . . . . . . . . . . . . . . . . . 503
16.5 Coefficients of BDF methods up to order 6. . . . . . . . . . . . . . . . . . . . . 505
16.6 Example 16.14: errors and calculated rates for BDF methods; (s, q) denotes the
s-step method of order q. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
xix
✐ ✐
✐ ✐
✐ ✐
✐ ✐
Preface
This book is designed for students and researchers who seek practical knowledge of modern tech-
niques in scientific computing. The text aims to provide an in-depth treatment of fundamental issues
and methods, and the reasons behind success and failure of numerical software. On one hand, we
avoid an extensive, encyclopedic, heavily theoretical exposition, and try to get to current methods,
issues, and software fairly quickly. On the other hand, this is by no means a quick recipe book,
since we feel that the introduction of algorithms requires adequate theoretical foundation: having a
solid basis enables those who need to apply the techniques to successfully design their own solution
approach for any nonstandard problems they may encounter in their work.
There are many books on scientific computing and numerical analysis, and a natural question
here would be why we think that yet another text is necessary. It is mainly because we feel that in an
age where yesterday’s concepts are not necessarily today’s truths, scientific computing is constantly
redefining itself and is now positioned as a discipline truly at the junction of mathematics, computer
science, and engineering. Books that rely heavily on theory, or on algorithm recipes, do not quite
capture the current state of this broad and dynamic area of research and application. We thus take an
algorithmic approach and focus on techniques of a high level of applicability to engineering, com-
puter science, and industrial mathematics practitioners. At the same time, we provide mathematical
justification throughout for the methods introduced. While we refrain from a theorem–proof type of
exposition, we construct the theory behind the methods in a systematic and fairly complete fashion.
We make a strong effort to emphasize computational aspects of the algorithms discussed by way of
discussing their efficiency and their computational limitations.
This book has been developed from notes for two courses taught by the Department of Com-
puter Science at the University of British Columbia (UBC) for over 25 years. The first author
developed a set of notes back in the late 1970s. These were based on the books by Conte and de
Boor [13], Dahlquist and Bjorck [15], and others, as well as on notes by Jim Varah. Improvements
to these notes were subsequently made by Ian Cavers, by the second author, and by Dhavide Aru-
liah. A substantial addition of material was made by the two authors in the last few years. A few of
our colleagues (Jack Snoeyink, Oliver Dorn, Ian Mitchell, Kees van den Doel and Tyrone Rees at
UBC, Jim Lambers at Stanford University, Marsha Berger and Michael Overton at NYU, Edmond
Chow at Columbia University, André Weidemann at Stellenbosch, and others) have used the notes
and provided us with invaluable feedback.
Most of the material contained in this book can be covered in two reasonably paced semesterial
courses. A possible model here is the one that has been adopted at UBC: one course covers Chapters
3 to 9, while another concentrates on Chapters 10 to 16. The two parts are designed so that they do
not heavily rely on each other, although we have found it useful to include the material of Chapter
1 and a subset of Chapter 2 in both semesterial courses. More advanced material, contained in
sections denoted by an asterisk, is included in the text as a natural extension. However, with one or
two exceptions, we have not taught the advanced material in the two basic courses.
Another use of this text is for a breadth-type introductory course on numerical methods at
the graduate level. The target audience would be beginning graduate students in a variety of disci-
xxi
✐ ✐
✐ ✐
✐ ✐
✐ ✐
xxii Preface
plines including computer science, applied mathematics, and engineering, who start graduate school
without having taken undergraduate courses in this area. Such a course would also use our more
advanced sections and possibly additional material.
The division of the material into chapters can be justified by the type of computational errors
encountered. These concepts are made clear in the text. We start off with roundoff error, which
appears in all the numerical processes considered in this book. Chapters 1 and 2 systematically
cover it, and later chapters, such as 5 and 6, contain assessments of its effect. Chapter 3 and Chapters
7 to 9 are concerned mainly with iterative processes, and as such, the focus is on the iteration, or
convergence error. Finally, control and assessment of discretization error is the main focus in
Chapters 10 to 16, although the other error types do arise there as well.
We illustrate our algorithms using the programming environment of MATLAB and expect the
reader to become gradually proficient in this environment while (if not before) learning the material
covered in this book. But at the same time, we use the MATLAB language and programming
environment merely as a tool, and we refrain from turning the book into a language tutorial.
Each chapter contains exercises, ordered by section. In addition, there is an exercise numbered
0 which consists of several review questions intended for self-testing and for punctuating the process
of reading and absorbing the presented material. Instructors should resist the temptation to answer
these review questions for the students.
We have made an effort to make the chapters fairly independent of one another. As a result,
we believe that readers who are interested in specific topics may often be able to settle for reading
almost exclusively only the chapters that are relevant to the material they wish to pursue.
We are maintaining a project webpage for this book which can be found at
http://www.siam.org/books/cs07
It contains links to our programs, solutions to selected exercises, errata, and more.
Last but not at all least, many generations of students at UBC have helped us over the years to
shape, define, and debug this text. The list of individuals who have provided crucial input is simply
too long to mention. This book is dedicated to you, our students.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
Chapter 1
Numerical Algorithms
This opening chapter introduces the basic concepts of numerical algorithms and scientific comput-
ing.
We begin with a general, brief introduction to the field in Section 1.1. This is followed by the
more substantial Sections 1.2 and 1.3. Section 1.2 discusses the basic errors that may be encountered
when applying numerical algorithms. Section 1.3 is concerned with essential properties of such
algorithms and the appraisal of the results they produce.
We get to the “meat” of the material in later chapters.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
Observed
phenomenon
Mathematical
model
Discretization Solution
algorithm
Implementation
As a computing tool, we will be using MATLAB: this is an interactive computer language, which
for our purposes may best be viewed as a convenient problem solving environment.
MATLAB is much more than a language based on simple data arrays; it is truly a complete
environment. Its interactivity and graphics capabilities make it more suitable and convenient in our
context than general-purpose languages such as C++, Java, Scheme, or Fortran 90. In fact,
many of the algorithms that we will learn are already implemented in MATLAB. . . So why learn
them at all? Because they provide the basis for much more complex tasks, not quite available (that
is to say, not already solved) in MATLAB or anywhere else, which you may encounter in the future.
Rather than producing yet another MATLAB tutorial or introduction in this text (there are
several very good ones available in other texts as well as on the Internet) we will demonstrate the
use of this language on examples as we go along.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
The relative error is usually a more meaningful measure. This is especially true for errors in floating
point representation, a point to which we return in Chapter 2. For example, we record absolute and
relative errors for various hypothetical calculations in the following table:
u v Absolute Relative
error error
1 0.99 0.01 0.01
1 1.01 0.01 0.01
−1.5 −1.2 0.3 0.2
100 99.99 0.01 0.0001
100 99 1 0.01
Evidently, when |u| ≈ 1 there is not much difference between absolute and relative error measures.
But when |u| 1, the relative error is more meaningful. In particular, we expect the approximation
in the last row of the above table to be similar in quality to the one in the first row. This expectation
is borne out by the value of the relative error but is not reflected by the value of the absolute error.
When the approximated value is small in magnitude, things are a little more delicate, and here
is where relative errors may not be so meaningful. But let us not worry about this at this early point.
e=exp(1);
n=1:10; % array
Sn=sqrt(2*pi*n).*((n/e).^n); % the Stirling approximation.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
fact_n=factorial(n);
abs_err=abs(Sn-fact_n); % absolute error
rel_err=abs_err./fact_n; % relative error
format short g
[n; fact_n; Sn; abs_err; rel_err]’ % print out values
Given that this is our first MATLAB script, let us provide a few additional details, though we
hasten to add that we will not make a habit out of this. The commands exp, factorial, and abs
use built-in functions. The command n=1:10 (along with a semicolon, which simply suppresses
screen output) defines an array of length 10 containing the integers 1, 2, . . . , 10. This illustrates a
fundamental concept in MATLAB of working with arrays whenever possible. Along with it come
array operations: for example, in the third line “.*” corresponds to elementwise multiplication of
vectors or matrices. Finally, our printing instructions (the last two in the script) are a bit primitive
here, a sacrifice made for the sake of simplicity in this, our first program.
The resulting output is
1 1 0.92214 0.077863 0.077863
2 2 1.919 0.080996 0.040498
3 6 5.8362 0.16379 0.027298
4 24 23.506 0.49382 0.020576
5 120 118.02 1.9808 0.016507
6 720 710.08 9.9218 0.01378
7 5040 4980.4 59.604 0.011826
8 40320 39902 417.6 0.010357
9 3.6288e+005 3.5954e+005 3343.1 0.0092128
10 3.6288e+006 3.5987e+006 30104 0.008296
The values of n! become very large very quickly, and so are the values of the approximation
Sn . The absolute errors grow as n grows, but the relative errors stay well behaved and indicate that
in fact the larger n is, the better the quality of the approximation is. Clearly, the relative errors are
much more meaningful as a measure of the quality of this approximation.
Error types
Knowing how errors are typically measured, we now move to discuss their source. There are several
types of error that may limit the accuracy of a numerical calculation.
• Heavenly bodies are often approximated by spheres when calculating their properties;
an example here is the approximate calculation of their motion trajectory, attempting to
answer the question (say) whether a particular asteroid will collide with Planet Earth
before 11.12.2016.
• Relatively unimportant chemical reactions are often discarded in complex chemical
modeling in order to obtain a mathematical problem of a manageable size.
It is important to realize, then, that often approximation errors of the type stated above are
deliberately made: the assumption is that simplification of the problem is worthwhile even if
it generates an error in the model. Note, however, that we are still talking about the math-
ematical model itself; approximation errors related to the numerical solution of the problem
are discussed below.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
Another typical source of error in the problem is error in the input data. This may arise, for
instance, from physical measurements, which are never infinitely accurate.
Thus, it may be that after a careful numerical simulation of a given mathematical problem, the
resulting solution would not quite match observations on the phenomenon being examined.
At the level of numerical algorithms, which is the focus of our interest here, there is really
nothing we can do about the above-described errors. Nevertheless, they should be taken into
consideration, for instance, when determining the accuracy (tolerance with respect to the next
two types of error mentioned below) to which the numerical problem should be solved.
2. Approximation errors
Such errors arise when an approximate formula is used in place of the actual function to be
evaluated.
We will often encounter two types of approximation errors:
3. Roundoff errors
Any computation with real numbers involves roundoff error. Even when no approximation
error is produced (as in the direct evaluation of a straight line, or the solution by Gaussian
elimination of a linear system of equations), roundoff errors are present. These arise because
of the finite precision representation of real numbers on any computer, which affects both data
representation and computer arithmetic.
Discretization and convergence errors may be assessed by an analysis of the method used,
and we will see a lot of that in this text. Unlike roundoff errors, they have a relatively smooth
structure which may occasionally be exploited. Our basic assumption will be that approximation
errors dominate roundoff errors in magnitude in actual, successful calculations.
✐ ✐
✐ ✐
✐ ✐
✐ ✐
Example 1.2. Consider the problem of approximating the derivative f (x 0 ) of a given smooth
function f (x) at the point x = x 0 . For instance, let f (x) = sin(x) be defined on the real line
−∞ < x < ∞, and set x 0 = 1.2. Thus, f (x 0 ) = sin(1.2) ≈ 0.932 . . ..
Further, consider a situation where f (x) may be evaluated at any point x near x 0 , but f (x 0 )
may not be directly available or is computationally expensive to evaluate. Thus, we seek ways to
approximate f (x 0 ) by evaluating f at x near x 0 .
A simple algorithm may be constructed using Taylor’s series. This fundamental theorem is
given on the preceding page. For some small, positive value h that we will choose in a moment, write
h 2 h 3 h 4
f (x 0 + h) = f (x 0 ) + h f (x 0) + f (x 0) + f (x 0) + f (x 0 ) + · · · .
2 6 24
Then
f (x 0 + h) − f (x 0 ) h h 2 h 3
f (x 0 ) = − f (x 0) + f (x 0) + f (x 0 ) + · · · .
h 2 6 24
Our algorithm for approximating f (x 0) is to calculate
f (x 0 + h) − f (x 0 )
.
h
The obtained approximation has the discretization error
f (x 0) − f (x 0 + h) − f (x 0 ) = h f (x 0) + h f (x 0) + h f (x 0 ) + · · · .
2 3
h 2 6 24
Geometrically, we approximate the slope of the tangent at the point x 0 by the slope of the chord
through neighboring points of f . In Figure 1.2, the tangent is in blue and the chord is in red.
0 x0 x0 + h x
If we know f (x 0 ), and it is nonzero, then for h small we can estimate the discretization error
by
f (x 0 ) − f (x 0 + h) − f (x 0 ) ≈ h f (x 0) .
h 2
Using the notation defined in the box on the next page we notice that the error is O(h) so long as
✐ ✐
✐ ✐
Another Random Scribd Document
with Unrelated Content
restrictions morales à l'esprit d'incorporation matérielle. Quoique ce
grand office moral n'ait pu être alors que très imparfaitement rempli
par la doctrine critique, que son caractère nécessairement hostile
empêchait, dans l'application, de pouvoir devenir suffisamment
habituelle, son aptitude exclusive à maintenir, pendant tout le cours
des trois derniers siècles, un certain sentiment réel des principales
conditions morales de l'humanité, n'en reste pas moins évidemment
incontestable, sauf l'irrégularité du mode, d'ailleurs impérieusement
prescrite par la nature exceptionnelle d'une telle situation sociale.
Pendant que la dictature temporelle faisait définitivement reposer le
système de résistance sur l'emploi continu d'une force matérielle
convenablement organisée, il fallait bien que l'esprit révolutionnaire,
seul organe alors possible du progrès social, recourût finalement aux
tendances insurrectionnelles, afin d'éviter à la fois l'avilissement
moral et la dégradation politique auxquels cette situation devait
exposer les sociétés modernes, jusqu'à l'avénement lointain d'une
vraie réorganisation, seule susceptible de résoudre enfin ce
déplorable antagonisme.
Notre appréciation historique de l'ensemble de la doctrine critique
ébauchée par le protestantisme, d'après son principe fondamental
du libre examen individuel, serait aisément confirmée par l'étude
spéciale, ici déplacée, des diverses phases successives qui ont
graduellement amené la dissolution systématique de l'ancienne
organisation spirituelle: car on y remarque presque toujours que ces
dissidences théologiques, alors si décisives, ne sont essentiellement
que la reproduction, sous des formes nouvelles, des principales
hérésies propres aux premiers siècles du christianisme, et qui
avaient dû primitivement s'effacer devant l'irrésistible ascendant de
l'unité catholique. Au lieu d'éclairer aujourd'hui les philosophes de
l'école rétrograde, un tel rapprochement, mal observé et mal
interprété, n'a fait qu'entretenir leurs vaines illusions sur la
restauration chimérique de l'antique constitution. Mais, du point de
vue propre à ce Traité, il est, au contraire, évident que ce
mémorable contraste général entre la chute des hérésies primitives
et le succès de leurs modernes équivalens, ne fait que confirmer
essentiellement l'opposition des unes et la conformité des autres aux
principales tendances des situations sociales correspondantes,
comme nous l'avions déjà directement établi. Toujours et partout,
l'esprit d'hérésie est nécessairement plus ou moins inhérent au
caractère vague et arbitraire de toute philosophie théologique;
seulement cet esprit se trouve, en réalité, contenu ou stimulé,
suivant les exigences variables de l'état social: telle est la seule
explication rationnelle que puisse évidemment comporter cette sorte
de grand paradoxe historique.
Quoique nous devions éviter ici de nous engager aucunement
dans cet examen spécial des diverses phases propres au
protestantisme, j'y dois cependant signaler brièvement au lecteur le
principe historique d'après lequel il pourra pénétrer dans
l'appréciation graduelle, d'abord si confuse et si désordonnée, de
cette multitude de sectes hétérogènes, dont chacune prenait la
précédente en pitié et la suivante en horreur, selon la décomposition
plus ou moins avancée du système théologique. Il suffit de
distinguer, à cet égard, trois degrés essentiels, nécessairement
successifs, où l'ancien organisme religieux a été radicalement ruiné,
d'abord quant à la discipline, ensuite quant à la hiérarchie, et enfin
quant au dogme lui-même, qui en était l'âme: car, si chaque grand
ébranlement protestant devait simultanément produire cette triple
altération, il n'en a pas moins dû affecter surtout un seul de ces
caractères, de manière à se distinguer suffisamment de l'effort
précédent. On arrive ainsi à reconnaître trois phases consécutives,
nettement représentées par les noms respectifs de leurs principaux
organes, Luther, Calvin et Socin, qui, malgré leur faible intervalle
chronologique, n'ont réellement obtenu qu'à de notables distances
leur véritable influence sociale, et seulement quand la protestation
antérieure avait été convenablement réalisée. Il est clair, en effet,
que l'ébranlement luthérien primitif n'a introduit que d'insignifiantes
modifications dogmatiques, et qu'il a même essentiellement respecté
partout la hiérarchie, sauf la consécration solennelle de cet
asservissement politique du clergé qui ne devait rester qu'implicite
chez les peuples catholiques: Luther n'a vraiment ruiné que la
discipline ecclésiastique, pour la mieux adapter, comme je l'ai
expliqué, à cette servile transformation. Aussi cette première
désorganisation, où le système catholique était le moins altéré,
constitue-t-elle réellement la seule forme sous laquelle le
protestantisme ait jamais pu s'organiser provisoirement en une vraie
religion d'état, au moins chez de grandes nations indépendantes. Le
calvinisme, d'abord ébauché par le célèbre curé de Zurich, est venu
ensuite ajouter à cette démolition initiale celle de l'ensemble de la
hiérarchie qui maintenait l'unité sociale du catholicisme, en
continuant d'ailleurs à n'apporter au dogme chrétien que des
modifications simplement secondaires, quoique plus étendues que
les précédentes. Cette seconde phase, qui ne peut évidemment
convenir qu'à l'état de pure opposition, sans comporter aucune
apparence organique durable, me semble dès-lors constituer la vraie
situation normale du protestantisme, si l'on peut ainsi qualifier une
telle anomalie politique: car, l'esprit protestant s'y est alors
développé de la manière la plus convenable à sa nature
éminemment critique, qui répugne à l'inerte régularité du
luthéranisme officiel. Enfin, l'explosion anti-trinitaire, ou socinienne,
a naturellement complété cette double dissolution préalable de la
discipline et de la hiérarchie, en y joignant finalement celle des
principales croyances qui distinguaient le catholicisme de tout autre
monothéisme quelconque: son origine italienne, presque sous les
yeux de la papauté, annonçait déjà hautement la tendance ultérieure
des esprits catholiques à pousser la décomposition théologique
beaucoup plus loin que leurs précurseurs protestans, comme nous le
reconnaîtrons bientôt. Ce dernier ébranlement universel était
évidemment, par sa nature, le seul pleinement décisif contre tout
espoir de restauration catholique: mais, à ce titre même, le
protestantisme s'y rapprochait trop du simple déisme moderne pour
que cette phase extrême pût rester suffisamment caractéristique
d'une telle transition métaphysique, dont le presbytérianisme
demeure historiquement le plus pur organe spécial. Après cette
filiation principale, il n'y a plus réellement à distinguer, parmi les
nombreuses sectes postérieures, aucune nouvelle différence
importante à l'étude rationnelle de l'évolution moderne, sauf
toutefois la mémorable protestation générale que tentèrent
directement les quakers contre l'esprit militaire de l'ancien régime
social, lorsque la désorganisation spirituelle, enfin suffisamment
consommée par l'accomplissement successif des trois opérations
précédentes, dut spontanément conduire à systématiser aussi, à son
tour, la décomposition temporelle. J'ai déjà noté ci-dessus
l'antipathie naturelle du protestantisme, à un état quelconque,
envers toute constitution guerrière, qu'il n'a pu jamais sanctionner
que momentanément, dans les luttes entreprises pour le maintien ou
le triomphe de ses propres principes: mais il est clair que la célèbre
secte des amis, malgré ses ridicules et même son charlatanisme, a
dû servir d'organe spécial à une telle manifestation, qui la place au-
dessus de toutes les autres sectes protestantes pour l'essor plus
complet du grand mouvement révolutionnaire.
Afin que notre exposition rationnelle du mode général de
formation convenable à cette première ébauche effective de
l'ensemble de la doctrine critique puisse toujours demeurer
suffisamment historique, j'y crois devoir ajouter, en dernier lieu, une
importante considération supplémentaire, destinée à prévenir la
disposition trop systématique dans laquelle, contre mon gré, le
lecteur pourrait envisager une telle appréciation. C'est seulement, en
effet, par contraste envers la phase primitive, toujours
essentiellement spontanée, du mouvement de décomposition, que la
phase protestante peut être caractérisée comme réellement
systématique, en tant que dirigée surtout d'après des doctrines
réformatrices, au lieu du simple conflit naturel des anciens élémens
politiques: mais la pleine systématisation de la philosophie négative,
autant du moins qu'elle en était susceptible, n'a pu véritablement
s'accomplir que sous la phase déiste, ci-après examinée, dont une
telle opération devait constituer le principal attribut. Sous le
protestantisme proprement dit, l'élaboration graduelle des principes
critiques a dû rester éminemment empirique, et s'effectuer
successivement, au milieu des variations religieuses, d'après
l'impulsion instinctive d'une situation fondamentale de plus en plus
révolutionnaire, à mesure que le cours général des événemens
faisait spécialement ressortir chacune des faces essentielles du
besoin uniforme de décomposition radicale, et par suite y sollicitait
de nouvelles applications politiques du dogme universel de libre
examen individuel, comme base intellectuelle de toute cette série de
maximes dissolvantes. En ce sens, seul strictement historique, on ne
saurait isoler la considération de ces opérations mentales de celle
des diverses révolutions correspondantes, qui leur ont réellement
donné lieu, ou sans lesquelles du moins elles n'eussent jamais pu
obtenir une haute influence sociale, en vertu de l'extrême
incohérence logique que nous avons reconnue propre à de telles
conceptions, où l'on tendait toujours à régénérer l'ancienne
organisation spirituelle en détruisant de plus en plus les différentes
conditions indispensables à son existence effective. Mais, par suite
même de cet inévitable caractère commun, ces explosions politiques,
quelque intense ou prolongée qu'ait pu être leur action successive,
ne devaient jamais devenir pleinement décisives, de manière à
constater irrévocablement la tendance finale des sociétés modernes
vers une entière rénovation, tant qu'elles n'avaient point été
précédées d'une préparation critique vraiment complète et
systématique, ce qui n'a dû avoir lieu que sous la phase suivante.
C'est pourquoi nous devons ici nous borner à signaler sommairement
ces révolutions purement protestantes, qui, abstraction faite de leur
importance locale ou passagère, ne pouvaient constituer que de
simples préambules au grand ébranlement final destiné directement
à caractériser l'issue nécessaire du mouvement général de
l'humanité, comme je l'expliquerai au cinquante-septième chapitre.
La première de ces révolutions préliminaires est celle qui affranchit
complétement la Hollande du joug espagnol; elle restera toujours
mémorable, comme une haute manifestation primitive de l'énergie
propre à la doctrine critique, dirigeant ainsi l'heureuse insurrection
d'une petite nation contre la plus puissante monarchie européenne.
C'est à cette lutte vraiment héroïque qu'il faut rapporter la première
élaboration régulière de cette doctrine politique: mais elle dut s'y
borner surtout à ébaucher spécialement le dogme de la souveraineté
populaire, et celui de l'indépendance nationale, que les légistes
coordonnèrent bientôt à leur conception spontanée du contrat social;
suivant les exigences naturelles d'un tel cas, où l'organisation
intérieure ne devait être qu'accessoirement modifiée, et dont le
principal besoin révolutionnaire devait seulement consister à briser
un lien extérieur devenu profondément oppressif. Un caractère plus
général, plus complet, et même plus décisif, une tendance mieux
prononcée vers la régénération sociale de l'ensemble de l'humanité,
distinguent ensuite noblement, malgré son avortement nécessaire, la
grande révolution anglaise, non la petite révolution aristocratique et
anglicane de 1688, aujourd'hui si ridiculement prônée, et qui ne
devait satisfaire qu'à un simple besoin local, mais la révolution
démocratique et presbytérienne, dominée par l'éminente nature[34]
de l'homme d'état le plus avancé dont le protestantisme puisse
jamais s'honorer. L'ébauche primordiale de l'ensemble de la doctrine
critique y dut recevoir spécialement son principal complément
naturel par l'élaboration directe du dogme de l'égalité, jusque alors à
peine manifesté, et qui n'avait pu certes ressortir suffisamment des
inclinations calvinistes de la noblesse française; tandis qu'on le voit
enfin nettement surgir, sous cette mémorable impulsion, de la
conception métaphysique sur l'état de nature, ancienne émanation
de la théorie théologique relative à la constitution humaine avant le
péché originel. On ne peut douter, en effet, que cette révolution n'ait
surtout consisté historiquement dans l'effort généreux, mais trop
prématuré, qui fut alors directement tenté, avec tant d'énergie, pour
l'abaissement politique de l'aristocratie anglaise, principal élément
temporel de l'ancienne nationalité: la chute de la royauté sous le
protectorat n'y fut, au contraire, comparativement à l'audacieuse
suppression de la Chambre des lords, qu'un incident secondaire,
dont les temps antérieurs avaient souvent offert l'équivalent, et qui
n'a trop préoccupé les esprits français que par suite des
irrationnelles habitudes de vicieux rapprochemens historiques que
j'ai déjà suffisamment signalées. C'est essentiellement ainsi qu'un tel
ébranlement social, quoiqu'il n'ait pu réussir politiquement, en vertu
de l'insuffisante préparation mentale d'où il émanait, a néanmoins
constitué, en réalité, dans la série générale des opérations
révolutionnaires, le principal symptôme précurseur de la grande
révolution française ou européenne, seule destinée à devenir
décisive, comme je l'expliquerai en son lieu. Il faut enfin rattacher
aussi à cette suite préliminaire d'explosions politiques une troisième
révolution, dont la vraie nature ne fut pas, au fond, moins purement
protestante que celle des deux précédentes, quoique son avénement
chronologique, spontanément retardé par les circonstances spéciales
de ce dernier cas, la fasse d'ordinaire rapporter abusivement à un
état plus avancé du mouvement général de décomposition. La
révolution américaine, à laquelle aucune importante élaboration
nouvelle de la doctrine critique ne fut réellement due, n'a pu être, en
effet, à tous égards, qu'une simple extension commune des deux
autres révolutions protestantes, dont les conséquences politiques y
ont été ultérieurement développées par un concours spontané de
conditions favorables, les unes locales, les autres sociales,
particulières à une telle application. Dans son principe, elle se borne
évidemment à reproduire, sous de nouvelles formes, la révolution
hollandaise; dans son essor final, elle prolonge la révolution
anglaise, qu'elle réalise autant que le protestantisme puisse le
comporter. Sous l'un ni l'autre aspect, la saine philosophie ne permet
point d'envisager comme socialement décisive une révolution qui, en
développant outre mesure les inconvéniens propres à l'ensemble de
la doctrine critique, n'a pu aboutir jusqu'ici qu'à consacrer, plus
profondément que partout ailleurs, l'entière suprématie politique des
métaphysiciens et des légistes, chez une population où
d'innombrables cultes incohérens prélèvent habituellement, sans
aucune vraie destination sociale, un tribut fort supérieur au budget
actuel d'aucun clergé catholique. Aussi cette colonie universelle,
malgré les éminens avantages temporels de sa présente situation,
doit-elle être regardée, au fond, comme étant réellement, à tous les
égards principaux, bien plus éloignée d'une véritable réorganisation
sociale que les peuples d'où elle émane, et d'où elle devra recevoir,
en temps opportun, cette régénération finale, dont l'initiative
philosophique ne saurait lui appartenir nullement; quelles que soient
aujourd'hui les puériles illusions relatives à la prétendue supériorité
politique d'une société où les divers élémens essentiels propres à la
civilisation moderne sont encore si imparfaitement développés, sauf
la seule activité industrielle, ainsi que je l'indiquerai plus
spécialement au chapitre suivant.
Note 34: Les admirateurs fanatiques de Bonaparte
dédaigneraient aujourd'hui son ancienne comparaison politique
avec le grand Cromwell, comme trop inférieure à la sublimité de
leur héros, qui leur semble ne pouvoir comporter de digne
parallèle historique qu'avec Charlemagne ou César. Néanmoins,
avant même que les influences contemporaines aient pu être
aussi effacées pour l'un qu'elles le sont maintenant pour l'autre, la
postérité éclairée mettra, sans doute, au contraire, un immense
intervalle définitif entre la dictature éminemment progressive de
Cromwell, s'efforçant d'améliorer l'organisation anglaise fort au-
delà de ce qui était alors possible, et la tyrannie purement
rétrograde de Bonaparte, entreprenant, à grands frais, après tant
d'autres empiriques, la vaine résurrection, en France, du régime
féodal et théologique, sans même en comprendre réellement
l'esprit ni les conditions. Quant à la comparaison militaire, qui
n'offre d'ailleurs qu'un intérêt très secondaire, ceux qui voudraient
l'établir judicieusement devraient, avant tout, prendre en
suffisante considération l'exiguïté des moyens employés par
Cromwell, eu égard à l'importance et à la stabilité des résultats
obtenus, par opposition à la monstrueuse consommation
d'hommes indispensable à la plupart des succès de Bonaparte,
sauf sa première expédition.
ebooksecure.com