Contents in Detail
PRAISE FOR MODELING AND SIMULATION IN PYTHON
Downey uses a combination of Python, calculus, bespoke helper functions, and easily accessible online materials to model a diverse and interesting set of simulation projects. In the process, he presents a practical and reusable framework for modeling dynamical systems with Python.
LEE VAUGHAN, AUTHOR OF PYTHON TOOLS FOR SCIENTISTS, REAL-WORLD PYTHON, AND IMPRACTICAL PYTHON PROJECTS AND FORMER SENIOR PRINCIPAL SCIENTIST AT EXXONMOBIL
Modeling and Simulation in Python is an introduction to physical modeling using a computational approach [which] makes it possible to work with more realistic models than what you typically see in a first-year physics class.
PYTHON KITCHEN
An impressive introduction to physical modeling and Python programming, featuring clear, concise explanations and examples... perfect for readers of any level.
CHRISTIAN MAYER, AUTHOR OF PYTHON ONE-LINERS AND FOUNDER OF FINXTER.COM
Modeling and Simulation in Python provides a wealth of instructive examples of all kinds of modeling.... This book can be valuable as a textbook for classes on scientific computation or as a guide to exploration for interested amateurs.
BRADFORD TUCKFIELD, AUTHOR OF DIVE INTO ALGORITHMS AND DIVE INTO DATA SCIENCE
Downeys book fills a significant gap in the market. For those unwilling to commit to the prolonged dullness of a bottom-up approach to programming, Downeys top-down, context-rich, and motivating approach dramatically lowers the barrier to gaining literacy in programming and explicitly and insightfully teaches modeling.
PHAT VU, DIRECTOR OF THE SCIENCE AND MATHEMATICS PROGRAM AT SOKA UNIVERSITY OF AMERICA
MODELING AND SIMULATION IN PYTHON
An Introduction for Scientists and Engineers
by Allen B. Downey
San Francisco
MODELING AND SIMULATION IN PYTHON. Copyright 2023 by Allen B. Downey.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
27 26 25 24 23 1 2 3 4 5
ISBN-13: 978-1-7185-0216-1 (print)
ISBN-13: 978-1-7185-0217-8 (ebook)
Publisher: William Pollock
Managing Editor: Jill Franklin
Production Manager: Sabrina Plomitallo-Gonzlez
Production Editor: Jennifer Kepler
Developmental Editor: Alex Freed
Cover Illustrator: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Valerie Barr
Copyeditor: Gary Smith
Proofreader: Lisa Devoto Farrell
For information on distribution, bulk sales, corporate sales, or translations, please contact No Starch Press, Inc. directly at or:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900
www.nostarch.com
Library of Congress Control Number: 2022049830
.
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
About the Author
Allen Downey is a staff scientist at DrivenData and professor emeritus at Olin College, where he taught Modeling and Simulation and other classes related to software and data science. He is the author of several textbooks, including Think Python, Think Bayes, and Elements of Data Science. Previously, he taught at Wellesley College and Colby College. He received his PhD in computer science from the University of California, Berkeley, in 1997. His undergraduate and masters degrees are from the civil engineering department at MIT. He is the author of Probably Overthinking It, a blog about data science and Bayesian statistics.
About the Technical Reviewer
Valerie Barr has spent more than a decade focusing on interdisciplinary applications and curricular strategies to expose students from all fields to computing. This has included developing and offering courses in modeling and simulation, data visualization, and other areas that now also cross into data science. She has a PhD in computer science from Rutgers University, held the Jean Sammet Chair at Mount Holyoke College, and now holds the Margaret Hamilton Chair at Bard College, where she is launching the Bard Network Computing Initiative.
CONTENTS IN DETAIL
PART I
DISCRETE SYSTEMS
1
INTRODUCTION TO MODELING
2
MODELING A BIKE SHARE SYSTEM
3
ITERATIVE MODELING
4
PARAMETERS AND METRICS
5
BUILDING A POPULATION MODEL
6
ITERATING THE POPULATION MODEL
7
LIMITS TO GROWTH
8
PROJECTING INTO THE FUTURE
9
ANALYSIS AND SYMBOLIC COMPUTATION
10
CASE STUDIES PART I
PART II
FIRST-ORDER SYSTEMS
11
EPIDEMIOLOGY AND SIR MODELS
12
QUANTIFYING INTERVENTIONS
13
SWEEPING PARAMETERS
14
NONDIMENSIONALIZATION
15
THERMAL SYSTEMS
16
SOLVING THE COFFEE PROBLEM
17
MODELING BLOOD SUGAR
18
IMPLEMENTING THE MINIMAL MODEL
19
CASE STUDIES PART II
PART III
SECOND-ORDER SYSTEMS
20
THE FALLING PENNY REVISITED
21
DRAG
22
TWO-DIMENSIONAL MOTION
23
OPTIMIZATION
24
ROTATION
25
TORQUE
26
CASE STUDIES PART III
ACKNOWLEDGMENTS
My early work on this book benefited from conversations with my colleagues at Olin College, including John Geddes, Mark Somerville, Alison Wood, Chris Lee, and Jason Woodard.
I am grateful to Lisa Downey and Jason Woodard for their thoughtful and careful copyediting, and to Eoghan Downey and Jason Moore for their technical review.
Thanks to Alessandra Ferzoco, Erhardt Graeff, Emily Tow, Kelsey Houston-Edwards, Linda Vanasupa, Matt Neal, Joanne Pratt, and Steve Matsumoto for their helpful suggestions.