APPLIED NUMERICAL METHODS USING MATLAB® Won Young Yang Chung-Ang University, Korea
Wenwu Cao Pennsylvania State University
Tae-Sang Chung Chung-Ang ...
APPLIED NUMERICAL METHODS USING MATLAB® Won Young Yang Chung-Ang University, Korea
Wenwu Cao Pennsylvania State University
Tae-Sang Chung Chung-Ang University, Korea
John Morris The University of Auckland, New Zealand
WILEYINTERSCIENCE A JOHN WILEY & SONS, INC., PUBLICATION
CONTENTS
Preface 1 MATLAB Usage and Computational Errors
xiii 1
1.1 Basic Operations of MATLAB / 1 1.1.1 Input/Output of Data from MATLAB Command Window / 2 1.1.2 Input/Output of Data Through Files / 2 1.1.3 Input/Output of Data Using Keyboard / 4 1.1.4 2-D Graphic Input/Output / 5 1.1.5 3-D Graphic Output / 10 1.1.6 Mathematical Functions / 10 1.1.7 Operations on Vectors and Matrices / 15 1.1.8 Random Number Generators / 22 1.1.9 Flow Control / 24 1.2 Computer Errors Versus Human Mistakes / 27 1.2.1 IEEE 64-bit Floating-Point Number Representation / 28 1.2.2 Various Kinds of Computing Errors / 31 1.2.3 Absolute/Relative Computing Errors / 33 1.2.4 Error Propagation / 33 1.2.5 Tips for Avoiding Large Errors / 34 1.3 Toward Good Program / 37 1.3.1 Nested Computing for Computational Efnciency / 37 1.3.2 Vector Operation Versus Loop Iteration / 39 1.3.3 Iterative Routine Versus Nested Routine / 40 1.3.4 To Avoid Runtime Error / 40 1.3.5 Parameter Sharing via Global Variables / 44 1.3.6 Parameter Passing Through Varargin / 45 1.3.7 Adaptive Input Argument List / 46 Problems / 46
vii
VÜi
CONTENTS
2 System of Linear Equations 2.1 Solution for a System of Linear Equations / 72 2.1.1 The Nonsingular Case (M = N) I 72 2.1.2 The Underdetermined Case (M < N): Minimum-Norm Solution / 72 2.1.3 The Overdetermined Case (M > N): Least-Squares Error Solution / 75 2.1.4 RLSE (Recursive Least-Squares Estimation) / 76 2.2 Solving a System of Linear Equations / 79 2.2.1 Gauss Elimination / 79 2.2.2 Partial Pivoting / 81 2.2.3 Gauss-Jordan Elimination / 89 2.3 Inverse Matrix / 92 2.4 Decomposition (Factorization) / 92 2.4.1 LU Decomposition (Factorization): Triangularization / 92 2.4.2 Other Decomposition (Factorization): Cholesky, QR, and SVD / 97 2.5 Iterative Methods to Solve Equations / 98 2.5.1 Jacobi Iteration / 98 2.5.2 Gauss-Seidel Iteration / 100 2.5.3 The Convergence of Jacobi and Gauss-Seidel Iterations / 103 Problems / 104 3 Interpolation and Curve Fitting 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8
Interpolation by Lagrange Polynomial / 117 Interpolation by Newton Polynomial / 119 Approximation by Chebyshev Polynomial / 124 Pade Approximation by Rational Function / 129 Interpolation by Cubic Spline / 133 Hermite Interpolating Polynomial / 139 Two-dimensional Interpolation / 141 Curve Fitting / 143 3.8.1 Straight Line Fit: A Polynomial Function of First Degree / 144 3.8.2 Polynomial Curve Fit: A Polynomial Function of Higher Degree / 145 3.8.3 Exponential Curve Fit and Other Functions / 149 3.9 Fourier Transform / 150 3.9.1 FFT Versus DFT / 151 3.9.2 Physical Meaning of DFT / 152 3.9.3 Interpolation by Using DFS / 155 Problems / 157
Iterative Method Toward Fixed Point / 179 Bisection Method / 183 False Position or Regula Falsi Method / 185 Newton(-Raphson) Method / 186 Secant Method / 189 Newton Method for a System of Nonlinear Equations / 191 Symbolic Solution for Equations / 193 A Real-World Problem / 194 Problems / 197
5 Numerical Differentiation/Integration
209
5.1 Difference Approximation for First Derivative / 209 5.2 Approximation Error of First Derivative / 211 5.3 Difference Approximation for Second and Higher Derivative / 216 5.4 Interpolating Polynomial and Numerical Differential / 220 5.5 Numerical Integration and Quadrature / 222 5.6 Trapezoidal Method and Simpson Method / 226 5.7 Recursive Rule and Romberg Integration / 228 5.8 Adaptive Quadrature / 231 5.9 Gauss Quadrature / 234 5.9.1 Gauss-Legendre Integration / 235 5.9.2 Gauss-Hermite Integration / 238 5.9.3 Gauss-Laguerre Integration / 239 5.9.4 Gauss-Chebyshev Integration / 240 5.10 Double Integral / 241 Problems / 244 6 Ordinary Differential Equations 6.1 6.2 6.3 6.4