Programming for Computations - Python : A Gentle Introduction to Numerical Simulations with Python 3. 6.
Material type: TextSeries: Texts in Computational Science and Engineering SeriesPublisher: Cham : Springer International Publishing AG, 2019Copyright date: �2020Edition: 2nd edDescription: 1 online resource (350 pages)Content type: text Media type: computer Carrier type: online resourceISBN: 9783030168773Genre/Form: Electronic books.Additional physical formats: Print version:: Programming for Computations - PythonDDC classification: 004.0151 LOC classification: QA71-90Online resources: Click to ViewIntro -- Preface -- Abstract -- Contents -- List of Exercises -- 1 The First Few Steps -- 1.1 What Is a Program? And What Is Programming? -- 1.1.1 Installing Python -- 1.2 A Python Program with Variables -- 1.2.1 The Program -- 1.2.2 Dissecting the Program -- 1.2.3 Why Use Variables? -- 1.2.4 Mathematical Notation Versus Coding -- 1.2.5 Write and Run Your First Program -- 1.3 A Python Program with a Library Function -- 1.4 Importing from Modules and Packages -- 1.4.1 Importing for Use Without Prefix -- 1.4.2 Importing for Use with Prefix -- 1.4.3 Imports with Name Change -- 1.4.4 Importing from Packages -- 1.4.5 The Modules/Packages Used in This Book -- 1.5 A Python Program with Vectorization and Plotting -- 1.6 Plotting, Printing and Input Data -- 1.6.1 Plotting with Matplotlib -- 1.6.2 Printing: The String Format Method -- 1.6.3 Printing: The f-String -- 1.6.4 User Input -- 1.7 Error Messages and Warnings -- 1.8 Concluding Remarks -- 1.8.1 Programming Demands You to Be Accurate! -- 1.8.2 Write Readable Code -- 1.8.3 Fast Code or Slower and Readable Code? -- 1.8.4 Deleting Data No Longer in Use -- 1.8.5 Code Lines That Are Too Long -- 1.8.6 Where to Find More Information? -- 1.9 Exercises -- Exercise 1.1: Error Messages -- Exercise 1.2: Volume of a Cube -- Exercise 1.3: Area and Circumference of a Circle -- Exercise 1.4: Volumes of Three Cubes -- Exercise 1.5: Average of Integers -- Exercise 1.6: Formatted Print to Screen -- 2 A Few More Steps -- 2.1 Using Python Interactively -- 2.1.1 The IPython Shell -- 2.1.2 Command History -- 2.1.3 TAB Completion -- 2.2 Variables, Objects and Expressions -- 2.2.1 Choose Descriptive Variable Names -- 2.2.2 Reserved Words -- 2.2.3 Assignment -- 2.2.4 Object Type and Type Conversion -- 2.2.5 Automatic Type Conversion -- 2.2.6 Operator Precedence -- 2.2.7 Division-Quotient and Remainder.
2.2.8 Using Parentheses -- 2.2.9 Round-Off Errors -- 2.2.10 Boolean Expressions -- 2.3 Numerical Python Arrays -- 2.3.1 Array Creation and Array Elements -- 2.3.2 Indexing an Array from the End -- 2.3.3 Index Out of Bounds -- 2.3.4 Copying an Array -- 2.3.5 Slicing an Array -- 2.3.6 Two-Dimensional Arrays and Matrix Computations -- 2.4 Random Numbers -- 2.5 Exercises -- Exercise 2.1: Interactive Computing of Volume -- Exercise 2.2: Interactive Computing of Circumference and Area -- Exercise 2.3: Update Variable at Command Prompt -- Exercise 2.4: Multiple Statements on One Line -- Exercise 2.5: Boolean Expression-Even or Odd Number? -- Exercise 2.6: Plotting Array Data -- Exercise 2.7: Switching Values -- Exercise 2.8: Drawing Random Numbers -- 3 Loops and Branching -- 3.1 The for Loop -- 3.1.1 Example: Printing the 5 Times Table -- 3.1.2 Characteristics of a Typical for Loop -- 3.1.3 Combining for Loop and Array -- 3.1.4 Using the range Function -- 3.1.5 Using break and continue -- 3.2 The while Loop -- 3.2.1 Example: Finding the Time of Flight -- 3.2.2 Characteristics of a Typical while Loop -- 3.3 Branching (if, elif and else) -- 3.3.1 Example: Judging the Water Temperature -- 3.3.2 The Characteristics of Branching -- 3.3.3 Example: Finding the Maximum Height -- 3.3.4 Example: Random Walk in Two Dimensions -- 3.4 Exercises -- Exercise 3.1: A for Loop with Errors -- Exercise 3.2: The range Function -- Exercise 3.3: A while Loop with Errors -- Exercise 3.4: while Loop Instead of for Loop -- Exercise 3.5: Compare Integers a and b -- Exercise 3.6: Area of Rectangle Versus Circle -- Exercise 3.7: Frequency of Random Numbers -- Exercise 3.8: Game 21 -- Exercise 3.9: Simple Search: Verification -- Exercise 3.10: Sort Array with Numbers -- Exercise 3.11: Compute -- 4 Functions and the Writing of Code -- 4.1 Functions: How to Write Them?.
4.1.1 Example: Writing Our First Function -- 4.1.2 Characteristics of a Function Definition -- 4.1.3 Functions and the Main Program -- 4.1.4 Local Versus Global Variables -- 4.1.5 Calling a Function Defined with Positional Parameters -- 4.1.6 A Function with Two Return Values -- 4.1.7 Calling a Function Defined with Keyword Parameters -- 4.1.8 A Function with Another Function as Input Argument -- 4.1.9 Lambda Functions -- 4.1.10 A Function with Several Return Statements -- 4.2 Programming as a Step-Wise Strategy -- 4.2.1 Making a Times Tables Test -- 4.2.2 The 1st Version of Our Code -- 4.2.3 The 2nd Version of Our Code -- 4.2.4 The 3rd Version of Our Code -- 4.3 Exercises -- Exercise 4.1: Errors with Colon, Indent, etc. -- Exercise 4.2: Reading Code 1 -- Exercise 4.3: Reading Code 2 -- Exercise 4.4: Functions for Circumference and Area of a Circle -- Exercise 4.5: Function for Adding Vectors -- Exercise 4.6: Function for Area of a Rectangle -- Exercise 4.7: Average of Integers -- Exercise 4.8: When Does Python Check Function Syntax? -- Exercise 4.9: Find Crossing Points of Two Graphs -- Exercise 4.10: Linear Interpolation -- Exercise 4.11: Test Straight Line Requirement -- Exercise 4.12: Fit Straight Line to Data -- Exercise 4.13: Fit Sines to Straight Line -- 5 Some More Python Essentials -- 5.1 Lists and Tuples: Alternatives to Arrays -- 5.2 Exception Handling -- 5.2.1 The Fourth Version of Our Times Tables Program -- 5.3 Symbolic Computations -- 5.3.1 Numerical Versus Symbolic Computations -- 5.3.2 SymPy: Some Basic Functionality -- 5.3.3 Symbolic Calculations with Some Other Tools -- 5.4 Making Our Own Module -- 5.4.1 A Naive Import -- 5.4.2 A Module for Vertical Motion -- 5.4.3 Module or Program? -- 5.5 Files: Read and Write -- 5.6 Measuring Execution Time -- 5.6.1 The timeit Module -- 5.7 Exercises -- Exercise 5.1: Nested for Loops and Lists.
Exercise 5.2: Exception Handling: Divisions in a Loop -- Exercise 5.3: Taylor Series, sympy and Documentation -- Exercise 5.4: Fibonacci Numbers -- Exercise 5.5: Read File: Total Volume of Boxes -- Exercise 5.6: Area of a Polygon -- Exercise 5.7: Count Occurrences of a String in a String -- Exercise 5.8: Compute Combinations of Sets -- 6 Computing Integrals and Testing Code -- 6.1 Basic Ideas of Numerical Integration -- 6.2 The Composite Trapezoidal Rule -- 6.2.1 The General Formula -- 6.2.2 A General Implementation -- 6.2.3 A Specific Implementation: What's the Problem? -- 6.3 The Composite Midpoint Method -- 6.3.1 The General Formula -- 6.3.2 A General Implementation -- 6.3.3 Comparing the Trapezoidal and the Midpoint Methods -- 6.4 Vectorizing the Functions -- 6.4.1 Vectorizing the Midpoint Rule -- 6.4.2 Vectorizing the Trapezoidal Rule -- 6.4.3 Speed up Gained with Vectorization -- 6.5 Rate of Convergence -- 6.6 Testing Code -- 6.6.1 Problems with Brief Testing Procedures -- 6.6.2 Proper Test Procedures -- 6.6.3 Finite Precision of Floating-Point Numbers -- 6.6.4 Constructing Unit Tests and Writing Test Functions -- 6.7 Double and Triple Integrals -- 6.7.1 The Midpoint Rule for a Double Integral -- 6.7.2 The Midpoint Rule for a Triple Integral -- 6.7.3 Monte Carlo Integration for Complex-Shaped Domains -- 6.8 Exercises -- Exercise 6.1: Hand Calculations for the Trapezoidal Method -- Exercise 6.2: Hand Calculations for the Midpoint Method -- Exercise 6.3: Compute a Simple Integral -- Exercise 6.4: Hand-Calculations with Sine Integrals -- Exercise 6.5: Make Test Functions for the Midpoint Method -- Exercise 6.6: Explore Rounding Errors with Large Numbers -- Exercise 6.7: Write Test Functions for 04xdx -- Exercise 6.8: Rectangle Methods -- Exercise 6.9: Adaptive Integration -- Exercise 6.10: Integrating x Raised to x.
Exercise 6.11: Integrate Products of Sine Functions -- Exercise 6.12: Revisit Fit of Sines to a Function -- Exercise 6.13: Derive the Trapezoidal Rule for a Double Integral -- Exercise 6.14: Compute the Area of a Triangle by Monte Carlo Integration -- 7 Solving Nonlinear Algebraic Equations -- 7.1 Brute Force Methods -- 7.1.1 Brute Force Root Finding -- 7.1.2 Brute Force Optimization -- 7.1.3 Model Problem for Algebraic Equations -- 7.2 Newton's Method -- 7.2.1 Deriving and Implementing Newton's Method -- 7.2.2 Making a More Efficient and Robust Implementation -- 7.3 The Secant Method -- 7.4 The Bisection Method -- 7.5 Rate of Convergence -- 7.6 Solving Multiple Nonlinear Algebraic Equations -- 7.6.1 Abstract Notation -- 7.6.2 Taylor Expansions for Multi-Variable Functions -- 7.6.3 Newton's Method -- 7.6.4 Implementation -- 7.7 Exercises -- Exercise 7.1: Understand Why Newton's Method Can Fail -- Exercise 7.2: See If the Secant Method Fails -- Exercise 7.3: Understand Why the Bisection Method Cannot Fail -- Exercise 7.4: Combine the Bisection Method with Newton's Method -- Exercise 7.5: Write a Test Function for Newton's Method -- Exercise 7.6: Halley's Method and the Decimal Module -- Exercise 7.7: Fixed Point Iteration -- Exercise 7.8: Solve Nonlinear Equation for a Vibrating Beam -- 8 Solving Ordinary Differential Equations -- 8.1 Filling a Water Tank: Two Cases -- 8.1.1 Case 1: Piecewise Constant Rate -- 8.1.2 Case 2: Continuously Increasing Rate -- 8.1.3 Reformulating the Problems as ODEs -- 8.2 Population Growth: A First Order ODE -- 8.2.1 Derivation of the Model -- 8.2.2 Numerical Solution: The Forward Euler (FE) Method -- 8.2.3 Programming the FE Scheme -- the Special Case -- 8.2.4 Understanding the Forward Euler Method -- 8.2.5 Programming the FE Scheme -- the General Case -- 8.2.6 A More Realistic Population Growth Model.
8.2.7 Verification: Exact Linear Solution of the Discrete Equations.
Description based on publisher supplied metadata and other sources.
Electronic reproduction. Ann Arbor, Michigan : ProQuest Ebook Central, 2023. Available via World Wide Web. Access may be limited to ProQuest Ebook Central affiliated libraries.
There are no comments on this title.