Preface |
|
xiii | |
|
|
xvii | |
|
|
1 | (27) |
|
|
2 | (1) |
|
|
3 | (1) |
|
1.3 Summary of Python Features |
|
|
4 | (6) |
|
|
4 | (1) |
|
|
5 | (1) |
|
|
6 | (2) |
|
1.3.4 User-Defined Functions |
|
|
8 | (2) |
|
|
10 | (3) |
|
1.4.1 List Comprehensions |
|
|
10 | (1) |
|
1.4.2 Iterating Idiomatically |
|
|
11 | (2) |
|
1.5 Basic Plotting with matplotlib |
|
|
13 | (2) |
|
|
15 | (6) |
|
1.7 Project: Visualizing Electric Fields |
|
|
21 | (4) |
|
1.7.1 Electric Field of a Distribution of Point Charges |
|
|
21 | (1) |
|
1.7.2 Plotting Field Lines |
|
|
22 | (3) |
|
|
25 | (3) |
|
|
28 | (57) |
|
|
28 | (1) |
|
|
29 | (9) |
|
2.2.1 Absolute and Relative Error |
|
|
30 | (2) |
|
|
32 | (6) |
|
2.3 Representing Real Numbers |
|
|
38 | (7) |
|
|
38 | (1) |
|
|
39 | (1) |
|
|
40 | (1) |
|
2.3.4 Revisiting Subtraction |
|
|
41 | (3) |
|
|
44 | (1) |
|
2.4 Rounding Errors in the Wild |
|
|
45 | (15) |
|
2.4.1 Are Roundoff Errors Random? |
|
|
45 | (2) |
|
2.4.2 Compensated Summation |
|
|
47 | (2) |
|
2.4.3 Naive vs Manipulated Expressions |
|
|
49 | (1) |
|
2.4.4 Computing the Exponential Function |
|
|
50 | (5) |
|
2.4.5 An Even Worse Case: Recursion |
|
|
55 | (3) |
|
2.4.6 When Rounding Errors Cancel |
|
|
58 | (2) |
|
2.5 Project: the Multipole Expansion in Electromagnetism |
|
|
60 | (16) |
|
2.5.1 Potential of a Distribution of Point Charges |
|
|
60 | (5) |
|
2.5.2 Expansion for One Point Charge |
|
|
65 | (6) |
|
2.5.3 Expansion for Many Point Charges |
|
|
71 | (5) |
|
|
76 | (9) |
|
|
85 | (36) |
|
|
85 | (1) |
|
3.1.1 Examples from Physics |
|
|
85 | (1) |
|
3.1.2 The Problem to Be Solved |
|
|
86 | (1) |
|
3.2 Analytical Differentiation |
|
|
86 | (1) |
|
|
87 | (18) |
|
3.3.1 Noncentral-Difference Approximations |
|
|
87 | (4) |
|
3.3.2 Central-Difference Approximation |
|
|
91 | (2) |
|
|
93 | (2) |
|
3.3.4 More Accurate Finite Differences |
|
|
95 | (1) |
|
|
96 | (1) |
|
|
97 | (4) |
|
3.3.7 Richardson Extrapolation |
|
|
101 | (4) |
|
3.4 Automatic Differentiation |
|
|
105 | (4) |
|
|
105 | (1) |
|
|
106 | (1) |
|
|
107 | (2) |
|
3.5 Project: Local Kinetic Energy in Quantum Mechanics |
|
|
109 | (8) |
|
3.5.1 Single-Particle Wave Functions in One Dimension |
|
|
109 | (5) |
|
|
114 | (3) |
|
|
117 | (4) |
|
|
121 | (122) |
|
|
121 | (4) |
|
4.1.1 Examples from Physics |
|
|
121 | (2) |
|
4.1.2 The Problems to Be Solved |
|
|
123 | (2) |
|
|
125 | (21) |
|
4.2.1 From a posteriori to a priori Estimates |
|
|
126 | (1) |
|
4.2.2 Magnitude of Determinant? |
|
|
127 | (2) |
|
4.2.3 Norms for Matrices and Vectors |
|
|
129 | (2) |
|
4.2.4 Condition Number for Linear Systems |
|
|
131 | (4) |
|
4.2.5 Condition Number for Simple Eigenvalues |
|
|
135 | (6) |
|
4.2.6 Sensitivity of Eigenvectors |
|
|
141 | (5) |
|
4.3 Solving Systems of Linear Equations |
|
|
146 | (29) |
|
4.3.1 Triangular Matrices |
|
|
147 | (5) |
|
4.3.2 Gaussian Elimination |
|
|
152 | (7) |
|
|
159 | (6) |
|
|
165 | (6) |
|
4.3.5 Jacobi Iterative Method |
|
|
171 | (4) |
|
|
175 | (31) |
|
|
177 | (4) |
|
4.4.2 Inverse-Power Method with Shifting |
|
|
181 | (6) |
|
|
187 | (17) |
|
4.4.4 All Eigenvalues and Eigenvectors |
|
|
204 | (2) |
|
4.5 Project: the Schrodinger Eigenvalue Problem |
|
|
206 | (27) |
|
|
206 | (5) |
|
|
211 | (12) |
|
|
223 | (3) |
|
|
226 | (7) |
|
|
233 | (10) |
|
|
243 | (68) |
|
|
243 | (3) |
|
5.1.1 Examples from Physics |
|
|
243 | (1) |
|
5.1.2 The Problem(s) to Be Solved |
|
|
244 | (2) |
|
5.2 Nonlinear Equation in One Variable |
|
|
246 | (26) |
|
|
247 | (1) |
|
5.2.2 Order of Convergence and Termination Criteria |
|
|
248 | (2) |
|
5.2.3 Fixed-Point Iteration |
|
|
250 | (6) |
|
|
256 | (4) |
|
|
260 | (5) |
|
|
265 | (4) |
|
|
269 | (3) |
|
5.2.8 Summary of One-Dimensional Methods |
|
|
272 | (1) |
|
|
272 | (7) |
|
|
273 | (1) |
|
5.3.2 One Root at a Time: Newton's Method |
|
|
274 | (3) |
|
5.3.3 All the Roots at Once: Eigenvalue Approach |
|
|
277 | (2) |
|
5.4 Systems of Nonlinear Equations |
|
|
279 | (8) |
|
|
280 | (2) |
|
5.4.2 Discretized Newton Method |
|
|
282 | (1) |
|
|
283 | (4) |
|
|
287 | (10) |
|
5.5.1 One-Dimensional Minimization |
|
|
287 | (2) |
|
5.5.2 Multidimensional Minimization |
|
|
289 | (3) |
|
|
292 | (3) |
|
|
295 | (2) |
|
5.6 Project: Extremizing the Action in Classical Mechanics |
|
|
297 | (7) |
|
5.6.1 Defining and Extremizing the Action |
|
|
297 | (1) |
|
5.6.2 Discretizing the Action |
|
|
298 | (1) |
|
5.6.3 Newton's Method for the Discrete Action |
|
|
299 | (2) |
|
|
301 | (3) |
|
|
304 | (7) |
|
|
311 | (82) |
|
|
311 | (6) |
|
6.1.1 Examples from Physics |
|
|
311 | (2) |
|
6.1.2 The Problems to Be Solved |
|
|
313 | (4) |
|
6.2 Polynomial Interpolation |
|
|
317 | (16) |
|
|
319 | (3) |
|
6.2.2 Lagrange Interpolation |
|
|
322 | (7) |
|
|
329 | (2) |
|
6.2.4 Hermite Interpolation |
|
|
331 | (2) |
|
6.3 Cubic-Spline Interpolation |
|
|
333 | (8) |
|
|
333 | (2) |
|
|
335 | (3) |
|
|
338 | (3) |
|
6.4 Trigonometric Interpolation |
|
|
341 | (20) |
|
|
342 | (1) |
|
6.4.2 Finite Series: Trigonometric Interpolation |
|
|
343 | (5) |
|
6.4.3 Discrete Fourier Transform |
|
|
348 | (13) |
|
6.5 Least-Squares Fitting |
|
|
361 | (15) |
|
|
362 | (2) |
|
|
364 | (4) |
|
6.5.3 General Linear Fit: Normal Equations |
|
|
368 | (8) |
|
6.6 Project: Testing the Stefan-Boltzmann Law |
|
|
376 | (11) |
|
6.6.1 Beyond Linear Fitting |
|
|
377 | (1) |
|
6.6.2 Total Power Radiated by a Black Body |
|
|
378 | (2) |
|
6.6.3 Fitting to the Lummer and Pringsheim Data |
|
|
380 | (7) |
|
|
387 | (6) |
|
|
393 | (101) |
|
|
393 | (3) |
|
7.1.1 Examples from Physics |
|
|
393 | (1) |
|
7.1.2 The Problem to Be Solved |
|
|
394 | (2) |
|
|
396 | (18) |
|
|
397 | (3) |
|
|
400 | (1) |
|
7.2.3 Integration from Interpolation |
|
|
401 | (1) |
|
|
402 | (5) |
|
|
407 | (4) |
|
|
411 | (1) |
|
|
412 | (2) |
|
|
414 | (5) |
|
7.3.1 Doubling the Number of Panels |
|
|
415 | (1) |
|
7.3.2 Thoughts before Implementing |
|
|
416 | (1) |
|
|
417 | (2) |
|
|
419 | (8) |
|
7.4.1 Richardson Extrapolation |
|
|
419 | (2) |
|
|
421 | (4) |
|
|
425 | (2) |
|
|
427 | (14) |
|
7.5.1 Gauss-Legendre: n = 2 Case |
|
|
428 | (1) |
|
7.5.2 Gauss-Legendre: General Case |
|
|
429 | (10) |
|
7.5.3 Other Gaussian Quadratures |
|
|
439 | (2) |
|
7.6 Complicating the Narrative |
|
|
441 | (7) |
|
|
441 | (1) |
|
|
442 | (2) |
|
|
444 | (2) |
|
7.6.4 Multidimensional Integrals |
|
|
446 | (2) |
|
7.6.5 Evaluating Different Integration Methods |
|
|
448 | (1) |
|
|
448 | (25) |
|
|
449 | (4) |
|
7.7.2 Monte Carlo Quadrature |
|
|
453 | (5) |
|
7.7.3 Monte Carlo beyond the Uniform Distribution |
|
|
458 | (5) |
|
|
463 | (2) |
|
7.7.5 Monte Carlo in Many Dimensions |
|
|
465 | (8) |
|
7.8 Project: Variational Quantum Monte Carlo |
|
|
473 | (13) |
|
7.8.1 Hamiltonian and Wave Function |
|
|
474 | (5) |
|
|
479 | (7) |
|
|
486 | (8) |
|
|
494 | (65) |
|
|
494 | (4) |
|
8.1.1 Examples from Physics |
|
|
494 | (2) |
|
8.1.2 The Problems to Be Solved |
|
|
496 | (2) |
|
8.2 Initial-Value Problems |
|
|
498 | (31) |
|
|
499 | (7) |
|
8.2.2 Second-Order Runge-Kutta Methods |
|
|
506 | (5) |
|
8.2.3 Fourth-Order Runge-Kutta Method |
|
|
511 | (11) |
|
8.2.4 Simultaneous Differential Equations |
|
|
522 | (7) |
|
8.3 Boundary-Value Problems |
|
|
529 | (7) |
|
|
530 | (2) |
|
|
532 | (4) |
|
|
536 | (9) |
|
|
537 | (4) |
|
|
541 | (4) |
|
8.5 Project: Poisson's Equation in Two Dimensions |
|
|
545 | (7) |
|
|
545 | (1) |
|
8.5.2 Poisson's Equation via FFT |
|
|
546 | (6) |
|
|
552 | (7) |
|
Appendix A Installation and Setup |
|
|
559 | (1) |
|
Appendix B Number Representations |
|
|
560 | (6) |
|
|
560 | (1) |
|
|
561 | (4) |
|
B.2.1 Single-Precision Floating-Point Numbers |
|
|
562 | (2) |
|
B.2.2 Double-Precision Floating-Point Numbers |
|
|
564 | (1) |
|
|
565 | (1) |
|
Appendix C Math Background |
|
|
566 | (7) |
|
|
566 | (1) |
|
|
567 | (3) |
|
|
570 | (3) |
|
C.3.1 Discrete Random Variables |
|
|
570 | (2) |
|
C.3.2 Continuous Random Variables |
|
|
572 | (1) |
Bibliography |
|
573 | (4) |
Index |
|
577 | |