Modeling and Simulation in Python

Book description

Modeling and Simulation in Python is a thorough but easy-to-follow introduction to physical modeling—that is, the art of describing and simulating real-world systems.

Readers are guided through modeling things like world population growth, infectious disease, bungee jumping, baseball flight trajectories, celestial mechanics, and more while simultaneously developing a strong understanding of fundamental programming concepts like loops, vectors, and functions.

Clear and concise, with a focus on learning by doing, the author spares the reader abstract, theoretical complexities and gets right to hands-on examples that show how to produce useful models and simulations.

Table of contents

  1. Cover Page
  2. PRAISE FOR MODELING AND SIMULATION IN PYTHON
  3. Title Page
  4. Copyright Page
  5. About the Author
  6. About the Technical Reviewer
  7. BRIEF CONTENTS
  8. CONTENTS IN DETAIL
  9. ACKNOWLEDGMENTS
  10. INTRODUCTION
    1. Who Is This Book For?
      1. How Much Math and Science Do I Need?
      2. How Much Programming Do I Need?
    2. Book Overview
    3. Teaching Modeling
    4. Getting Started
      1. Installing Python
      2. Running Jupyter
    5. Suggestions and Corrections
  11. PART I DISCRETE SYSTEMS
  12. 1 INTRODUCTION TO MODELING
    1. The Modeling Framework
    2. Testing the Falling Penny Myth
    3. Computation in Python
      1. False Precision
      2. Computation with Units
    4. Summary
    5. Exercises
  13. 2 MODELING A BIKE SHARE SYSTEM
    1. Our Bike Share Model
    2. Defining Functions
    3. Print Statements
    4. if Statements
    5. Parameters
    6. for Loops
    7. TimeSeries
    8. Plotting
    9. Summary
    10. Exercises
    11. Under the Hood
  14. 3 ITERATIVE MODELING
    1. Iterating on Our Bike Share Model
    2. Using More Than One State Object
    3. Documentation
    4. Dealing with Negative Bikes
    5. Comparison Operators
    6. Introducing Metrics
    7. Summary
    8. Exercises
  15. 4 PARAMETERS AND METRICS
    1. Functions That Return Values
    2. Loops and Arrays
    3. Sweeping Parameters
    4. Incremental Development
    5. Summary
    6. Exercises
    7. Challenge Exercises
    8. Under the Hood
  16. 5 BUILDING A POPULATION MODEL
    1. Exploring the Data
    2. Absolute and Relative Errors
    3. Modeling Population Growth
    4. Simulating Population Growth
    5. Summary
    6. Exercise
  17. 6 ITERATING THE POPULATION MODEL
    1. System Objects
    2. A Proportional Growth Model
    3. Factoring Out the Update Function
    4. Combining Birth and Death
    5. Summary
    6. Exercise
    7. Under the Hood
  18. 7 LIMITS TO GROWTH
    1. Quadratic Growth
    2. Net Growth
    3. Finding Equilibrium
    4. Dysfunctions
    5. Summary
    6. Exercises
  19. 8 PROJECTING INTO THE FUTURE
    1. Generating Projections
    2. Comparing Projections
    3. Summary
    4. Exercise
  20. 9 ANALYSIS AND SYMBOLIC COMPUTATION
    1. Difference Equations
    2. Differential Equations
    3. Analysis and Simulation
    4. Analysis with WolframAlpha
    5. Analysis with SymPy
    6. Differential Equations in SymPy
    7. Solving the Quadratic Growth Model
    8. Summary
    9. Exercises
  21. 10 CASE STUDIES PART I
    1. Historical World Population
    2. One Queue or Two?
    3. Predicting Salmon Populations
    4. Tree Growth
  22. PART II FIRST-ORDER SYSTEMS
  23. 11 EPIDEMIOLOGY AND SIR MODELS
    1. The Freshman Plague
    2. The Kermack-McKendrick Model
    3. The KM Equations
    4. Implementing the KM Model
    5. The Update Function
    6. Running the Simulation
    7. Collecting the Results
    8. Now with a TimeFrame
    9. Summary
    10. Exercise
  24. 12 QUANTIFYING INTERVENTIONS
    1. The Effects of Immunization
    2. Choosing Metrics
    3. Sweeping Immunization
    4. Summary
    5. Exercise
  25. 13 SWEEPING PARAMETERS
    1. Sweeping Beta
    2. Sweeping Gamma
    3. Using a SweepFrame
    4. Summary
    5. Exercise
  26. 14 NONDIMENSIONALIZATION
    1. Beta and Gamma
    2. Exploring the Results
    3. Contact Number
    4. Comparing Analysis and Simulation
    5. Estimating the Contact Number
    6. Summary
    7. Exercises
    8. Under the Hood
  27. 15 THERMAL SYSTEMS
    1. The Coffee Cooling Problem
    2. Temperature and Heat
    3. Heat Transfer
    4. Newton’s Law of Cooling
    5. Implementing Newtonian Cooling
    6. Finding Roots
    7. Estimating r
    8. Summary
    9. Exercises
  28. 16 SOLVING THE COFFEE PROBLEM
    1. Mixing Liquids
    2. Mix First or Last?
    3. Optimal Timing
    4. The Analytic Solution
    5. Summary
    6. Exercises
  29. 17 MODELING BLOOD SUGAR
    1. The Minimal Model
    2. The Glucose Minimal Model
    3. Getting the Data
    4. Interpolation
    5. Summary
    6. Exercises
  30. 18 IMPLEMENTING THE MINIMAL MODEL
    1. Implementing the Model
    2. The Update Function
    3. Running the Simulation
    4. Solving Differential Equations
    5. Summary
    6. Exercise
  31. 19 CASE STUDIES PART II
    1. Revisiting the Minimal Model
    2. The Insulin Minimal Model
    3. Low-Pass Filter
    4. Thermal Behavior of a Wall
    5. HIV
  32. PART III SECOND-ORDER SYSTEMS
  33. 20 THE FALLING PENNY REVISITED
    1. Newton’s Second Law of Motion
    2. Dropping Pennies
    3. Event Functions
    4. Summary
    5. Exercise
  34. 21 DRAG
    1. Calculating Drag Force
    2. The Params Object
    3. Simulating the Penny Drop
    4. Summary
    5. Exercises
  35. 22 TWO-DIMENSIONAL MOTION
    1. Assumptions and Decisions
    2. Vectors
    3. Simulating Baseball Flight
    4. Drag Force
    5. Adding an Event Function
    6. Visualizing Trajectories
    7. Animating the Baseball
    8. Summary
    9. Exercises
  36. 23 OPTIMIZATION
    1. The Manny Ramirez Problem
    2. Finding the Range
    3. Summary
    4. Exercise
    5. Under the Hood
  37. 24 ROTATION
    1. The Physics of Toilet Paper
    2. Setting Parameters
    3. Simulating the System
    4. Plotting the Results
    5. The Analytic Solution
    6. Summary
    7. Exercise
  38. 25 TORQUE
    1. Angular Acceleration
    2. Moment of Inertia
    3. Teapots and Turntables
    4. Two-Phase Simulation
      1. Phase 1
      2. Phase 2
      3. Combining the Results
    5. Estimating Friction
    6. Animating the Turntable
    7. Summary
    8. Exercise
  39. 26 CASE STUDIES PART III
    1. Bungee Jumping
    2. Bungee Dunk Revisited
    3. Orbiting the Sun
    4. Spider-Man
    5. Kittens
    6. Simulating a Yo-Yo
    7. Congratulations
  40. APPENDIX: UNDER THE HOOD
    1. How run_solve_ivp Works
    2. How root_scalar Works
    3. How maximize_scalar Works
  41. INDEX

Product information

  • Title: Modeling and Simulation in Python
  • Author(s): Allen B. Downey
  • Release date: May 2023
  • Publisher(s): No Starch Press
  • ISBN: 9781718502161