(Ebook) Doing Math with Python by Amit Saha ISBN 9781593277192, 1593277199pdf download
(Ebook) Doing Math with Python by Amit Saha ISBN 9781593277192, 1593277199pdf download
https://ebooknice.com/product/doing-math-with-python-58614158
https://ebooknice.com/product/doing-math-with-python-use-programming-to-
explore-algebra-statistics-calculus-and-more-5209546
https://ebooknice.com/product/doing-math-with-python-use-programming-to-
explore-algebra-statistics-calculus-and-more-55421412
(Ebook) doing math with python doing math with python by kan
https://ebooknice.com/product/doing-math-with-python-doing-math-with-
python-50196050
https://ebooknice.com/product/math-adventures-with-python-an-illustrated-
guide-to-exploring-math-with-code-36151058
(Ebook) Math Adventures with Python: An Illustrated Guide to
Exploring Math with Code by Peter Farrell ISBN 9781593278670,
1593278675
https://ebooknice.com/product/math-adventures-with-python-an-illustrated-
guide-to-exploring-math-with-code-10674096
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-arco-
master-the-sat-subject-test-math-levels-1-2-2326094
https://ebooknice.com/product/sat-ii-success-math-1c-and-2c-2002-peterson-
s-sat-ii-success-1722018
https://ebooknice.com/product/practical-weak-supervision-doing-more-with-
less-data-54661408
https://ebooknice.com/product/practical-weak-supervision-doing-more-with-
less-data-55298530
DOING MATH WITH PYTHON
DO ING M A T H
W IT H P Y T H O N
U s e P r o g r a m m i n g t o
Ex p l o r e A l g e b r a , S t a t i s t i c s ,
C a l c u l u s , a n d M o r e !
b y Amit Sa ha
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.
Eighth printing
27 26 25 24 23 8 9 10 11 12
ISBN-13: 978-1-59327-640-9 (print)
ISBN-13: 978-1-59327-719-2 (ebook)
®
® Published by No Starch Press , Inc.
245 8th Street, San Francisco, CA 94103
phone: +1.415.863.9900
www.nostarch.com; info@nostarch.com
For customer service inquiries, please contact info@nostarch.com. For information on distribution,
bulk sales, corporate sales, or translations: sales@nostarch.com. For permission to translate this work:
rights@nostarch.com. To report counterfeit copies or piracy: counterfeit@nostarch.com.
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.
To Protyusha, for never giving up on me
BRIEF CONTENTS
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
CONTE NT S IN DE TA IL
ACKNOWLEDGMENTS xiii
INTRODUCTION xv
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Scripts, Solutions, and Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
1
WORKING WITH NUMBERS 1
Basic Mathematical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Labels: Attaching Names to Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Different Kinds of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Working with Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Getting User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Handling Exceptions and Invalid Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Fractions and Complex Numbers as Input . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Writing Programs That Do the Math for You . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Calculating the Factors of an Integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Generating Multiplication Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Converting Units of Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Finding the Roots of a Quadratic Equation . . . . . . . . . . . . . . . . . . . . . . . . . . 20
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
#1: Even-Odd Vending Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
#2: Enhanced Multiplication Table Generator. . . . . . . . . . . . . . . . . . . . . . . . 23
#3: Enhanced Unit Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
#4: Fraction Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
#5: Give Exit Power to the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
VISUALIZING DATA WITH GRAPHS 27
Understanding the Cartesian Coordinate Plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Working with Lists and Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Iterating over a List or Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating Graphs with Matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Marking Points on Your Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Graphing the Average Annual Temperature in New York City . . . . . . . . . . . . 35
Comparing the Monthly Temperature Trends of New York City . . . . . . . . . . . . 38
Customizing Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Saving the Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Plotting with Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Newton’s Law of Universal Gravitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Projectile Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
#1: How Does the Temperature Vary During the Day?. . . . . . . . . . . . . . . . . . 55
#2: Exploring a Quadratic Function Visually. . . . . . . . . . . . . . . . . . . . . . . . . 55
#3: Enhanced Projectile Trajectory Comparison Program . . . . . . . . . . . . . . . . 56
#4: Visualizing Your Expenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
#5: Exploring the Relationship Between
the Fibonacci Sequence and the Golden Ratio . . . . . . . . . . . . . . . . . . . . 59
3
DESCRIBING DATA WITH STATISTICS 61
Finding the Mean. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Finding the Median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Finding the Mode and Creating a Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Finding the Most Common Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Finding the Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Creating a Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Measuring the Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Finding the Range of a Set of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Finding the Variance and Standard Deviation. . . . . . . . . . . . . . . . . . . . . . . . 72
Calculating the Correlation Between Two Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Calculating the Correlation Coefficient. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
High School Grades and Performance on College Admission Tests . . . . . . . . . 78
Scatter Plots. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Reading Data from Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Reading Data from a Text File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Reading Data from a CSV File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#1: Better Correlation Coefficient–Finding Program . . . . . . . . . . . . . . . . . . . . 89
#2: Statistics Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#3: Experiment with Other CSV Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#4: Finding the Percentile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#5: Creating a Grouped Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4
ALGEBRA AND SYMBOLIC MATH WITH SYMPY 93
Defining Symbols and Symbolic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Working with Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Factorizing and Expanding Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Substituting in Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Converting Strings to Mathematical Expressions . . . . . . . . . . . . . . . . . . . . . 103
Solving Equations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Solving Quadratic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Solving for One Variable in Terms of Others . . . . . . . . . . . . . . . . . . . . . . . 106
Solving a System of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Plotting Using SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Plotting Expressions Input by the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Plotting Multiple Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#1: Factor Finder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#2: Graphical Equation Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#3: Summing a Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
#4: Solving Single-Variable Inequalities . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
x Contents in Detail
5
PLAYING WITH SETS AND PROBABILITY 121
What’s a Set? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Set Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Subsets, Supersets, and Power Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Probability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Probability of Event A or Event B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Probability of Event A and Event B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Generating Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Nonuniform Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
#1: Using Venn Diagrams to Visualize Relationships Between Sets . . . . . . . . 140
#2: Law of Large Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
#3: How Many Tosses Before You Run Out of Money? . . . . . . . . . . . . . . . . 144
#4: Shuffling a Deck of Cards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
#5: Estimating the Area of a Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
6
DRAWING GEOMETRIC SHAPES AND FRACTALS 149
Drawing Geometric Shapes with Matplotlib’s Patches. . . . . . . . . . . . . . . . . . . . . . . . 150
Drawing a Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Creating Animated Figures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Animating a Projectile’s Trajectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Drawing Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Transformations of Points in a Plane. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Drawing the Barnsley Fern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
#1: Packing Circles into a Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
#2: Drawing the Sierpiński Triangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
#3: Exploring Hénon’s Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
#4: Drawing the Mandelbrot Set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
7
SOLVING CALCULUS PROBLEMS 177
What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Domain and Range of a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
An Overview of Common Mathematical Functions. . . . . . . . . . . . . . . . . . . . 178
Assumptions in SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Finding the Limit of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Continuous Compound Interest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Instantaneous Rate of Change. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Finding the Derivative of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
A Derivative Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Calculating Partial Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Higher-Order Derivatives and Finding the Maxima and Minima . . . . . . . . . . . . . . . . 188
Finding the Global Maximum Using Gradient Ascent . . . . . . . . . . . . . . . . . . . . . . . . 191
A Generic Program for Gradient Ascent. . . . . . . . . . . . . . . . . . . . . . . . . . . 195
A Word of Warning About the Initial Value . . . . . . . . . . . . . . . . . . . . . . . . 196
The Role of the Step Size and Epsilon . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Contents in Detail xi
Finding the Integrals of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Probability Density Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
#1: Verify the Continuity of a Function at a Point. . . . . . . . . . . . . . . . . . . . . 205
#2: Implement the Gradient Descent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
#3: Area Between Two Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
#4: Finding the Length of a Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
AFTERWORD 209
Things to Explore Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Project Euler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Python Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
A
SOFTWARE INSTALLATION 213
Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Starting the Python Shell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Starting the Python Shell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Mac OS X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Starting the Python Shell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
B
OVERVIEW OF PYTHON TOPICS 221
if __name__ == '__main__' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Dictionary Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Multiple Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Specifying Multiple Exception Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
The else Block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Reading Files in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Reading All the Lines at Once. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Specifying the Filename as Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Handling Errors When Reading Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Reusing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
INDEX 237
I would like to thank everyone at No Starch Press for making this book
possible. From the first emails discussing the book idea with Bill Pollock
and Tyler Ortman, through the rest of the process, everyone there has
been an absolute pleasure to work with. Seph Kramer was amazing with his
technical insights and suggestions and Riley Hoffman was meticulous in
checking and re-checking that everything was correct. It is only fair to say
that without these two fine people, this book wouldn’t have been close to
what it is. Thanks to Jeremy Kun and Otis Chodosh for their insights and
making sure all the math made sense. I would also like to thank the copy-
editor, Julianne Jigour, for her thoroughness.
SymPy forms a core part of many chapters in this book and I would
like to thank everyone on the SymPy mailing list for answering my queries
patiently and reviewing my patches with promptness. I would also like to
thank the matplotlib community for answering and clearing up my doubts.
I would like to thank David Ash for lending me his Macbook, which
helped me when writing the software installation instructions.
I also must thank every writer and thinker who inspired me to write,
from humble web pages to my favorite books.
INTRODUCTION
xvi Introduction
• Chapter 4, Algebra and Symbolic Math with SymPy, introduces sym-
bolic math using the SymPy library. It begins with the basics of repre-
senting and manipulating algebraic expressions before introducing
more complicated matters, such as solving equations.
• Chapter 5, Playing with Sets and Probability, discusses the representa-
tion of mathematical sets and moves on to basic discrete probability.
You’ll also learn to simulate uniform and nonuniform random events.
• Chapter 6, Drawing Geometric Shapes and Fractals, discusses using
matplotlib to draw geometric shapes and fractals and create animated
figures.
• Chapter 7, Solving Calculus Problems, discusses some of the math-
ematical functions available in the Python standard library and SymPy
and then introduces you to solving calculus problems.
• Appendix A, Software Installation, covers installation of Python 3,
matplotlib, and SymPy on Microsoft Windows, Linux, and Mac OS X.
• Appendix B, Overview of Python Topics, discusses several Python
topics that may be helpful for beginners.
Introduction xvii
Random documents with unrelated
content Scribd suggests to you:
CHAPTER VIII
THE TRADITIONAL CURRICULUM AND ITS
REORGANIZATION
Educators are usually learned men; but this world generally does
not ascribe to them an abundance of sound sense. These learned
men have charge of the greatest plant in the world—our schools. A
half million employees are at work at an annual expense to the
nation of $450,000,000. The product of this institution should be
manhood and womanhood, efficient to take its place in the world of
workers, and firmly established in habits of right thinking and noble
action. Yet who is accounted efficient for the work of to-day?
Certainly not the armorer, no matter how skilled—for what need
have we of him? Possibly not the bootmaker; for the best and latest
in boots come from big factories. And so rapidly do industries
change that confusion awaits the man still using methods of ten
years ago. No system of education can be efficient until the
conditions of life to which pupils go are thoroughly known. No
manufacturer would think of setting his machines to make “what-
nots” or muzzle-loading guns; they were all right in their day but
that day is now yesterday. The first thing for the man of business is
to know what the market demands. And the managers of the
schools must explore their market to know what is demanded of the
education factory. That is the reason for this survey.
The commission was made up of persons well known in the city
and representative of differing interests....
Ten months were spent in gathering the information, and a month
in studying it and getting it into shape for presentation. The tables
have been arranged in the following order: First, a set of three
tables, showing the sources of the material studied, by school, by
age, by grade, and by nationality, and the causes of retardation;
second, a table showing upon whom the responsibility should be
placed for the child’s leaving school; third, four tables setting forth
the reasons for leaving school, and the economic status of the
family; fourth, a table indicating the education of the children after
leaving the public school; and fifth, five tables showing the industrial
history of each child, his wages, the number of jobs, the kind of
work, and his advancement.
In the discussion comparisons are frequently made with similar
reports from other cities, and following these are the conclusions
reached by the committee and recommendations for further work.
It will not be possible to give in detail all the results thus obtained.
It must suffice to repeat here the figures which summarize the table
of causes for leaving school. The percentages of pupils leaving for
each cause are given with the statement of the cause.
Ill health 5.7 per cent
Had to go to work 35.5 per cent
Child’s desire to earn money 8.2 per cent
Kept vacation work 2.6 per cent
Disliked or not interested in school 29.6 per cent
Trouble with teacher 3.1 per cent
Failure to pass 1.1 per cent
Further public school not worth while 14.2 per cent
The number of pupils who leave because they do not like school
or do not believe it worth while is disturbingly large. That there
should be so pronounced an adverse judgment on the part of pupils
is perhaps to be explained in a measure by their immaturity and
restlessness; but part of the school’s problem is to meet this
immaturity and restlessness and to train the pupils with full regard to
all that goes to make up their individual tastes and abilities.
It is especially important that a careful study be made of all
available recommendations for improving the situation. We turn,
therefore, to some of the leading recommendations of the
Minneapolis commission:
I have left myself only a few words to sum up and define the
main issue raised by the so-called modernist reform of
education. It is not the place of physical science in our
civilization and in our universities: that is secure. It is not the
opportunity of industrial or vocational training for the masses:
we all welcome that. It is not the conversion of the American
high school into the old Latin-verse-writing English public
school: nobody ever proposed that. It is not the prescription of
a universal requirement of Greek or the maintenance of a
disproportionate predominance of Latin in our high schools and
colleges: there is not the slightest danger of that. It is the
survival or the total suppression, in the comparatively small
class of educated leaders who graduate from high schools and
colleges, of the very conception of linguistic, literary, and critical
discipline; of culture, taste, and standards; of the historic sense
itself; of some trained faculty of appreciation and enjoyment of
our rich heritage from the civilized past; of some
counterbalancing familiarity with the actual evolution of the
human man, to soften the rigidities of physical science, and to
check and control by the touchstones of humor and common
sense the a priori deductions of pseudo-science from conjectural
reconstructions of the evolution of the physical and animal man.
It is in vain that they rejoin that they too care for these
things, and merely repudiate our exclusive definitions of them.
That is, in the main, only oratorical precaution and the tactics of
debate, as, if space permitted, I could show by hundreds of
citations from their books. The things which, for lack of better
names, we try to suggest by culture, discipline, taste, standards,
criticism, and the historic sense, they hate. Or, if you prefer,
they are completely insensitive to them and wish to impose their
own insensibility upon the coming generation. They are
genuinely skeptical of intellectual discriminations which they do
not perceive, and æsthetic values which they do not feel. They
are fiercely resentful of what they deem the supercilious
arrogance of those who possess or strive for some far-off touch
or faint tincture of the culture and discipline which they
denounce as shibboleths, taboos, and the arbitrary conventions
of pedants.
From their own point of view it is natural that they should
deprecate with sullen jealousy the inoculation of the adolescent
mind with standards and tastes that would render it immune to
what one of them has commended in print as the “science” of
Elsie Clews Parsons. The purpose, or, at any rate, the tendency
of their policies is to stamp out and eradicate these things and
inculcate exclusively their own tastes and ideals by controlling
American education with the political efficiency of Prussian
autocracy and in the fanatical intolerance of the French
anticlericalists. Greek and Latin have become mere symbols and
pretexts. They are as contemptuous of Dante, Shakespeare,
Milton, Racine, Burke, John Stuart Mill, Tennyson, Alexander
Hamilton, or Lowell, as of Homer, Sophocles, Virgil, or Horace.
They will wipe the slate clean of everything that antedates
Darwin’s Descent of Man, Mr. Wells’s Research Magnificent, and
the familiar pathos of James Whitcomb Riley’s vernacular verse.
These are the policies that mask as compassion for the child
bored by literature which, they say, it cannot be expected to
appreciate and understand, or behind the postulate that we
should develop æsthetic and literary sensibilities only by means
of the literature that expresses the spirit of modern science, not
that which preserves in amber the husks of the dead past.43
Fig. 12
The high schools of the country entered into competition with the
private commercial schools, and for some years the competition has
been running high. The private schools solicit and get a large
patronage on the ground that they do not teach anything that is
useless. They give short, compact courses fitted to pupils’ needs.
The high schools point out that the short courses leave the
stenographer with a meager vocabulary and the clerk with no
outlook on life.
The public schools are gradually pulling ahead of their competitors
because they are employing a higher grade of teachers than
formerly and are doing the work in a fashion which is technically
more complete. In the meantime the commercial courses are
becoming more “respectable” and are being taken by a better grade
of students. The effect of the election of commercial courses by a
better grade of students is such as to modify the whole program of
the school in the direction of more attention to the needs and
practices of business life.
Part-Time Courses
A third movement which has recently attracted a great deal of
attention and favorable comment was started in the engineering
school of the University of Cincinnati and is known as the part-time
plan. Classes are organized in such a way that their members spend
one week or one month in the shop of some manufacturing plant
and the next period in school. A second group alternates in the
reverse order, so that the shop and the school are at all times
engaged in regular work. Where this plan is well organized, there is
a special school officer, called a correlator, who sees to it that there
is some direct connection between the shop work and the courses
taken up in the schools.
The part-time plan aims to supply that mixture of practical
opportunity and training in science, mathematics, and the academic
subjects which will lead to both vocational efficiency and a general
education.
Various Types of Trade Schools
Fourth, there are all kinds of schools for young people in the
trades. Some of these hold their sessions at night, when the working
day is over, and others are organized to take the young worker out
of the shop or store for a limited number of hours during the
working day. In the matter of instruction some give only special
training intended to make the worker more skillful; others give
general courses in civics, or history, or even in literary subjects.
Some of these schools for workers are organized by the
corporations which employ the workers. Thus, telephone companies
and dry-goods stores find that it is economical to train their
employees. Some of the schools are conducted by the school system
and are provided with pupils either through the voluntary demand
on the part of learners or through the operation of state laws or
municipal ordinances compelling children to attend such schools until
they are of a certain age.
Fifth, trade training is provided not merely for those in the trades
but also for those who are preparing to enter them. Trade schools
are sometimes supported out of the public purse, sometimes by
private endowments. The method of instruction is that of requiring
the learner to go through a definite series of exercises which will
give him skill in the trade. The strictly technical training is usually
supplemented by some “general” training.
The following quotation gives a brief summary by one specialist in
vocational education of the writings of another specialist in the same
field:
THE MANHATTAN TRADE SCHOOL, NEW YORK CITY
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com