Math Adventures with Python

Book description

Math Adventures with Python will show you how to harness the power of programming to keep math relevant and fun. With the aid of the Python programming language, you’ll learn how to visualize solutions to a range of math problems as you use code to explore key mathematical concepts like algebra, trigonometry, matrices, and cellular automata.

Once you’ve learned the programming basics like loops and variables, you’ll write your own programs to solve equations quickly, make cool things like an interactive rainbow grid, and automate tedious tasks like factoring numbers and finding square roots. You’ll learn how to write functions to draw and manipulate shapes, create oscillating sine waves, and solve equations graphically.

You’ll also learn how to:

•Draw and transform 2D and 3D graphics with matrices

•Make colorful designs like the Mandelbrot and Julia sets with complex numbers

•Use recursion to create fractals like the Koch snowflake and the Sierpinski triangle

•Generate virtual sheep that graze on grass and multiply autonomously

•Crack secret codes using genetic algorithms

As you work through the book’s numerous examples and increasingly challenging exercises, you’ll code your own solutions, create beautiful visualizations, and see just how much more fun math can be!

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. ABOUT THE AUTHOR
  6. ABOUT THE TECHNICAL REVIEWER
  7. BRIEF CONTENTS
  8. CONTENTS IN DETAIL
  9. ACKNOWLEDGMENTS
  10. INTRODUCTION
    1. The Problem with School Math
    2. About This Book
    3. Who Should Use This Book
    4. What’s in This Book?
    5. Downloading and Installing Python
    6. Starting IDLE
    7. Installing Processing
  11. PART I: HITCHIN’ UP YOUR PYTHON WAGON
  12. 1 DRAWING POLYGONS WITH THE TURTLE MODULE
    1. Python’s turtle Module
    2. Repeating Code with Loops
    3. Creating Shortcuts with Functions
    4. Using Variables to Draw Shapes
    5. Equilateral Triangles
    6. Summary
  13. 2 MAKING TEDIOUS ARITHMETIC FUN WITH LISTS AND LOOPS
    1. Basic Operators
    2. Data Types in Python
    3. Using Lists to Store Values
    4. Using Lists in Loops
    5. Summation
    6. Finding the Average of a List of Numbers
    7. Summary
  14. 3 GUESSING AND CHECKING WITH CONDITIONALS
    1. Comparison Operators
    2. Making Decisions with if and else Statements
    3. Using Conditionals to Find Factors
    4. Creating a Number-Guessing Game
    5. Finding Square Roots
    6. Summary
  15. PART 2: RIDING INTO MATH TERRITORY
  16. 4 TRANSFORMING AND STORING NUMBERS WITH ALGEBRA
    1. Solving First-Degree Equations
    2. Solving Higher-Degree Equations
    3. Solving Equations Graphically
    4. Summary
  17. 5 TRANSFORMING SHAPES WITH GEOMETRY
    1. Drawing a Circle
    2. Specifying Location Using Coordinates
    3. Transformation Functions
    4. Animating Objects
    5. Creating an Interactive Rainbow Grid
    6. Drawing Complex Patterns Using Triangles
    7. Summary
  18. 6 CREATING OSCILLATIONS WITH TRIGONOMETRY
    1. Using Trigonometry for Rotations and Oscillations
    2. Writing Functions to Draw Polygons
    3. Making Sine Waves
    4. Creating a Spirograph Program
    5. Making Harmonographs
    6. Summary
  19. 7 COMPLEX NUMBERS
    1. The Complex Coordinate System
    2. Adding Complex Numbers
    3. Multiplying a Complex Number by i
    4. Multiplying Two Complex Numbers
    5. Writing the magnitude() Function
    6. Creating the Mandelbrot Set
    7. Creating the Julia Set
    8. Summary
  20. 8 USING MATRICES FOR COMPUTER GRAPHICS AND SYSTEMS OF EQUATIONS
    1. What Is a Matrix?
    2. Adding Matrices
    3. Multiplying Matrices
    4. Order Matters in Matrix Multiplication
    5. Drawing 2D Shapes
    6. Transforming Matrices
    7. Transposing Matrices
    8. Rotating Matrices in Real Time
    9. Creating 3D Shapes
    10. Creating the Rotation Matrix
    11. Solving Systems of Equations with Matrices
    12. Summary
  21. PART 3: BLAZING YOUR OWN TRAIL
  22. 9 BUILDING OBJECTS WITH CLASSES
    1. Bouncing Ball Program
    2. Grazing Sheep Program
    3. Summary
  23. 10 CREATING FRACTALS USING RECURSION
    1. The Length of a Coastline
    2. Koch Snowflake
    3. Sierpinski Triangle
    4. Square Fractal
    5. Dragon Curve
    6. Summary
  24. 11 CELLULAR AUTOMATA
    1. Creating a Cellular Automaton
    2. Python Lists Are Strange
    3. Playing the Game of Life
    4. The Elementary Cellular Automaton
    5. Summary
  25. 12 SOLVING PROBLEMS USING GENETIC ALGORITHMS
    1. Using a Genetic Algorithm to Guess Phrases
    2. Solving the Traveling Salesperson Problem (TSP)
    3. Summary
  26. INDEX

Product information

  • Title: Math Adventures with Python
  • Author(s): Peter Farrell
  • Release date: January 2019
  • Publisher(s): No Starch Press
  • ISBN: 9781593278670