Python Programming and Numerical Methods: A Guide for Engineers and Scientists introduces programming tools and numerical methods to engineering and science students, with the goal of helping the students to develop good computational problem-solving techniques through the use of numerical methods and the Python programming language. Part One introduces fundamental programming concepts, using simple examples to put new concepts quickly into practice. Part Two covers the fundamentals of algorithms and numerical analysis at a level that allows students to quickly apply results in practical settings.
Author(s): Qingkai Kong, Timmy Siauw, Alexandre Bayen
Edition: 1
Publisher: Academic Press
Year: 2020
Language: English
Commentary: Vector PDF
Pages: 480
City: London, UK
Tags: Programming; Python; Ordinary Differential Equations; Parallel Programming; Data Visualization; Numerical Methods; Linear Regression; Recursion; Linear Algebra; Interpolation; Fourier Transform
Contents
List of Figures
Preface
Purpose
Prerequisites
Organization
How to Read This Book?
Why Python?
Python and Package Versions
Acknowledgements
1 Python Basics
1.1 Getting Started With Python
1.1.1 Setting Up Your Working Environment
1.1.2 Three Ways to Run Python Code
1.2 Python as a Calculator
1.3 Managing Packages
1.3.1 Managing Packages Using Package Managers
Install a Package
Upgrade a Package
Uninstall a Package
Other Useful Commands
1.3.2 Install Packages From Source
1.4 Introduction to Jupyter Notebook
1.4.1 Starting the Jupyter Notebook
1.4.2 Within the Notebook
1.4.3 How Do I Close a Notebook?
1.4.4 Shutting Down the Jupyter Notebook Server
1.5 Logical Expressions and Operators
1.6 Summary and Problems
1.6.1 Summary
1.6.2 Problems
2 Variables and Basic Data Structures
2.1 Variables and Assignment
2.2 Data Structure - String
2.3 Data Structure - List
2.4 Data Structure - Tuple
2.5 Data Structure - Set
2.6 Data Structure - Dictionary
2.7 Introducing NumPy Arrays
2.8 Summary and Problems
2.8.1 Summary
2.8.2 Problems
3 Functions
3.1 Function Basics
3.1.1 Built-In Functions in Python
3.1.2 Define Your Own Function
3.2 Local Variables and Global Variables
3.3 Nested Functions
3.4 Lambda Functions
3.5 Functions as Arguments to Functions
3.6 Summary and Problems
3.6.1 Summary
3.6.2 Problems
4 Branching Statements
4.1 If-Else Statements
4.2 Ternary Operators
4.3 Summary and Problems
4.3.1 Summary
4.3.2 Problems
5 Iteration
5.1 For-Loops
5.2 While Loops
5.3 Comprehensions
5.3.1 List Comprehension
5.3.2 Dictionary Comprehension
5.4 Summary and Problems
5.4.1 Summary
5.4.2 Problems
6 Recursion
6.1 Recursive Functions
6.2 Divide-and-Conquer
6.2.1 Tower of Hanoi
6.2.2 Quicksort
6.3 Summary and Problems
6.3.1 Summary
6.3.2 Problems
7 Object-Oriented Programming
7.1 Introduction to OOP
7.2 Class and Object
7.2.1 Class
7.2.2 Object
7.2.3 Class vs Instance Attributes
7.3 Inheritance, Encapsulation, and Polymorphism
7.3.1 Inheritance
7.3.1.1 Inheriting and Extending New Method
7.3.1.2 Inheriting and Method Overriding
7.3.1.3 Inheriting and Updating Attributes With Super
7.3.2 Encapsulation
7.3.3 Polymorphism
7.4 Summary and Problems
7.4.1 Summary
7.4.2 Problems
8 Complexity
8.1 Complexity and Big-O Notation
8.2 Complexity Matters
8.3 The Profiler
8.3.1 Using the Magic Command
8.3.2 Use Python Profiler
8.3.3 Use Line Profiler
8.4 Summary and Problems
8.4.1 Summary
8.4.2 Problems
9 Representation of Numbers
9.1 Base-N and Binary
9.2 Floating Point Numbers
9.3 Round-Off Errors
9.3.1 Representation Error
9.3.2 Round-Off Error by Floating-Point Arithmetic
9.3.3 Accumulation of Round-Off Errors
9.4 Summary and Problems
9.4.1 Summary
9.4.2 Problems
10 Errors, Good Programming Practices, and Debugging
10.1 Error Types
10.2 Avoiding Errors
10.2.1 Plan Your Program
10.2.2 Test Everything Often
10.2.3 Keep Your Code Clean
10.3 Try/Except
10.4 Type Checking
10.5 Debugging
10.5.1 Activating Debugger After Running Into an Exception
10.5.2 Activating Debugger Before Running the Code
10.5.3 Add a Breakpoint
10.6 Summary and Problems
10.6.1 Summary
10.6.2 Problems
11 Reading and Writing Data
11.1 TXT Files
11.1.1 Writing to a File
11.1.2 Appending a File
11.1.3 Reading a File
11.1.4 Dealing With Numbers and Arrays
11.2 CSV Files
11.2.1 Writing and Opening a CSV File
11.2.2 Reading a CSV File
11.2.3 Beyond NumPy
11.3 Pickle Files
11.3.1 Writing to a Pickle File
11.3.2 Reading a Pickle File
11.3.3 Reading in Python 2 Pickle File
11.4 JSON Files
11.4.1 JSON Format
11.4.2 Writing a JSON File
11.4.3 Reading a JSON File
11.5 HDF5 Files
11.5.1 Reading an HDF5 File
11.6 Summary and Problems
11.6.1 Summary
11.6.2 Problems
12 Visualization and Plotting
12.1 2D Plotting
12.2 3D Plotting
12.3 Working With Maps
12.4 Animations and Movies
12.5 Summary and Problems
12.5.1 Summary
12.5.2 Problems
13 Parallelize Your Python
13.1 Parallel Computing Basics
13.1.1 Process and Thread
13.1.2 Python's GIL Problem
13.1.3 Disadvantages of Using Parallel Computing
13.2 Multiprocessing
13.2.1 Visualize the Execution Time
13.3 Using Joblib
13.4 Summary and Problems
13.4.1 Summary
13.4.2 Problems
14 Linear Algebra and Systems of Linear Equations
14.1 Basics of Linear Algebra
14.1.1 Sets
14.1.2 Vectors
14.1.3 Matrices
14.2 Linear Transformations
14.3 Systems of Linear Equations
14.4 Solutions to Systems of Linear Equations
14.4.1 Gauss Elimination Method
14.4.2 Gauss-Jordan Elimination Method
14.4.3 LU Decomposition Method
14.4.4 Iterative Methods - Gauss-Seidel Method
14.4.4.1 Gauss-Seidel Method
14.5 Solving Systems of Linear Equations in Python
14.6 Matrix Inversion
14.7 Summary and Problems
14.7.1 Summary
14.7.2 Problems
15 Eigenvalues and Eigenvectors
15.1 Eigenvalues and Eigenvectors Problem Statement
15.1.1 Eigenvalues and Eigenvectors
15.1.2 The Motivation Behind Eigenvalues and Eigenvectors
15.1.3 The Characteristic Equation
15.2 The Power Method
15.2.1 Finding the Largest Eigenvalue
15.2.2 The Inverse Power Method
15.2.3 The Shifted Power Method
15.3 The QR Method
15.4 Eigenvalues and Eigenvectors in Python
15.5 Summary and Problems
15.5.1 Summary
15.5.2 Problems
16 Least Squares Regression
16.1 Least Squares Regression Problem Statement
16.2 Least Squares Regression Derivation (Linear Algebra)
16.3 Least Squares Regression Derivation (Multivariate Calculus)
16.4 Least Squares Regression in Python
16.4.1 Using the Direct Inverse Method
16.4.2 Using the Pseudo-Inverse
16.4.3 Using numpy.linalg.lstsq
16.4.4 Using optimize.curve_fit From SciPy
16.5 Least Squares Regression for Nonlinear Functions
16.5.1 Log Tricks for Exponential Functions
16.5.2 Log Tricks for Power Functions
16.5.3 Polynomial Regression
16.5.4 Using optimize.curve_fit From SciPy
16.6 Summary and Problems
16.6.1 Summary
16.6.2 Problems
17 Interpolation
17.1 Interpolation Problem Statement
17.2 Linear Interpolation
17.3 Cubic Spline Interpolation
17.4 Lagrange Polynomial Interpolation
17.4.1 Using the Lagrange Function From SciPy
17.5 Newton's Polynomial Interpolation
17.6 Summary and Problems
17.6.1 Summary
17.6.2 Problems
18 Taylor Series
18.1 Expressing Functions Using a Taylor Series
18.2 Approximations Using Taylor Series
18.3 Discussion About Errors
18.3.1 Truncation Errors for Taylor Series
18.3.2 Estimating Truncation Errors
18.3.3 Round-Off Errors for Taylor Series
18.4 Summary and Problems
18.4.1 Summary
18.4.2 Problems
19 Root Finding
19.1 Root Finding Problem Statement
19.2 Tolerance
19.3 Bisection Method
19.4 Newton-Raphson Method
19.5 Root Finding in Python
19.6 Summary and Problems
19.6.1 Summary
19.6.2 Problems
20 Numerical Differentiation
20.1 Numerical Differentiation Problem Statement
20.2 Using Finite Difference to Approximate Derivatives
20.2.1 Using Finite Difference to Approximate Derivatives With Taylor Series
20.3 Approximating of Higher Order Derivatives
20.4 Numerical Differentiation With Noise
20.5 Summary and Problems
20.5.1 Summary
20.5.2 Problems
21 Numerical Integration
21.1 Numerical Integration Problem Statement
21.2 Riemann Integral
21.3 Trapezoid Rule
21.4 Simpson's Rule
21.5 Computing Integrals in Python
21.6 Summary and Problems
21.6.1 Summary
21.6.2 Problems
22 Ordinary Differential Equations (ODEs) Initial-Value Problems
22.1 ODE Initial Value Problem Statement
22.2 Reduction of Order
22.3 The Euler Method
22.4 Numerical Error and Instability
22.5 Predictor-Corrector and Runge-Kutta Methods
22.5.1 Predictor-Corrector Methods
22.5.2 Runge-Kutta Methods
22.5.2.1 Second-Order Runge-Kutta Method
22.5.2.2 Fourth-Order Runge-Kutta Method
22.6 Python ODE Solvers
22.7 Advanced Topics
22.7.1 Multistep Methods
22.7.2 Stiffness ODE
22.8 Summary and Problems
22.8.1 Summary
22.8.2 Problems
23 Boundary-Value Problems for Ordinary Differential Equations (ODEs)
23.1 ODE Boundary Value Problem Statement
23.2 The Shooting Method
23.3 The Finite Difference Method
23.4 Numerical Error and Instability
23.5 Summary and Problems
23.5.1 Summary
23.5.2 Problems
24 Fourier Transform
24.1 The Basics of Waves
24.1.1 Modeling a Wave Using Mathematical Tools
24.1.2 Characteristics of a Wave
24.2 Discrete Fourier Transform (DFT)
24.2.1 DFT
24.2.2 The Inverse DFT
24.2.3 The Limit of DFT
24.3 Fast Fourier Transform (FFT)
24.3.1 Symmetries in the DFT
24.3.2 Tricks in FFT
24.4 FFT in Python
24.4.1 FFT in NumPy
24.4.2 FFT in SciPy
24.4.3 More Examples
24.4.3.1 Electricity Demand in California
24.4.3.2 Filtering a Signal in Frequency Domain
24.5 Summary and Problems
24.5.1 Summary
24.5.2 Problems
A Getting Started With Python in Windows
A.1 Getting Started With Python in Windows
A.1.1 Setting Up Your Working Environment in Windows
A.1.2 Three Ways to Run Python Code
Index