Modeling and Simulation in Python: An Introduction for Scientists and Engineers

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Modeling and Simulation in Python teaches readers how to analyze real-world scenarios using the Python programming language, requiring no more than a background in high school math. 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.

Author(s): Allen B. Downey
Edition: 1
Publisher: No Starch Press
Year: 2023

Language: English
Pages: 311

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