Math for Programmers
eBook - ePub

Math for Programmers

3D graphics, machine learning, and simulations with Python

Paul Orland

Share book
  1. 688 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Math for Programmers

3D graphics, machine learning, and simulations with Python

Paul Orland

Book details
Book preview
Table of contents
Citations

About This Book

"A gentle introduction to some of the most useful mathematical concepts that should be in your developer toolbox." - Christopher Haupt, New Relic Explore important mathematical concepts through hands-on coding.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. Filled with graphics and more than 300 exercises and mini-projects, this book unlocks the door to interestingā€“and lucrative!ā€“careers in some of today's hottest fields. As you tackle the basics of linear algebra, calculus, and machine learning, you'll master the key Python libraries used to turn them into real-world software applications. Summary
To score a job in data science, machine learning, computer graphics, and cryptography, you need to bring strong math skills to the party. Math for Programmers teaches the math you need for these hot careers, concentrating on what you need to know as a developer. Filled with lots of helpful graphics and more than 200 exercises and mini-projects, this book unlocks the door to interestingā€“and lucrative!ā€“careers in some of today's hottest programming fields. About the technology
Skip the mathematical jargon: This one-of-a-kind book uses Python to teach the math you need to build games, simulations, 3D graphics, and machine learning algorithms. Discover how algebra and calculus come alive when you see them in code! What's inside Vector geometry for computer graphics
Matrices and linear transformations
Core concepts from calculus
Simulation and optimization
Image and audio processing
Machine learning algorithms for regression and classification About the reader
For programmers with basic skills in algebra. About the author
Paul Orland is a programmer, software entrepreneur, and math enthusiast. He is co-founder of Tachyus, a start-up building predictive analytics software for the energy industry. You can find him online at www.paulor.land. Table of Contents 1 Learning math with code PART I - VECTORS AND GRAPHICS 2 Drawing with 2D vectors 3 Ascending to the 3D world 4 Transforming vectors and graphics 5 Computing transformations with matrices 6 Generalizing to higher dimensions 7 Solving systems of linear equations PART 2 - CALCULUS AND PHYSICAL SIMULATION 8 Understanding rates of change 9 Simulating moving objects 10 Working with symbolic expressions 11 Simulating force fields 12 Optimizing a physical system 13 Analyzing sound waves with a Fourier series PART 3 - MACHINE LEARNING APPLICATIONS 14 Fitting functions to data 15 Classifying data with logistic regression 16 Training neural networks

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Math for Programmers an online PDF/ePUB?
Yes, you can access Math for Programmers by Paul Orland in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
2020
ISBN
9781638357070

1 Learning math with code

This chapter covers
  • Solving lucrative problems with math and software
  • Avoiding common pitfalls in learning math
  • Building on intuition from programming to understand math
  • Using Python as a powerful and extensible calculator
Math is like baseball, or poetry, or fine wine. Some people are so fascinated by math that they devote their whole lives to it, while others feel like they just donā€™t get it. Youā€™ve probably already been forced into one camp or another by twelve years of compulsory math education in school.
What if we learned about fine wine in school like we learned math? I donā€™t think Iā€™d like wine at all if I got lectured on grape varietals and fermentation techniques for an hour a day, five days a week. Maybe in such a world, Iā€™d need to consume three or four glasses for homework as assigned by the teacher. Sometimes this would be a delicious educational experience, but sometimes I might not feel like getting loaded on a school night. My experience in math class went something like that, and it turned me off of the subject for a while. Like wine, mathematics is an acquired taste, and a daily grind of lectures and assignments is no way to refine oneā€™s palate.
Itā€™s easy to think youā€™re either cut out for math or you arenā€™t. If you already believe in yourself, and youā€™re excited to start learning, thatā€™s great! Otherwise, this chapter is designed for those less optimistic. Feeling intimidated by math is so common, it has a name: math anxiety. I hope to dispel any anxiety you might have and show you that math can be a stimulating experience rather than a frightening one. All you need are the right tools and the right mindset.
The main tool for learning in this book is the Python programming language. Iā€™m guessing that when you learned math in high school, you saw it written on the blackboard and not in computer code. Thatā€™s a shame, because a high-level programming language is far more powerful than a blackboard and far more versatile than whatever overpriced calculator you may have used. An advantage of meeting math in code is that the ideas have to be precise enough for a computer to understand, and thereā€™s never any hand-waving about what new symbols mean.
As with learning any new subject, the best way to set yourself up for success is to want to learn. There are plenty of good reasons for this. You could be intrigued by the beauty of mathematical concepts or enjoy the ā€œbrain-teaserā€ feel of math problems. Maybe thereā€™s an app or game that you dream of building, and you need to write some mathematical code to make it work. For now, Iā€™ll focus on a more pragmatic kind of motivationāˆ’solving mathematical problems with software can make you a lot of money.

1.1 Solving lucrative problems with math and software

A classic criticism you hear in high school math class is, ā€œWhen am I ever going to use this stuff in real life?ā€ Our teachers told us that math would help us succeed professionally and make money. I think they were right about this, even though their examples were off. For instance, I donā€™t calculate my compounding bank interest by hand (and neither does my bank). Maybe if I became a construction site surveyor as my trigonometry teacher suggested, Iā€™d be using sines and cosines every day to earn my paycheck.
It turns out the ā€œreal worldā€ applications from high school textbooks arenā€™t that useful. Still, there are real applications of math out there, and some of them are mind-bogglingly lucrative. Many are solved by translating the right mathematical idea into usable software. Iā€™ll share some of my favorite examples.

1.1.1 Predicting financial market movements

Weā€™ve all heard legends of stock traders making millions of dollars by buying and selling the right stocks at the right time. Based on the movies Iā€™ve seen, I always picture a trader as a middle-aged man in a suit yelling at his broker over a cell phone while driving around in a sports car. Maybe this stereotype was spot-on at one point, but the situation is different today.
Holed up in back offices of skyscrapers all over Manhattan are thousands of people called quants. Quants, otherwise known as quantitative analysts, design mathematical algorithms to automatically trade stocks and earn a profit. They donā€™t wear suits and they donā€™t spend time yelling on their cell phones, but Iā€™m sure many of them own very nice sports cars.
So how does a quant write a program that automatically makes money? The best answers to that question are closely-guarded trade secrets, but you can be sure they involve a lot of math. We can look at a brief example to get a sense of how an automated trading strategy might work.
Stocks are types of financial assets that represent ownership stakes in companies. When the market perceives a company is doing well, its stock price goes upāˆ’buying the stock becomes more costly and selling it becomes more rewarding. Stock prices change erratically and in real time. Figure 1.1 shows how a graph of a stock price over a day of trading might look.
Figure 1.1 Typical graph of a stock price over time
If you bought a thousand shares of this stock for $24 around minute 100 and sold them for $38 at minute 400, you would make $14,000 for the day. Not bad! The challenge is that youā€™d have to know in advance that the stock was going up, and that minutes 100 and 400 were the best times to buy and sell, respectively. It may not be possible to predict the exact lowest or highest price points, but maybe you can find relatively good times to buy and sell throughout the day. Letā€™s look at a way to do this mathematically.
We could measure whether the stock is going up or down by finding a line of ā€œbest fitā€ that approximately follows the direction the price is moving. This process is called linear regression, and we cover it in part 3 of this book. Based on the variability of data, we can calculate two more lines above and below the ā€œbest fitā€ line that show the region in which the price is wobbling up and down. Overlaid on the price graph, figure 1.2 shows that the lines follow the trend nicely.
Figure 1.2 Using linear regression to identify a trend in changing stock prices
With a mathematical understanding of the price movement, we can then write code to automatically buy when the price is going through a low fluctuation relative to its trend and to sell when the price goes back up. Specifically, our program could connect to the stock exchange over the network and buy 100 shares when the price crosses the bottom line and sell 100 shares when the price crosses the top line. Figure 1.3 illustrates one such profitable trade: buying at around $27.80 and selling at around $32.60 makes you $480 in an hour.
Figure 1.3 Buying and selling according to our rules-based software to make a profit
I donā€™t claim Iā€™ve shown you a complete or viable strategy here, but the point is that with the right mathematical model, you can make a profit automatically. At this moment, some unknown number of programs are building and updating models measuring the predicted trend of stocks and other financial instruments. If you write such a program, you can enjoy some leisure time while it makes money for you!

1.1.2 Finding a good deal

Maybe you donā€™t have deep enough pockets to consider risky stock trading. Math can still help you make and save money in other transactions like buying a used car, for example. New cars are easy-to-understand commodities. If two dealers are selling the same car, you obviously want to buy from the dealer that has the lowest cost. But used cars have more numbers associated with them: an asking...

Table of contents