1 Introduction to MATLAB 1
1.1 The Golden Ratio 1
1.2 Fibonacci Numbers 7
1.3 Fractal Fern 13
1.4 Magic Squares 18
1.5 Cryptography 26
1.6 The 3n+1 Sequence 31
1.7 Floating-Point Arithmetic 33
1.8 Further Reading 41
Exercises 41
2 Linear Equations 53
2.1 Solving Linear Systems 53
2.2 The MATLAB Backslash Operator 54
2.3 A 3-by-3 Example 54
2.4 Permutation and Triangular Matrices 56
2.5 LU Factorization 57
2.6 Why Is Pivoting Necessary? 58
2.7 lutx,bslashtx,lugui 60
2.8 Effect of Roundoff Errors 63
2.9 Norms and Condition Numbers 66
2.10 Sparse Matrices and Band Matrices 72
2.11 PageRank and Markov Chains 74
2.12 Further Reading 81
Exercises 82
3 Interpolation 93
3.1 The Interpolating Polynomial 93
3.2 Piecewise Linear Interpolation 98
3.3 Piecewise Cubic Hermite Interpolation 99
3.4 Shape-Preserving Piecewise Cubic 100
3.5 Cubic Spline 102
3.6 pchiptx,splinetx 105
3.7 interpgui 108
Exercises 110
4 Zeros and Roots 117
4.1 Bisection 117
4.2 Newton’s Method 119
4.3 A Perverse Example 121
4.4 Secant Method 122
4.5 Inverse Quadratic Interpolation 123
4.6 Zeroin 124
4.7 fzerotx,feval 124
4.8 fzerogui 129
4.9 Value Finding and Reverse Interpolation 132
4.10 Optimization and fmintx 132
Exercises 135
5 Least Squares 141
5.1 Models and Curve Fitting 141
5.2 Norms 143
5.3 censusgui 144
5.4 Householder Reflections 145
5.5 The QR Factorization 147
5.6 Pseudoinverse 152
5.7 Rank Deficiency 154
5.8 Separable Least Squares 156
5.9 Further Reading 159
Exercises 159
6 Quadrature 167
6.1 Adaptive Quadrature 167
6.2 Basic Quadrature Rules 168
6.3 quadtx,quadgui 170
6.4 Specifying Integrands 173
6.5 Performance 175
6.6 Integrating Discrete Data 177
6.7 Further Reading 179
Exercises 179
7 Ordinary Differential Equations 187
7.1 Integrating Differential Equations 187
7.2 Systems of Equations 188
7.3 Linearized Differential Equations 189
7.4 Single-Step Methods 191
7.5 The BS23 Algorithm 194
7.6 ode23tx 196
7.7 Examples 199
7.8 Lorenz Attractor 202
7.9 Stiffness 204
7.10 Events 208
7.11 Multistep Methods 212
7.12 The MATLAB ODE Solvers 212
7.13 Errors 213
7.14 Performance 217
7.15 Further Reading 219
Exercises 219
8 Fourier Analysis 237
8.1 Touch-Tone Dialing 237
8.2 Finite Fourier Transform 241
8.3 fftgui 242
8.4 Sunspots 244
8.5 Periodic Time Series 248
8.6 Fast Finite Fourier Transform 249
8.7 ffttx 250
8.8 fftmatrix 251
8.9 Other Fourier Transforms and Series 252
8.10 Further Reading 254
Exercises 254
9 Random Numbers 257
9.1 Pseudorandom Numbers 257
9.2 Uniform Distribution 257
9.3 Normal Distribution 260
9.4 randtx,randntx 263
Exercises 265
10 Eigenvalues and Singular Values 269
10.1 Eigenvalue and Singular Value Decompositions 269
10.2 A Small Example 272
10.3 eigshow 273
10.4 Characteristic Polynomial 275
10.5 Symmetric and Hermitian Matrices 276
10.6 Eigenvalue Sensitivity and Accuracy 277
10.7 Singular Value Sensitivity and Accuracy 283
10.8 Jordan and Schur Forms 284
10.9 The QR Algorithm 285
10.10 eigsvdgui 287
10.11 Principal Components 289
10.12 Circle Generator 293
10.13 Further Reading 298
Exercises 298
11 Partial Differential Equations 307
11.1 Model Problems 307
11.2 Finite Difference Methods 308
11.3 Matrix Representation 310
11.4 Numerical Stability 312
11.5 The L-Shaped Membrane 314
Exercises 319
Bibliography 327
Index 332