Numerical Methods
for Engineers and Scientists
An Introduction with
®
Applications using MATLAB
Third Edition
Amos Gilat
Vish- Subramaniam
Department of Mechanical Engineering
The Ohio State University
Wiley
Contents
iii
Preface
Chapter 1
Introduction
l
1.1
Background 1
1.2 Representation of Numbers on a Computer
1.3 Errors in Numerical Solutions
Round-OffErrors
10
1.3.2 Truncation Errors
13
1.3.1
1.3.3 Total Error
14
15
1.4 Computers and Programming
18
1.5 Problems
Chapter 2
2.1
Mathematical Background
2.2 Concepts from Pre-Calculus and Calculus
2.3 Vectors
23
23
Background
2.3.1
4
10
24
28
30
Operations with Vectors
32
2.4 Matrices and Linear Algebra
2.4.1
Operations with Matrices
2.4.2
Special Matrices '35
2.4.3 Inverse ofa Matrix
33
36
2.4.4 Properties ofMatrices
2.4.5 Determinant of a Matrix
37
37
2.4.6 Cramer's Rule and Solution of a System of Simultaneous Linear Equations
2.4.7 Norms
38
40
2.5
Ordinary Differential Equations (ODE) 41
2.6 Functions of Two or More Independent Variables
2.6.1
Definition ofthe Partial Derivative
2.6.2 Chain Rule
2.6.3 TheJacobian
2.7
45
46
Taylor Series Expansion of Functions
2.7.1
2.7.2
44
44
47
Taylor Series for a Function ofOne Variable 47
Taylor Series for a Function of Two Variables 49
2.8 Inner Product and Orthogonality
2.9 Problems
50
51
xi
Contents
Chapter 3
Solving Nonlinear Equations
Background
3.1
57
3.2 Estimation of Errors in Numerical Solutions
3.3 Bisection Method
3.5 Newton's Method
3.6 Secant Method
59
61
64
Regula Falsi Method
3.4
57
66
71
3.7 Fixed-Point Iteration Method
74
3.8 Use of MATLAB Built-in Functions for Solving Nonlinear Equations
3.8.1 The f zero Command 78
3.8.2 The roots Command
79
79
Equations with Multiple Solutions
3.10 Systems of Nonlinear Equations
3.9
81
3.10.1 Newton's Methodfor Solving a System ofNonlinear Equations
3.10.2
4.1
82
Fixed-Point Iteration Methodfor Solving a System ofNonlinear Equations
3.11 Problems
Chapter 4
77
88
Solving a System ofLinear Equations
Background
86
99
99
4.1.1 Overview ofNumerical Methods for Solving a System ofLinear Algebraic Equations
102
4.2 Gauss Elimination Method
When
4.2.1 Potential Difficulties
Applying the Gauss Elimination Method
4.3 Gauss Elimination with Pivoting
4.4
115
118
120
4.5.1 LU Decomposition Using the Gauss Elimination Procedure
4.5.2 LU Decomposition Using Crout's Method
4.5.3 LU Decomposition with Pivoting
4.6 Inverse of a Matrix
4.6.1
121
128
128
Calculating the Inverse with the LU Decomposition Method
4.6.2 Calculating the Inverse Using the Gauss-Jordan Method
4.7 Iterative Methods
110
112
Gauss-Jordan Elimination Method
4.5 LU Decomposition Method
129
131
132
4.7.1 JacobiIterative Method
133
4.7.2 Gauss-Seidel Iterative Method
133
4.8 Use of MATLAB Built-in Functions for Solving a System of Linear Equations
4.8.1 Solving a System ofEquations Using MATLAB's Left and Right Division 136
Solving a System of Equations Using MATLAB"s Inverse Operation
138
4.8.3 MATLAB's Built-in Function for LUDecomposition
4.8.2
-
4.9
100
4.8.4 Additional MATLAB Built-in Functions
Tridiagonal Systems of Equations
141
139
137
136
Contents
4.10
xiii
Error, Residual, Norms, and Condition Number
4.10.1 Error and Residual
4.10.2 Norms and Condition Number
4.11 Ill-Conditioned Systems
4.12 Problems
Chapter 5
5.1
146
146
148
153
155
Eigenvalues and Eigenvectors
165
165
Background
5.2 The Characteristic Equation
5.3 The Basic Power Method
167
167
5.4 The Inverse Power Method
172
5.5 The Shifted Power Method
173
5.6 The QR Factorization and Iteration Method
174
5.7 Use of MATLAB Built-in Functions for Determining Eigenvalues and
Eigenvectors
5.8
6.1
186
Problems
Chapter 6
184
Curve Fitting and Interpolation
Background
193
193
6.2 Curve Fitting with a Linear Equation
6.2.1 Measuring How Good Is a Fit
195
195
6.2.2 Linear Least-Squares Regression
197
6.3 Curve Fitting with Nonlinear Equation by Writing the
Equation in a Linear Form
6.4 Curve Fitting with Quadratic and Higher-Order Polynomials
6.5
Interpolation
6.5.1
Using a
Single Polynomial
210
Lagrange Interpolating Polynomials
212
6.5.2 Newton's Interpolating Polynomials
216
6.6 Piecewise (Spline) Interpolation
6.6.1 Linear Splines
6.6.2
6.6.3
205
223
223
Quadratic Splines 225
Cubic Splines
229
6.7 Use of MATLAB Built-in Functions for Curve Fitting and
Interpolation
6.8 Curve Fitting with a Linear Combination of Nonlinear Functions
6.9 Problems
Chapter 7
241
Fourier Methods
251
7.1
Background
7.2
Approximating a Square Wave by a Series of Sine Functions
251
7.3 General (Infinite) Fourier Series
7.4
257
Complex Form of the Fourier Series
261
253
238
236
201
Contents
xiv
7.5 The Discrete Fourier Series and Discrete Fourier Transform
268
7.6 Complex Discrete Fourier Transform
7.7 Power (Energy) Spectrum
263
271
7.8 Aliasing and Nyquist Frequency
272
7.9 Alternative Forms of the Discrete Fourier Transform
278
7.10 Use of MATLAB Built-in Functions for Calculating Discrete Fourier Transform
7.11
Leakage and Windowing
7.12 Bandwidth and Filters
284
286
289
7.13 The Fast Fourier Transform (FFT)
7.14 Problems
Chapter 8
298
Numerical Differentiation
8.1 Background
303
303
8.2 Finite Difference Approximation of the Derivative
305
8.3 Finite Difference Formulas Using Taylor Series Expansion
8.3.1 Finite Difference Formulas ofFirst Derivative
310
310
8.3.2 Finite Difference Formulasfor the Second Derivative
315
Summary of Finite Difference Formulas for Numerical Differentiation
319
8.5 Differentiation Formulas Using Lagrange Polynomials
320
8.6 Differentiation Using Curve Fitting
8.4
8.7 Use of MATLAB Built-in Functions for Numerical Differentiation
8.8 Richardson's Extrapolation
322
8.9 Error in Numerical Differentiation
325
8.10 Numerical Partial Differentiation
327
8.11
Problems
Chapter 9
9.1
330
Numerical Integration
Background
341
341
9.1.1 Overview ofApproaches in Numerical Integration
9.2
9.3
Rectangle and Midpoint Methods
Trapezoidal Method
9.3.1
9.4
344
346
Composite Trapezoidal Method
347
Simpson's Methods 350
9.4.1 Simpson's 1/3 Method 350
9.4.2 Simpson's3/8Method 353
9.5 Gauss Quadrature
355
9.6 Evaluation of Multiple Integrals
9.7
342
360
Use of MATLAB Built-in Functions for Integration
9.8 Estimation of Error in Numerical Integration
9.9 Richardson's Extrapolation
366
364
362
320
317
278
,
Contents
xv
9.10
Romberg Integration
9.11
Improper Integrals
9.11.1
369
372
Integrals with Singularities
372
373
9.11.2 Integrals with Unbounded Limits
9.12
Problems
Chapter 10
374
Ordinary Differential Equations: Initial- Value
Problems
10.1 Background
385
385
10.2 Euler's Methods
390
390
10.2.1 Euler 's Explicit Method
10.2.2 Analysis of Truncation Error in Euler's Explicit Method
10.2.3 Euler's Implicit Method
10.3 Modified Euler's Method
10.4
Midpoint Method
10.5
Runge-Kutta Methods
401
404
405
10.5.1 Second-Order Runge-Kutta Methods
10.5.2 Third-Order Runge-Kutta Methods
10.5.3 Fourth-Order Runge-Kutta Methods
10.6
Multistep Methods
394
398
406
410
411
-
417
10.6.1 Adams-BashforthMethod
10.6.2 Adams-Moulton Method
10.7 Predictor-Corrector Methods
418
419
420
System of First-Order Ordinary Differential Equations 422
Solving a System ofFirst-Order ODEs Using Euler's Explicit Method 424
10.8.2 Solving a System ofFirst-Order ODEs Using Second-Order Runge-Kutta Method
(Modified Euler Version) 424
10.8.3 Solving a System ofFirst-Order ODEs Using the Classical Fourth-Order Runge-Kutta
10.8
10.8.1
Method
10.9
431
Solving a Higher-Order Initial Value Problem
432
10.10 Use of MATLAB Built-in Functions for Solving Initial-Value Problems
10.10.1
10.10.2
Solving a Single First-Order ODE Using MATLAB 438
Solving a System ofFirst-Order ODEs Using MATLAB 444
10.11 Local Truncation Error in Second-Order Range-Kutta Method
10.12
Step Size for Desired Accuracy
448
Stability 452
10.14 Stiff Ordinary Differential Equations
10.13
10.15 Problems
457
454
447
437
Contents
xvi
Chapter 11
Ordinary Differential Equations: Boundary- Value
Problems
471
11.1
Background 471
11.2 The Shooting Method
474
11.3 Finite Difference Method
482
11.4 Use of MATLAB Built-in Functions for Solving Boundary Value Problems
11.5 Error and Stability in Numerical Solution of Boundary Value Problems
11.6 Problems
499
Appendix A Introductory MATLAB
A. 1
A.2 Starting with MATLAB
Arrays
509
509
Background
A.3
497
509
514
A.4 Mathematical Operations with Arrays
519
Script Files 524
A.6 Plotting 526
A.5
A.7 User-Defined Functions and Function Files
Anonymous Functions
A. 8
A.9 Function functions
A. 10 Subfunctions
A. 11
530
532
535
Programming in MATLAB
537
A. 11.1 Relational and Logical Operators
537
A.11.2 Conditional Statements, if-else Structures
Loops
541
A. 12 Problems
542
A. 11.3
528
Appendix B MATLAB Programs
538
547
Appendix C Derivation of the Real Discrete Fourier Transform
(DFT)
C. 1
551
Orthogonality of Sines and Cosines for Discrete Points
C.2 Determination of the Real DFT
Index
555
553
551
492