Numerical Methods for
Engineers
and Scientists
Using
MATLAB®
Second
Edition
Ramin
S.
Esfandiari,
PhD
CRC Press
CJI*'
J Taylor&.FrancisGroup Boca Raton London New York CRC Press isanimprintof theContents
Preface xv
Acknowledgments
X1XAuthor xxi
1.
Background
and Introduction 1Part 1:
Background
11.1 Differential
Equations
11.1.1 Linear,First-Order ODEs 1 1.1.2 Second-Order ODEswithConstantCoefficients 2 1.1.2.1
Homogeneous
Solution 2 1.1.2.2 Particular Solution 3 1.1.3 Method ofUndeterminedCoefficients 31.2 Matrix
Analysis
4 1.2.1 MatrixOperations
5 1.2.2 MatrixTranspose
5 1.2.3Special
Matrices 6 1.2.4 Determinant ofaMatrix 6 1.2.5Properties
of Determinant 6 1.2.5.1 Cramer's Rule .-. 7 1.2.6 Inverse ofaMatrix 8 1.2.7Properties
of Inverse 9 1.2.8Solving
aLinearSystem
ofEquations
91.3 Matrix
Eigenvalue
Problem 9 1.3.1Solving
theEigenvalue
Problem 10 1.3.2Similarity
Transformation 11 1.3.3 MatrixDiagonalization
11 1.3.4Eigenvalue Properties
of Matrices 12 Part 2: IntroductiontoNumericalMethods 12 1.4 Errors andApproximations
12 1.4.1 Sources ofComputational
Error 12 1.4.2Binary
andHexadecimalNumbers 13 1.4.3Floating
Point andRounding
Errors 13 1.4.4 Round-Off:Chopping
andRounding
14 1.4.5 Absolute and RelativeErrors 151.4.6 Error Bound 16
1.4.7 Transmission ofErrorfromaSourceto
J:he
Final Result 16 1.4.8 Subtraction ofNearly Equal
Numbers 171.5 Iterative Methods 19
1.5.1 FundamentalIterativeMethod 20 1.5.2 Rate of
Convergence
ofanIterativeMethod 21ProblemSet
(Chapter
1)
222. IntroductiontoMATLAB® 27
2.1 MATLAB Built-in Functions 27 vii
viii Contents
2.1.1
Rounding
Commands 272.1.2 Relational
Operators
282.1.3 Format
Options
282.2 Vectors and Matrices 29
2.2.1
Linspace
302.2.2 Matrices 30
2.2.3 Determinant,
Transpose,
and Inverse 322.2.4 Slash
Operators
332.2.5
Element-by-Element
Operations
33 2.2.6Diagonal
Matrices andDiagonals
ofaMatrix 342.3
Symbolic
MathToolbox 36 2.3.1Anonymous
Functions 382.3.2 MATLABFunction 38
2.3.3 Differentiation 39
2.3.4 Partial Derivatives 40
2.3.5
Integration
402.4
Program
Flow Control 412.4.1 for
Loop
412.4.2 The ifCommand 42
2.4.3 while
Loop
432.5
Displaying
FormattedData 432.5.1 Differential
Equations
442.6
Plotting
452.6.1
subplot
452.6.2
Plotting Analytical Expressions
462.6.3
Multiple
Plots 462.7 User-Defined Functions and
Script
Files 47 2.7.1Setting
DefaultValues forInput
Variables 49 2.7.2Creating Script
Files 50ProblemSet
(Chapter 2)
513. Numerical Solution of
Equations
ofaSingle
Variable 553.1 Numerical Solution of
Equations
553.2 Bisection Method 55
3.2.1 MATLAB Built-inFunction fzero 60
3.3
Regula
Falsi Method(Method
ofFalsePosition)
61 3.3.1 ModifiedRegula
FalsiMethod 643.4 Fixed-PointMethod 65
3.4.1 Selection ofaSuitable IterationFunction 66
3.4.2 A Note on
Convergence
67 3.4.3 Rate ofConvergence
of the Fixed-Point Iteration 71 3.5 Newton's Method(Newton-Raphson
Method)
72 3.5.1 Rate ofConvergence
of Newton's Method 76 3.5.2 AFew NotesonNewton's Method 77 3.5.3 Modified Newton's Method for Roots withMultiplicity
2 or
Higher
783.6 Secant Method 81
3.6.1 Rate of
Convergence
of Secant Method 83 3.6.2 AFew NotesonSecant Method 83Contents 1X
3.7
Equations
with Several Roots 833.7.1
Finding
RootstotheRight
ofaSpecified
Point 833.7.2
Finding
Several Roots inanIntervalUsing
fzero 84ProblemSet
(Chapter
3)
884. Numerical Solution of
Systems
ofEquations
954.1 Linear
Systems
ofEquations
954.2 Numerical Solution of Linear
Systems
964.3 Gauss Elimination Method 96
4.3.1
Choosing
thePivot Row: PartialPivoting
with RowScaling
98 4.3.2 PermutationMatrices 99 4.3.3Counting
the NumberofOperations
1024.3.3.1 Elimination 102
4.3.3.2 BackSubstitution 103 4.3.4
Tridiagonal Systems
103 4.3.4.1 ThomasMethod 104 4.3.4.2 MATLABBuilt-in Function«\«
106 4.4 LU Factorization Methods 107 4.4.1 DoolittleFactorization 107 4.4.2Finding
L and UUsing Steps
of Gauss Elimination 108 4.4.3Finding
L and UDirectly
108 4.4.3.1 Doolittle's MethodtoSolve aLinearSystem
1104.4.3.2
Operations
Count 112 4.4.4Cholesky
Factorization 112 4.4.4.1Cholesky's
Method toSolveaLinearSystem
1134.4.4.2
Operations
Count 115 4.4.4.3 MATLAB Built-inFunctionsluand chol 115 4.5 Iterative Solution ofLinearSystems
1164.5.1 Vector Norms 116
4.5.2 Matrix Norms 118
4.5.2.1
Compatibility
of Vector and Matrix Norms 119 4.5.3 General Iterative Method 120 4.5.3.1Convergence
of the General IterativeMethod 120 4.5.4Jacobi
Iteration Method 121 4.5.4.1Convergence
of theJacobi
Iteration Method 122 4.5.5 Gauss-Seidel Iteration Method 1254.5.5.1
Convergence
of theGauss-Seidel Iteration Method 127 4.5.6 Indirect MethodsversusDirectMethods forLarge Systems
1304.6
Ill-Conditioning
and ErrorAnalysis
1314.6.1 Condition Number 131 4.6.2
Ill-Conditioning
1324.6.2.1 Indicatorsof
Ill-Conditioning
1334.6.3
Computational
Error 133 4.6.3.1Consequences
ofIll-Conditioning
1354.6.4 Effectsof Parameter
Changes
onthe Solution 1364.7
Systems
of NonlinearEquations
1384.7.1 Newton'sMethod fora
System
of NonlinearEquations
1384.7.1.1 Newton'sMethodfor
Solving
aSystem
ofX Contents
4.7.1.2 Newton's Method for
Solving
aSystem
ofnNonlinearEquations
1424.7.1.3
Convergence
of Newton's Method 142 4.7.2 Fixed-PointIterationMethod foraSystem
of NonlinearEquations....
1434.7.2.1
Convergence
of the Fixed-Point Iteration Method 143ProblemSet
(Chapter
4)
1465. Curve
Fitting
andInterpolation
1615.1
Least-Squares Regression
1615.2 Linear
Regression
1625.2.1
Deciding
a"Best" FitCriterion 1635.2.2 Linear
Least-Squares Regression
1645.3 Linearization of Nonlinear Data 167 5.3.1
Exponential
Function 1675.3.2 PowerFunction 167
5.3.3 SaturationFunction 168
5.4
Polynomial Regression
1725.4.1
Quadratic
Least-Squares Regression
1745.4.2 Cubic
Least-Squares Regression
1765.4.3 MATLAB Built-in Functions Polyfit and
Polyval
1785.5
Polynomial
Interpolation
1795.5.1
Lagrange Interpolating Polynomials
180 5.5.2 Drawbacks ofLagrange
Interpolation
183 5.5.3 NewtonDivided-DifferenceInterpolating
Polynomials
1845.5.4
Special
Case:Equally-Spaced
Data 1905.5.5 NewtonForward-Difference
Interpolating Polynomials
1915.6
Spline Interpolation
1935.6.1 Linear
Splines
1945.6.2
Quadratic
Splines
1955.6.2.1 Function Valuesatthe
Endpoints
(2
Equations)
1955.6.2.2 FunctionValuesattheInterior Knots
(2n
-2Equations)
1965.6.2.3 FirstDerivativesatthe Interior Knots
(n
- 1Equations)
1965.6.2.4 Second Derivativeatthe Left
Endpoint
is Zero(1
Equation)....
1965.6.3 Cubic
Splines
1985.6.3.1
Clamped Boundary
Conditions 199 5.6.3.2 FreeBoundary
Conditions 199 5.6.4 Construction of CubicSplines: Clamped Boundary
Conditions 199 5.6.5 Constructionof CubicSplines:
FreeBoundary
Conditions 204 5.6.6 MATLABBuilt-in Functions interpland spline 205 5.6.7Boundary
Conditions 2075.6.8 Interactive Curve
Fitting
andInterpolation
inMATLAB 208 5.7 FourierApproximation
andInterpolation
209 5.7.1 Sinusoidal CurveFitting
209 5.7.1.1 FourierApproximation
210 5.7.1.2 FourierInterpolation
210 5.7.2 Linear Transformationof Data 210 5.7.3 Discrete FourierTransform 2155.7.4 Fast FourierTransform 216 5.7.4.1
Sande-Tukey Algorithm
(N
=2?,
p=integer)
217Contents xl
5.7.4.2 Case
Study:
N=23=8 2185.7.4.3
Cooley-Tukey Algorithm
(N
=2v,p
=integer)
2195.7.5 MATLABBuilt-inFunctionf f t 220 5.7.5.1
Interpolation Using
f f t 220Problem Set
(Chapter
5)
2236. NumericalDifferentiationand
Integration
249 6.1 Numerical Differentiation 249 6.2 Finite-DifferenceFormulas for Numerical Differentiation 249 6.2.1 Finite-Difference Formulas for the First Derivative 250 6.2.1.1 Two-PointBackward DifferenceFormula 2506.2.1.2 Two-Point Forward Difference Formula 251
6.2.1.3 Two-Point Central Difference Formula 251 6.2.1.4 Three-Point BackwardDifference Formula 252
6.2.1.5 Three-Point Forward DifferenceFormula 253
6.2.2 Finite-Difference FormulasfortheSecondDerivative 254
6.2.2.1 Three-Point BackwardDifference Formula 254
6.2.2.2 Three-PointForward Difference Formula 254
6.2.2.3 Three-Point CentralDifference Formula 255
6.2.2.4
Summary
ofFinite-Difference Formulas for FirsttoFourthDerivatives 256
6.2.3 Estimate
Improvement:
Richardson'sExtrapolation
2566.2.4 Richardson's
Extrapolation
for Discrete Sets of Data 2596.2.5 Derivative Estimatesfor
Non-Evenly Spaced
Data 2596.2.6 MATLAB Built-in Functions dif f andpolyder 260
6.3 Numerical
Integration:
Newton-Cotes Formulas 261 6.3.1 Newton-Cotes Formulas 2626.3.2
Rectangular
Rule 2626.3.2.1
Composite Rectangular
Rule 262 6.3.3 Error Estimate forComposite Rectangular
Rule 264 6.3.4Trapezoidal
Rule 266 6.3.4.1Composite Trapezoidal
Rule 267 6.3.4.2 Error Estimate forComposite Trapezoidal
Rule 2676.3.5
Simpson's
Rules 2696.3.5.1
Simpson's
1/3 Rule 269 6.3.5.2Composite Simpson's
1/3Rule 270 6.3.5.3 Error Estimate forComposite Simpson's
1/3
Rule 270 6.3.5.4Simpson's
3/8Rule 271 6.3.5.5Composite
Simpson's
3/8Rule 272 6.3.5.6 Error Estimate forComposite Simpson's
3/8
Rule 273 6.3.6 MATLAB Built-in Functionsquad andtrapz 273 6.4 NumericalIntegration
ofAnalytical
Functions:Romberg Integration,
Gaussian
Quadrature
275 6.4.1Romberg Integration
275 6.4.1.1 Richardson'sExtrapolation
275 6.4.1.2Romberg Integration
278 6.4.2 GaussianQuadrature
280 6.5Improper Integrals
285xii Contents
7. Numerical SolutionofInitial-Value Problems 301
7.1 Introduction 301
7.2
One-Step
Methods 3017.3 Euler'sMethod 302
7.3.1 Error
Analysis
for Euler's Method 305 7.3.2 Calculation of Local and Global Truncation Errors 3057.3.3
Higher-Order
Taylor
Methods 3077.4
Runge-Kutta
Methods 3097.4.1 Second-Order
Runge-Kutta
(RK2)
Methods 3107.4.1.1
Improved
Euler's Method 3117.4.1.2 Heun's Method 311
7.4.1.3 Ralston's Method 312 7.4.1.4
Graphical Representation
ofHeun'sMethod 312 7.4.2 Third-OrderRunge-Kutta (RK3)
Methods 315 7.4.2.1 The Classical RK3 Method 315 7.4.2.2 Heun's RK3 Method 315 7.4.3 Fourth-OrderRunge-Kutta
(RK4)
Methods 316 7.4.3.1 The ClassicalRK4 Method 3177.4.4
Higher-Order Runge-Kutta
Methods 319 7.4.5 Selection ofOptimal Step
Size:Runge-Kutta Fehlberg (RKF)
Method 320
7.4.5.1
Adjustment
ofStep
Size 3217.5
Multistep
Methods 3227.5.1 Adams-Bashforth Method 323
7.5.1.1 Second-Order Adams-Bashforth Formula 324 7.5.1.2 Third-Order Adams-Bashforth Formula 324 7.5.1.3 Fourth-Order Adams-Bashforth Formula 324 7.5.2 Adams-MoultonMethod 325 7.5.2.1 Second-Order Adams-Moulton Formula 326 7.5.2.2 Third-Order Adams-Moulton Formula 326 7.5.2.3 Fourth-OrderAdams-Moulton Formula 326
7.5.3 Predictor-CorrectorMethods 326
7.5.3.1 Heun'sPredictor-Corrector Method 327 7.5.3.2 Adams-Bashforth-Moulton
(ABM)
Predictor-Corrector Method 327
7.6
Systems
ofOrdinary
DifferentialEquations
330 7.6.1 Transformation into aSystem
ofFirst-OrderODEs 3307.6.1.1 State Variables 330
7.6.1.2 Notation 330
7.6.1.3 State-Variable
Equations
330 7.6.2 Numerical Solution ofaSystem
of First-Order ODEs 3327.6.2.1 Euler's Method for
Systems
3327.6.2.2 Heun's Method for
Systems
3357.6.2.3 Classical RK4 Method for
Systems
3367.7
Stability
3407.7.1 Euler's Method 341
7.7.2 Euler's
Implicit
Method 341 7.8 StiffDifferentialEquations
343 7.9 MATLABBuilt-inFunctionsforSolving
Initial-ValueProblems 345Contents xm
7.9.1 Non-Stiff
Equations
3457.9.2 A
Single
First-Order IVP 345 7.9.3Setting
ODESolverOptions
347 7.9.4 ASystem
of First-Order IVPs 3487.9.5 Stiff
Equations
349Problem Set
(Chapter
7)
3508. Numerical Solution of
Boundary-Value
Problems 3678.1 Second-OrderBVP 367
8.2
Boundary
Conditions 3678.3
Higher-Order
BVP 3688.4
Shooting
Method 3688.5 Finite-DifferenceMethod 374
8.5.1
Boundary-Value
Problemswith MixedBoundary
Conditions 3798.6 MATLAB Built-in Functionbvp4cfor
Boundary-Value
Problems 3818.6.1 Second-OrderBVP 382
Problem Set
(Chapter
8)
3869. Matrix
Eigenvalue
Problem 3939.1 Matrix
Eigenvalue
Problem 3939.2 Power Method: Estimation of the Dominant
Eigenvalue
3939.2.1 Different Cases of Dominant
Eigenvalue
3959.2.2
Algorithm
for thePower Method 3959.3 Inverse Power Method: Estimation of the Smallest
Eigenvalue
3989.4 Shifted Inverse PowerMethod: Estimation of the
Eigenvalue
Nearesta
Specified
Value 3999.4.1 NotesontheShifted Inverse PowerMethod 400
9.5 ShiftedPowerMethod 401
9.5.1
Strategy
to EstimateAllEigenvalues
ofaMatrix 4019.6 MATLABBuilt-inFunction e
ig
4039.7 Deflation Methods 403
9.7.1 Wielandt's Deflation Method 404
9.7.2 DeflationProcess 405 9.8 Householder
Tridiagonalization
andQR
Factorization Methods 4079.8.1 Householder's
Tridiagonalization
Method(Symmetric
Matrices)
4089.8.2 Determination of
Symmetric Orthogonal
Pk (k
=1,2,... ,n-2)
4099.8.3
QR
Factorization Method 4119.8.4 Determinationof
Qk
andRfc
Matrices 4129.8.5 Structure of
Lk (k
=2,3,..n)
4129.9 MATLAB Built-in Functionqr 413
9.10 ANote onthe
Terminating
Condition Usedin HouseholderQR 414 9.11 TransformationtoHessenberg
Form(Nonsymmetric
Matrices)
417Problem Set
(Chapter 9)
41810. Numerical Solution of Partial Differential
Equations
42310.1 Introduction 423
10.2
Elliptic
Partial DifferentialEquations
424 10.2.1 Dirichlet Problem 424xiv Contents
10.2.2
Alternating
DirectionImplicit
(ADI)
Methods 428 10.2.2.1 Peaceman-RachfordAlternating
DirectionImplicit
(PRADI)
Method 42910.2.3 Neumann Problem 433 10.2.3.1 Existence ofaSolution for the NeumannProblem 435
10.2.4 Mixed Problem 436
10.2.5 More
Complex Regions
43710.3 Parabolic Partial Differential
Equations
440 10.3.1 Finite-Difference Method 44010.3.1.1
Stability
andConvergence
of the Finite-DifferenceMethod 441
10.3.2 Crank-Nicolson Method 443
10.3.2.1 Crank-Nicolson
(CN)
MethodversusFinite-Difference(FD)
Method 44610.4
Hyperbolic
PartialDifferentialEquations
44810.4.1
Starting
the Procedure 449 Problem Set(Chapter
10)
452