Book

Numerical Methods: From Error Analysis to Machine Learning, with Java and Python

From Error Analysis to Machine Learning, with Java and Python — A laundry’s spreadsheet says that 4.1 kg at Rp7,500 a kilogram is not quite Rp30,750. A water seller marks a dipstick for a tank that lies on its side.

A416 ChaptersBI · ENJava · Python521 pages
Profitina Numerical Methods
Download Full Book (PDF) Download All Lectures (PDF) Download the Source Code (ZIP)

Overview

Chapter 1 explains why a computer’s answers are almost always slightly wrong: how numbers are stored in floating point, what round-off and truncation errors are, and how to measure them. It sets up the workbench and ends with a small laboratory of experiments on the machine’s arithmetic.

Chapters 2 and 3 find roots of equations. Chapter 2 helps Mas Dimas, an ojek driver, discover the real interest rate hidden in a phone’s instalment plan with bisection and regula falsi, methods that can never lose the root once it is bracketed. Chapter 3 marks the dipstick of Pak Harun’s water truck with Newton-Raphson, the secant method and fixed-point iteration, measures how fast each one converges, and shows when Newton goes wrong.

Chapters 4 to 6 solve systems of linear equations. Chapter 4 works out how much of each fertilizer Bu Rahma’s durian trees need with Gaussian elimination, shows why pivoting matters, and explains why a small residual does not guarantee a small error. Chapter 5 finds the steady temperature over Pak Joni’s martabak griddle with the iterative methods of Jacobi, Gauss-Seidel and SOR. Chapter 6 factors a matrix once and reuses it, with LU, Cholesky and QR decompositions, to answer the fertilizer question for every block of an orchard.

Chapters 7 and 8 draw curves through data. Chapter 7 turns the tank maker’s table for Pak Darto’s fuel kiosk into accurate litres at every depth with Lagrange and Newton interpolation and cubic splines. Chapter 8 fits models to Mas Dimas’s notebook of fuel and trips with least squares, and shows how to choose a model without overfitting.

Chapters 9 to 11 are about change. Chapter 9 explains how a ride-hailing app can tell a harsh brake from a gentle stop, with finite differences derived from Taylor’s theorem and Richardson extrapolation. Chapter 10 measures a durian orchard whose boundary is a winding river with the trapezoidal rule, Simpson’s rules, Romberg integration and Gauss quadrature. Chapter 11 decides when to switch off the orchard’s pump with Euler and Runge–Kutta methods for ordinary differential equations, and looks at systems and stability.

Chapters 12 to 14 take the methods toward modern computing. Chapter 12 follows three laundries competing in one kampung with the power method for eigenvalues, and shows how the same idea ranks the pages of the web with PageRank. Chapter 13 finds the most profitable price for a cup of iced tea with golden-section search, Newton’s method and gradient descent. Chapter 14 shows that machine learning is numerical methods at heart: least squares, gradient descent with mini-batches, momentum and Adam, and logistic regression trained by Newton’s method, predicting the length of an ojek trip and whether a customer will cancel.

Chapter 15 makes the programs fast: where the time goes, vectorization, parallel threads and their limits, sums that are accurate and reproducible, and smarter methods that simply do less work. Chapter 16, the capstone, simulates the dry season of a durian orchard end to end — tank, pump, weather, trees, well and drip line — with methods from across the book, runs hundreds of seasons, and helps Pak Hadi choose his water tank.

Every chapter follows the same path: the problem and who it helps, the idea in plain words with numbers worked by hand, the method derived with its error and convergence analyzed, the programs built step by step in Java and Python, running them, checking the answers against NumPy and SciPy, making them better, using them for real, numerical methods in practice at Profitina, common mistakes, a summary, exercises with complete solutions, and references.

Every program in this book was run before its output was printed. The programs are collected, chapter by chapter, in the accompanying Code folder, from Chapter01 to Chapter16, each with a java and a python folder, the data it needs, and a README that explains how to run it in a terminal and in VS Code on Windows, macOS and Linux.

Inside the Book

  1. Numbers in the Machine: Errors, Floating Point, and Your Workbench
  2. Root Finding I: Bisection and Regula Falsi
  3. Root Finding II: Newton-Raphson, Secant and Fixed-Point Iteration
  4. Linear Systems I: Gaussian Elimination and Pivoting
  5. Linear Systems II: Jacobi, Gauss-Seidel and SOR
  6. Matrix Decompositions: LU, Cholesky and QR
  7. Interpolation: Lagrange, Newton and Splines
  8. Curve Fitting: Least Squares Regression
  9. Numerical Differentiation
  10. Numerical Integration: Trapezoid, Simpson, Romberg and Gauss
  11. Ordinary Differential Equations: Euler to Runge-Kutta
  12. Eigenvalues: Power Method and Its Uses (e.g. PageRank)
  13. Optimization: Golden Section, Newton and Gradient Descent
  14. Numerical Methods for Machine Learning
  15. Fast and Parallel Numerical Computing
  16. Capstone: Simulating a Real System End to End
Who this book is for: The book is self-contained, and you are assumed to be a beginner. If you have never written a line of code, never installed a programming language and do not remember much calculus, you are exactly the reader this book was written for. Every term is introduced in plain words before it is used, every method is first worked by hand on a small example with real numbers, the mathematics it needs is explained where it is needed, and every program in the book was run before its output was printed here. Chapter 1 begins with a receipt that does not add up and ends with a workbench that is ready for everything that follows.

Profitina · profitina.com

💬 Community Discussion