contents

preface

acknowledgments

about this book

about the author

about the cover illustration

  

  1 Learning math with code

  1.1  Solving lucrative problems with math and software

Predicting financial market movements

Finding a good deal

Building 3D graphics and animations

Modeling the physical world

  1.2  How not to learn math

Jane wants to learn some math

Slogging through math textbooks

  1.3  Using your well-trained left brain

Using a formal language

Build your own calculator

Building abstractions with functions

Part 1. Vectors and graphics

  2  Drawing with 2D vectors

  2.1  Picturing 2D vectors

Representing 2D vectors

2D drawing in Python

Exercises

  2.2  Plane vector arithmetic

Vector components and lengths

Multiplying vectors by numbers

Subtraction, displacement, and distance

Exercises

  2.3  Angles and trigonometry in the plane

From angles to components

Radians and trigonometry in Python

From components back to angles

Exercises

  2.4  Transforming collections of vectors

Combining vector transformations

Exercises

  2.5  Drawing with Matplotlib

  3  Ascending to the 3D world

  3.1  Picturing vectors in 3D space

Representing 3D vectors with coordinates

3D drawing with Python

Exercises

  3.2  Vector arithmetic in 3D

Adding 3D vectors

Scalar multiplication in 3D

Subtracting 3D vectors

Computing lengths and distances

Computing angles and directions

Exercises

  3.3  The dot product: Measuring vector alignment

Picturing the dot product

Computing the dot product

Dot products by example

Measuring angles with the dot product

Exercises

  3.4  The cross product: Measuring oriented area

Orienting ourselves in 3D

Finding the direction of the cross product

Finding the length of the cross product

Computing the cross product of 3D vectors

Exercises

  3.5  Rendering a 3D object in 2D

Defining a 3D object with vectors

Projecting to 2D

Orienting faces and shading

Exercises

  4  Transforming vectors and graphics

  4.1  Transforming 3D objects

Drawing a transformed object

Composing vector transformations

Rotating an object about an axis

Inventing your own geometric transformations

Exercises

  4.2  Linear transformations

Preserving vector arithmetic

Picturing linear transformations

Why linear transformations?

Computing linear transformations

Exercises

  5  Computing transformations with matrices

  5.1  Representing linear transformations with matrices

Writing vectors and linear transformations as matrices

Multiplying a matrix with a vector

Composing linear transformations by matrix multiplication

Implementing matrix multiplication

3D animation with matrix transformations

Exercises

  5.2  Interpreting matrices of different shapes

Column vectors as matrices

What pairs of matrices can be multiplied?

Viewing square and non-square matrices as vector functions

Projection as a linear map from 3D to 2D

Composing linear maps

Exercises

  5.3  Translating vectors with matrices

Making plane translations linear

Finding a 3D matrix for a 2D translation

Combining translation with other linear transformations

Translating 3D objects in a 4D world

Exercises

  6  Generalizing to higher dimensions

  6.1  Generalizing our definition of vectors

Creating a class for 2D coordinate vectors

Improving the Vec2 class

Repeating the process with 3D vectors

Building a vector base class

Defining vector spaces

Unit testing vector space classes

Exercises

  6.2  Exploring different vector spaces

Enumerating all coordinate vector spaces

Identifying vector spaces in the wild

Treating functions as vectors

Treating matrices as vectors

Manipulating images with vector operations

Exercises

  6.3  Looking for smaller vector spaces

Identifying subspaces

Starting with a single vector

Spanning a bigger space

Defining the word dimension

Finding subspaces of the vector space of functions

Subspaces of images

Exercises

  7  Solving systems of linear equations

  7.1  Designing an arcade game

Modeling the game

Rendering the game

Shooting the laser

Exercises

  7.2  Finding intersection points of lines

Choosing the right formula for a line

Finding the standard form equation for a line

Linear equations in matrix notation

Solving linear equations with NumPy

Deciding whether the laser hits an asteroid

Identifying unsolvable systems

Exercises

  7.3  Generalizing linear equations to higher dimensions

Representing planes in 3D

Solving linear equations in 3D

Studying hyperplanes algebraically

Counting dimensions, equations, and solutions

Exercises

  7.4  Changing basis by solving linear equations

Solving a 3D example

Exercises

Part 2. Calculus and physical simulation

  8  Understanding rates of change

  8.1  Calculating average flow rate from volume

Implementing an average_flow_rate function

Picturing the average flow rate with a secant line

Negative rates of change

Exercises

  8.2  Plotting the average flow rate over time

Finding the average flow rate in different time intervals

Plotting the interval flow rates

Exercises

  8.3  Approximating instantaneous flow rates

Finding the slope of small secant lines

Building the instantaneous flow rate function

Currying and plotting the instantaneous flow rate function

Exercises

  8.4  Approximating the change in volume

Finding the change in volume for a short time interval

Breaking up time into smaller intervals

Picturing the volume change on the flow rate graph

Exercises

  8.5  Plotting the volume over time

Finding the volume over time

Picturing Riemann sums for the volume function

Improving the approximation

Definite and indefinite integrals

  9  Simulating moving objects

  9.1  Simulating a constant velocity motion

Adding velocities to the asteroids

Updating the game engine to move the asteroids

Keeping the asteroids on the screen

Exercises

  9.2  Simulating acceleration

Accelerating the spaceship

  9.3  Digging deeper into Euler’s method

Carrying out Euler’s method by hand

Implementing the algorithm in Python

  9.4  Running Euler’s method with smaller time steps

Exercises

10  Working with symbolic expressions

10.1  Finding an exact derivative with a computer algebra system

Doing symbolic algebra in Python

10.2  Modeling algebraic expressions

Breaking an expression into pieces

Building an expression tree

Translating the expression tree to Python

Exercises

10.3  Putting a symbolic expression to work

Finding all the variables in an expression

Evaluating an expression

Expanding an expression

Exercises

10.4  Finding the derivative of a function

Derivatives of powers

Derivatives of transformed functions

Derivatives of some special functions

Derivatives of products and compositions

Exercises

10.5  Taking derivatives automatically

Implementing a derivative method for expressions

Implementing the product rule and chain rule

Implementing the power rule

Exercises

10.6  Integrating functions symbolically

Integrals as antiderivatives

Introducing the SymPy library

Exercises

11  Simulating force fields

11.1  Modeling gravity with a vector field

Modeling gravity with a potential energy function

11.2  Modeling gravitational fields

Defining a vector field

Defining a simple force field

11.3  Adding gravity to the asteroid game

Making game objects feel gravity

Exercises

11.4  Introducing potential energy

Defining a potential energy scalar field

Plotting a scalar field as a heatmap

Plotting a scalar field as a contour map

11.5  Connecting energy and forces with the gradient

Measuring steepness with cross sections

Calculating partial derivatives

Finding the steepness of a graph with the gradient

Calculating force fields from potential energy with the gradient

Exercises

12  Optimizing a physical system

12.1  Testing a projectile simulation

Building a simulation with Euler’s method

Measuring properties of the trajectory

Exploring different launch angles

Exercises

12.2  Calculating the optimal range

Finding the projectile range as a function of the launch angle

Solving for the maximum range

Identifying maxima and minima

Exercises

12.3  Enhancing our simulation

Adding another dimension

Modeling terrain around the cannon

Solving for the range of the projectile in 3D

Exercises

12.4  Optimizing range using gradient ascent

Plotting range versus launch parameters

The gradient of the range function

Finding the uphill direction with the gradient

Implementing gradient ascent

Exercises

13  Analyzing sound waves with a Fourier series

13.1  Combining sound waves and decomposing them

13.2  Playing sound waves in Python

Producing our first sound

Playing a musical note

Exercises

13.3  Turning a sinusoidal wave into a sound

Making audio from sinusoidal functions

Changing the frequency of a sinusoid

Sampling and playing the sound wave

Exercises

13.4  Combining sound waves to make new ones

Adding sampled sound waves to build a chord

Picturing the sum of two sound waves

Building a linear combination of sinusoids

Building a familiar function with sinusoids

Exercises

13.5  Decomposing a sound wave into its Fourier series

Finding vector components with an inner product

Defining an inner product for periodic functions

Writing a function to find Fourier coefficients

Finding the Fourier coefficients for the square wave

Fourier coefficients for other waveforms

Exercises

Part 3. Machine learning applications

14  Fitting functions to data

14.1  Measuring the quality of fit for a function

Measuring distance from a function

Summing the squares of the errors

Calculating cost for car price functions

Exercises

14.2  Exploring spaces of functions

Picturing cost for lines through the origin

The space of all linear functions

Exercises

14.3  Finding the line of best fit using gradient descent

Rescaling the data

Finding and plotting the line of best fit

Exercises

14.4  Fitting a nonlinear function

Understanding the behavior of exponential functions

Finding the exponential function of best fit

Exercises

15  Classifying data with logistic regression

15.1  Testing a classification function on real data

Loading the car data

Testing the classification function

Exercises

15.2  Picturing a decision boundary

Picturing the space of cars

Drawing a better decision boundary

Implementing the classification function

Exercises

15.3  Framing classification as a regression problem

Scaling the raw car data

Measuring the “BMWness” of a car

Introducing the sigmoid function

Composing the sigmoid function with other functions

Exercises

15.4  Exploring possible logistic functions

Parameterizing logistic functions

Measuring the quality of fit for a logistic function

Testing different logistic functions

Exercises

15.5  Finding the best logistic function

Gradient descent in three dimensions

Using gradient descent to find the best fit

Testing and understanding the best logistic classifier

Exercises

16  Training neural networks

16.1  Classifying data with neural networks

16.2  Classifying images of handwritten digits

Building the 64-dimensional image vectors

Building a random digit classifier

Measuring performance of the digit classifier

Exercises

16.3  Designing a neural network

Organizing neurons and connections

Data flow through a neural network

Calculating activations

Calculating activations in matrix notation

Exercises

16.4  Building a neural network in Python

Implementing an MLP class in Python

Evaluating the MLP

Testing the classification performance of an MLP

Exercises

16.5  Training a neural network using gradient descent

Framing training as a minimization problem

Calculating gradients with backpropagation

Automatic training with scikit-learn

Exercises

16.6  Calculating gradients with backpropagation

Finding the cost in terms of the last layer weights

Calculating the partial derivatives for the last layer weights using the chain rule

Exercises

  

appendix A. Getting set up with Python

appendix B. Python tips and tricks

appendix C. Loading and rendering 3D Models with OpenGL and PyGame

  

index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.118.244