1 Preliminaries 1
1.0 Introduction 1
1.1 Program Organization and Control Structures 5
1.2 Some C++ Conventions for Scientific Computing 16
1.3 Implementation of the Vector and Matrix Classes 25
1.4 Error, Accuracy, and Stability 31
2 Solution of Linear Algebraic Equations 35
2.0 Introduction 35
2.1 Gauss-Jordan Elimination 39
2.2 Gaussian Elimination with Backsubstitution 44
2.3 LU Decomposition and Its Applications 46
2.4 Tridiagonal and Band Diagonal Systems of Equations 53
2.5 Iterative Improvement of a Solution to Linear Equations 58
2.6 Singular Value Decomposition 62
2.7 Sparse Linear Systems 74
2.8 Vandermonde Matrices and Toeplitz Matrices 93
2.9 Cholesky Decomposition 99
2.10 QR Decomposition 101
2.11 Is Matrix Inversion an N3 Process? 105
3 Interpolation and Extrapolation 108
3.0 Introduction 108
3.1 Polynomial Interpolation and Extrapolation 111
3.2 Rational Function Interpolation and Extrapolation 114
3.3 Cubic Spline Interpolation 116
3.4 How to Search an Ordered Table 120
3.5 Coef?cients of the Interpolating Polynomial 123
3.6 Interpolation in Two or More Dimensions 126
4 Integration of Functions 133
4.0 Introduction 133
4.1 Classical Formulas for Equally Spaced Abscissas 134
4.2 Elementary Algorithms 141
4.3 Romberg Integration 144
4.4 Improper Integrals 146
4.5 Gaussian Quadratures and Orthogonal Polynomials 152
4.6 Multidimensional Integrals 166
5 Evaluation of Functions 171
5.0 Introduction 171
5.1 Series and Their Convergence 171
5.2 Evaluation of Continued Fractions 175
5.3 Polynomials and Rational Functions 179
5.4 Complex Arithmetic 182
5.5 Recurrence Relations and Clenshaw’s Recurrence Formula 184
5.6 Quadratic and Cubic Equations 189
5.7 Numerical Derivatives 192
5.8 Chebyshev Approximation 196
5.9 Derivatives or Integrals of a Chebyshev-approximated Function 201
5.10 Polynomial Approximation from Chebyshev Coef?cients 203
5.11 Economization of Power Series 204
5.12 Pade Approximants 206 ´
5.13 Rational Chebyshev Approximation 209
5.14 Evaluation of Functions by Path Integration 213
6 Special Functions 217
6.0 Introduction 217
6.1 Gamma Function, Beta Function, Factorials, Binomial Coef?cients 218
6.2 Incomplete Gamma Function, Error Function, Chi-Square Probability Function, Cumulative Poisson Function 221
6.3 Exponential Integrals 227
6.4 Incomplete Beta Function, Student’s Distribution, F-Distribution, Cumulative Binomial Distribution 231
6.5 Bessel Functions of Integer Order 235
6.6 Modi?ed Bessel Functions of Integer Order 241
6.7 Bessel Functions of Fractional Order, Airy Functions, Spherical
Bessel Functions 245
6.8 Spherical Harmonics 257
6.9 Fresnel Integrals, Cosine and Sine Integrals 259
6.10 Dawson’s Integral 264
6.11 Elliptic Integrals and Jacobian Elliptic Functions 265
6.12 Hypergeometric Functions 275
7 Random Numbers 278
7.0 Introduction 278
7.1 Uniform Deviates 279Contents vii
7.2 Transformation Method: Exponential and Normal Deviates 291
7.3 Rejection Method: Gamma, Poisson, Binomial Deviates 294
7.4 Generation of Random Bits 300
7.5 Random Sequences Based on Data Encryption 304
7.6 Simple Monte Carlo Integration 308
7.7 Quasi- (that is, Sub-) Random Sequences 313
7.8 Adaptive and Recursive Monte Carlo Methods 320
8 Sorting 332
8.0 Introduction 332
8.1 Straight Insertion and Shell’s Method 333
8.2 Quicksort 336
8.3 Heapsort 339
8.4 Indexing and Ranking 341
8.5 Selecting the Mth Largest 344
8.6 Determination of Equivalence Classes 348
9 Root Finding and Nonlinear Sets of Equations 351
9.0 Introduction 351
9.1 Bracketing and Bisection 354
9.2 Secant Method, False Position Method, and Ridders’ Method 358
9.3 Van Wijngaarden–Dekker–Brent Method 363
9.4 Newton-Raphson Method Using Derivative 366
9.5 Roots of Polynomials 373
9.6 Newton-Raphson Method for Nonlinear Systems of Equations 383
9.7 Globally Convergent Methods for Nonlinear Systems of Equations 387
10 Minimization or Maximization of Functions 398
10.0 Introduction 398
10.1 Golden Section Search in One Dimension 401
10.2 Parabolic Interpolation and Brent’s Method in One Dimension 406
10.3 One-Dimensional Search with First Derivatives 410
10.4 Downhill Simplex Method in Multidimensions 413
10.5 Direction Set (Powell’s) Methods in Multidimensions 417
10.6 Conjugate Gradient Methods in Multidimensions 424
10.7 Variable Metric Methods in Multidimensions 430
10.8 Linear Programming and the Simplex Method 434
10.9 Simulated Annealing Methods 448
11 Eigensystems 461
11.0 Introduction 461
11.1 Jacobi Transformations of a Symmetric Matrix 468
11.2 Reduction of a Symmetric Matrix to Tridiagonal Form: Givens and Householder Reductions 474
11.3 Eigenvalues and Eigenvectors of a Tridiagonal Matrix 481
11.4 Hermitian Matrices 486
11.5 Reduction of a General Matrix to Hessenberg Form 487viii Contents
11.6 The QR Algorithm for Real Hessenberg Matrices 491
11.7 Improving Eigenvalues and/or Finding Eigenvectors by Inverse Iteration 498
12 Fast Fourier Transform 501
12.0 Introduction 501
12.1 Fourier Transform of Discretely Sampled Data 505
12.2 Fast Fourier Transform (FFT) 509
12.3 FFT of Real Functions, Sine and Cosine Transforms 515
12.4 FFT in Two or More Dimensions 526
12.5 Fourier Transforms of Real Data in Two and Three Dimensions 530
12.6 External Storage or Memory-Local FFTs 536
13 Fourier and Spectral Applications 542
13.0 Introduction 542
13.1 Convolution and Deconvolution Using the FFT 543
13.2 Correlation and Autocorrelation Using the FFT 550
13.3 Optimal (Wiener) Filtering with the FFT 552
13.4 Power Spectrum Estimation Using the FFT 555
13.5 Digital Filtering in the Time Domain 563
13.6 Linear Prediction and Linear Predictive Coding 569
13.7 Power Spectrum Estimation by the Maximum Entropy (All Poles) Method 577
13.8 Spectral Analysis of Unevenly Sampled Data 580
13.9 Computing Fourier Integrals Using the FFT 589
13.10 Wavelet Transforms 596
13.11 Numerical Use of the Sampling Theorem 611
14 Statistical Description of Data 614
14.0 Introduction 614
14.1 Moments of a Distribution: Mean, Variance, Skewness, and So Forth 615
14.2 Do Two Distributions Have the Same Means or Variances? 620
14.3 Are Two Distributions Different? 625
14.4 Contingency Table Analysis of Two Distributions 633
14.5 Linear Correlation 641
14.6 Nonparametric or Rank Correlation 644
14.7 Do Two-Dimensional Distributions Differ? 650
14.8 Savitzky-Golay Smoothing Filters 655
15 Modeling of Data 661
15.0 Introduction 661
15.1 Least Squares as a Maximum Likelihood Estimator 662
15.2 Fitting Data to a Straight Line 666
15.3 Straight-Line Data with Errors in Both Coordinates 671
15.4 General Linear Least Squares 676
15.5 Nonlinear Models 686Contents ix
15.6 Con?dence Limits on Estimated Model Parameters 694
15.7 Robust Estimation 704
16 Integration of Ordinary Differential Equations 712
16.0 Introduction 712
16.1 Runge-Kutta Method 715
16.2 Adaptive Stepsize Control for Runge-Kutta 719
16.3 Modi?ed Midpoint Method 727
16.4 Richardson Extrapolation and the Bulirsch-Stoer Method 729
16.5 Second-Order Conservative Equations 737
16.6 Stiff Sets of Equations 739
16.7 Multistep, Multivalue, and Predictor-Corrector Methods 751
17 Two Point Boundary Value Problems 756
17.0 Introduction 756
17.1 The Shooting Method 760
17.2 Shooting to a Fitting Point 762
17.3 Relaxation Methods 765
17.4 A Worked Example: Spheroidal Harmonics 775
17.5 Automated Allocation of Mesh Points 785
17.6 Handling Internal Boundary Conditions or Singular Points 787
18 Integral Equations and Inverse Theory 790
18.0 Introduction 790
18.1 Fredholm Equations of the Second Kind 793
18.2 Volterra Equations 796
18.3 Integral Equations with Singular Kernels 799
18.4 Inverse Problems and the Use of A Priori Information 806
18.5 Linear Regularization Methods 811
18.6 Backus-Gilbert Method 818
18.7 Maximum Entropy Image Restoration 821
19 Partial Differential Equations 829
19.0 Introduction 829
19.1 Flux-Conservative Initial Value Problems 836
19.2 Diffusive Initial Value Problems 849
19.3 Initial Value Problems in Multidimensions 855
19.4 Fourier and Cyclic Reduction Methods for Boundary Value Problems 859
19.5 Relaxation Methods for Boundary Value Problems 865
19.6 Multigrid Methods for Boundary Value Problems 873
20 Less-Numerical Algorithms 891
20.0 Introduction 891
20.1 Diagnosing Machine Parameters 891
20.2 Gray Codes 896x Contents
20.3 Cyclic Redundancy and Other Checksums 898
20.4 Huffman Coding and Compression of Data 906
20.5 Arithmetic Coding 912
20.6 Arithmetic at Arbitrary Precision 916
References 927
Appendix A: Table of Function Declarations 931
Appendix B: Utility Routines and Classes 939
Appendix C: Converting to Single Precision 957
Index of Programs and Dependencies 959
General Index 972