Preface |
|
xi | |
|
|
|
1 Computers and Programming Languages: An Introduction |
|
|
1 | (10) |
|
1.1 Early History of Computing |
|
|
3 | (1) |
|
|
4 | (1) |
|
1.2.1 Common features of a modern Computer |
|
|
4 | (1) |
|
1.3 What Is Prograrnming? |
|
|
5 | (1) |
|
1.4 Programming Languages Overview |
|
|
5 | (2) |
|
1.5 Numbers Representation in Computers and Its Potential Problems |
|
|
7 | (3) |
|
1.5.1 Discretization---the main weakness of computers |
|
|
7 | (1) |
|
1.5.2 Binary representation |
|
|
8 | (1) |
|
1.5.3 Floating-point number representation |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (20) |
|
2.1 MATLAB's Graphical User Interface |
|
|
11 | (3) |
|
2.2 MATLAB as a Powerful Calculator |
|
|
14 | (3) |
|
2.2.1 MATLAB's variable types |
|
|
14 | (1) |
|
2.2.2 Some built-in functions and operators |
|
|
15 | (1) |
|
2.2.3 Operator precedence |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
|
19 | (6) |
|
2.5.1 Creating and accessing matrix elements |
|
|
19 | (2) |
|
2.5.2 Native matrix operations |
|
|
21 | (3) |
|
2.5.3 Strings as matrices |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
26 | (3) |
|
2.7.1 Saving plots to files |
|
|
28 | (1) |
|
|
29 | (2) |
|
3 Boolean Algebra, Conditional Statements, Loops |
|
|
31 | (10) |
|
|
31 | (2) |
|
3.1.1 Boolean operators precedence in MATLAB |
|
|
32 | (1) |
|
3.1.2 MATLAB Boolean logic examples |
|
|
32 | (1) |
|
|
33 | (2) |
|
3.2.1 Comparison with vectors |
|
|
34 | (1) |
|
3.2.2 Comparison with matrices |
|
|
34 | (1) |
|
3.3 Conditional Statements |
|
|
35 | (1) |
|
3.3.1 The if-else-end statement |
|
|
35 | (1) |
|
3.3.2 Short form of the "if" statement |
|
|
36 | (1) |
|
3.4 Common Mistake with the Equality Statement |
|
|
36 | (1) |
|
|
36 | (4) |
|
|
36 | (2) |
|
3.5.2 Special commands "break" and "continue" |
|
|
38 | (1) |
|
|
38 | (2) |
|
|
40 | (1) |
|
4 Functions, Scripts, and Good Programming Practice |
|
|
41 | (16) |
|
4.1 Motivational Examples |
|
|
41 | (2) |
|
4.1.1 Bank interest rate problem |
|
|
41 | (1) |
|
4.1.2 Time of flight problem |
|
|
42 | (1) |
|
|
43 | (2) |
|
4.2.1 Quadratic equation solver script |
|
|
43 | (2) |
|
|
45 | (2) |
|
4.3.1 Quadratic equation solver function |
|
|
46 | (1) |
|
4.4 Good Programming Practice |
|
|
47 | (4) |
|
|
47 | (1) |
|
4.4.2 Try to foresee unexpected behavior |
|
|
48 | (1) |
|
|
48 | (1) |
|
4.4.4 Check and sanitize input arguments |
|
|
49 | (1) |
|
4.4.5 Is the solution realistic? |
|
|
50 | (1) |
|
4.4.6 Summary of good programming practice |
|
|
51 | (1) |
|
4.5 Recursive and Anonymous Functions |
|
|
51 | (3) |
|
4.5.1 Recursive functions |
|
|
51 | (1) |
|
4.5.2 Anonymous functions |
|
|
52 | (2) |
|
|
54 | (3) |
|
II Solving Everyday Problems with MATLAB |
|
|
57 | (82) |
|
5 Solving Systems of Linear Algebraic Equations |
|
|
59 | (10) |
|
|
59 | (2) |
|
5.2 Built-in MATLAB Solvers |
|
|
61 | (2) |
|
5.2.1 The inverse matrix method |
|
|
61 | (1) |
|
5.2.2 Solution without inverse matrix calculation |
|
|
62 | (1) |
|
5.2.3 Which method to use |
|
|
62 | (1) |
|
5.3 Solution of the Mobile Problem with MATLAB |
|
|
63 | (2) |
|
|
64 | (1) |
|
5.4 Example: Wheatstone Bridge Problem |
|
|
65 | (1) |
|
|
66 | (3) |
|
6 Fitting and Data Reduction |
|
|
69 | (18) |
|
6.1 Necessity for Data Reduction and Fitting |
|
|
69 | (1) |
|
6.2 Formal Definition for Fitting |
|
|
70 | (1) |
|
6.2.1 Goodness of the fit |
|
|
70 | (1) |
|
|
71 | (2) |
|
6.4 Parameter Uncertainty Estimations |
|
|
73 | (1) |
|
6.5 Evaluation of the Resulting Fit |
|
|
74 | (1) |
|
6.6 How to Find the Optimal Fit |
|
|
75 | (9) |
|
6.6.1 Example: Light diffraction on a single slit |
|
|
77 | (1) |
|
|
77 | (1) |
|
6.6.3 Choosing the fit model |
|
|
78 | (1) |
|
6.6.4 Making an initial guess for the fit parameters |
|
|
79 | (1) |
|
6.6.5 Plotting data and the model based on the initial guess |
|
|
80 | (1) |
|
|
81 | (1) |
|
6.6.7 Evaluating uncertainties for the fit parameters |
|
|
82 | (2) |
|
|
84 | (3) |
|
|
87 | (6) |
|
7.1 Estimate of the Derivative via the Forward Difference |
|
|
87 | (1) |
|
7.2 Algorithmic Error Estimate for Numerical Derivative |
|
|
88 | (1) |
|
7.3 Estimate of the Derivative via the Central Difference |
|
|
89 | (2) |
|
|
91 | (2) |
|
8 Root Finding Algorithms |
|
|
93 | (20) |
|
|
93 | (1) |
|
8.2 Trial and Error Method |
|
|
94 | (1) |
|
|
95 | (5) |
|
8.3.1 Bisection use example and test case |
|
|
97 | (3) |
|
8.3.2 Possible improvement of the bisection code |
|
|
100 | (1) |
|
8.4 Algorithm Convergence |
|
|
100 | (1) |
|
8.5 False Position (Regula Falsi) Method |
|
|
101 | (1) |
|
|
102 | (1) |
|
8.7 Newton--Raphson Method |
|
|
103 | (3) |
|
8.7.1 Using Newton--Raphson algorithm with the analytical derivative |
|
|
105 | (1) |
|
8.7.2 Using Newton-Raphson algorithm with the numerical derivative |
|
|
106 | (1) |
|
|
106 | (2) |
|
8.9 Root Finding Algorithms Gotchas |
|
|
108 | (1) |
|
8.10 Root Finding Algorithms Summary |
|
|
109 | (1) |
|
8.11 MATLAB's Root Finding Built-in Command |
|
|
110 | (1) |
|
|
110 | (3) |
|
9 Numerical Integration Methods |
|
|
113 | (16) |
|
9.1 Integration Problem Statement |
|
|
113 | (1) |
|
|
114 | (2) |
|
9.2.1 Rectangle method algorithmic error |
|
|
116 | (1) |
|
|
116 | (2) |
|
9.3.1 Trapezoidal method algorithmic error |
|
|
117 | (1) |
|
|
118 | (1) |
|
9.4.1 Simpson's method algorithmic error |
|
|
118 | (1) |
|
9.5 Generalized Formula for Integration |
|
|
119 | (1) |
|
9.6 Monte Carlo Integration |
|
|
119 | (3) |
|
9.6.1 Toy example: finding the area of a pond |
|
|
119 | (1) |
|
9.6.2 Naive Monte Carlo integration |
|
|
120 | (1) |
|
9.6.3 Monte Carlo integration derived |
|
|
120 | (1) |
|
9.6.4 The Monte Carlo method algorithmic error |
|
|
121 | (1) |
|
9.7 Multidimensional Integration |
|
|
122 | (1) |
|
9.7.1 Minimal example for integration in two dimensions |
|
|
122 | (1) |
|
9.8 Multidimensional Integration with Monte Carlo |
|
|
123 | (1) |
|
9.8.1 Monte Carlo method demonstration |
|
|
124 | (1) |
|
9.9 Numerical Integration Gotchas |
|
|
124 | (1) |
|
9.9.1 Using a very large number of points |
|
|
124 | (1) |
|
9.9.2 Using too few points |
|
|
124 | (1) |
|
9.10 MATLAB Functions for Integration |
|
|
125 | (1) |
|
|
126 | (3) |
|
|
129 | (10) |
|
10.1 The Nearest Neighbor Interpolation |
|
|
129 | (1) |
|
10.2 Linear Interpolation |
|
|
130 | (2) |
|
10.3 Polynomial Interpolation |
|
|
132 | (2) |
|
10.4 Criteria for a Good Interpolation Routine |
|
|
134 | (1) |
|
10.5 Cubic Spline Interpolation |
|
|
134 | (1) |
|
10.6 MATLAB Built-in Interpolation Methods |
|
|
135 | (1) |
|
|
136 | (1) |
|
10.8 Unconventional Use of Interpolation |
|
|
136 | (2) |
|
10.8.1 Finding the location of the data crossing y = 0 |
|
|
136 | (2) |
|
|
138 | (1) |
|
III Going Deeper and Expanding the Scientist's Toolbox |
|
|
139 | (104) |
|
11 Random Number Generators and Random Processes |
|
|
141 | (8) |
|
11.1 Statistics and Probability Introduction |
|
|
141 | (1) |
|
11.1.1 Discrete event probability |
|
|
141 | (1) |
|
11.1.2 Probability density function |
|
|
142 | (1) |
|
11.2 Uniform Random Distribution |
|
|
142 | (1) |
|
11.3 Random Number Generators and Computers |
|
|
143 | (2) |
|
11.3.1 Linear congruential generator |
|
|
144 | (1) |
|
11.3.2 Random number generator period |
|
|
145 | (1) |
|
11.4 How to Check a Random Generator |
|
|
145 | (3) |
|
11.4.1 Simple RNG test with Monte Carlo integration |
|
|
146 | (2) |
|
11.5 MATLAB's Built-in RNGs |
|
|
148 | (1) |
|
|
148 | (1) |
|
12 Monte Carlo Simulations |
|
|
149 | (12) |
|
|
149 | (2) |
|
|
151 | (1) |
|
12.3 One-Dimensional Infection Spread |
|
|
152 | (8) |
|
|
160 | (1) |
|
13 The Optimization Problem |
|
|
161 | (34) |
|
13.1 Introduction to Optimization |
|
|
161 | (1) |
|
13.2 One-Dimensional Optimization |
|
|
162 | (5) |
|
13.2.1 The golden section optimum search algorithm |
|
|
163 | (2) |
|
13.2.2 MATLAB's built-in function for the one-dimension optimization |
|
|
165 | (1) |
|
13.2.3 One-dimensional optimization examples |
|
|
165 | (2) |
|
13.3 Multidimensional Optimization |
|
|
167 | (7) |
|
13.3.1 Examples of multidimensional optimization |
|
|
168 | (6) |
|
13.4 Combinatorial Optimization |
|
|
174 | (9) |
|
|
174 | (4) |
|
13.4.2 Traveling salesman problem |
|
|
178 | (5) |
|
13.5 Simulated Annealing Algorithm |
|
|
183 | (9) |
|
13.5.1 The backpack problem solution with the annealing algorithm |
|
|
185 | (7) |
|
|
192 | (1) |
|
|
193 | (2) |
|
14 Ordinary Differential Equations |
|
|
195 | (18) |
|
14.1 Introduction to Ordinary Differential Equation |
|
|
195 | (2) |
|
|
197 | (1) |
|
14.3 Numerical Method to Solve ODEs |
|
|
197 | (4) |
|
|
197 | (2) |
|
14.3.2 The second-order Runge-Kutta method (RK2) |
|
|
199 | (1) |
|
14.3.3 The fourth-order Runge-Kutta method (RK4) |
|
|
200 | (1) |
|
14.3.4 Other numerical solvers |
|
|
200 | (1) |
|
14.4 Stiff ODEs and Stability Issues of the Numerical Solution |
|
|
201 | (2) |
|
14.5 MATLAB's Built-in ODE Solvers |
|
|
203 | (1) |
|
|
203 | (9) |
|
|
203 | (3) |
|
14.6.2 Motion with the air drag |
|
|
206 | (6) |
|
|
212 | (1) |
|
15 Discrete Fourier-Transform |
|
|
213 | (16) |
|
|
213 | (6) |
|
15.1.1 Example: Fourier series for |t| |
|
|
215 | (2) |
|
15.1.2 Example: Fourier series for the step function |
|
|
217 | (1) |
|
15.1.3 Complex Fourier series representation |
|
|
218 | (1) |
|
15.1.4 Non-periodic functions |
|
|
219 | (1) |
|
15.2 Discrete Fourier Transform (DFT) |
|
|
219 | (2) |
|
15.3 MATLAB's DFT Implementation and Fast Fourier Transform (FFT) |
|
|
221 | (1) |
|
15.4 Compact Mathematical Notation for Fourier Transforms |
|
|
222 | (1) |
|
|
222 | (4) |
|
|
226 | (3) |
|
|
229 | (14) |
|
16.1 Nyquist Frequency and the Minimal Sampling Rate |
|
|
229 | (3) |
|
16.1.1 Under-sampling and aliasing |
|
|
230 | (2) |
|
|
232 | (5) |
|
|
233 | (1) |
|
|
234 | (1) |
|
16.2.3 Band-pass and band-stop filters |
|
|
235 | (2) |
|
|
237 | (2) |
|
|
239 | (2) |
|
|
241 | (2) |
References |
|
243 | (2) |
Index |
|
245 | |