These are the notes and code-along pages we use in class. Pages with multiple class meetings keep their materials together under one textbook module.
Getting started
Calculations, variables, vectors, graphs, loops, and decisions. Includes the complete downloadable R script from our introductory meetings.
Modeling change
Build an Euler simulation, compare it with the analytical solution, investigate time-step error, and model decay.
Textbook: Read Module 2.2, “Unconstrained Growth and Decay.”
Add carrying capacity to the growth model, interpret its balancing feedback, compare constrained and unconstrained trajectories, and answer threshold questions.
Textbook: Read Module 2.3, “Constrained Growth.”
Work through trout harvesting, bacterial growth, caffeine decay, and a constrained-growth challenge. Focus on choosing a model and using it to answer questions.
Interacting populations
Model two shark populations whose birth and competition flows depend on both species, then investigate equilibria and long-term behavior.
Textbook: Read Module 4.1, “Competition.”
Build a squirrel–hawk simulation with two coupled populations, compare their peak times, and examine the predator-versus-prey trajectory.
Textbook: Read Module 4.2, “Predator–Prey Models.”
Model infection and recovery as transfers between three groups, verify conservation, find the outbreak peak, and compare transmission rates.
Textbook: Read Module 4.3, “Modeling the Spread of SARS—Containing Emerging Disease.”
Checking our simulations
Locate errors in data, assumptions, implementation, and computation. Practice normalized notation, precision, and magnitude; measure absolute and relative error; investigate floating-point arithmetic; and test how time-step size changes an Euler result.
Textbook: Read Module 5.2, “Errors.”
See why an Euler update follows the current slope, compare one large step with several smaller steps, and weigh numerical error against the number of calculations.
Textbook: Read Module 6.2, “Euler’s Method.”
Use an Euler prediction to estimate the end-of-step rate, correct with the average rate, and compare RK2 with Euler at several time steps.
Textbook: Read Module 6.3, “Runge-Kutta 2 Method.”
Build four trial changes from one starting population, combine them with RK4’s weighted average, and compare its numerical error with Euler and RK2.
Textbook: Read Module 6.4, “Runge-Kutta 4 Method.”
Compare Euler, RK2, and RK4 on a familiar constrained-growth model. Test whether the method and time step change the first recorded year a population reaches a target.
Simulating with randomness
Compare uniform and normal random draws in R, then throw virtual darts to estimate π. Investigate why repeated estimates vary and how the number of darts affects reliability.
Textbook: Read Module 9.2, “Simulations.” Our rnorm() comparison previews Module 9.3, “Random Numbers from Various Distributions.”
Build one two-dimensional random walk, then repeat it to estimate a typical final distance and the chance of finishing near the start.
Textbook: Read Module 9.5, “Random Walk.”
Fitting models to data
Fit lines and curves to NIST data with lm(), use residuals to find what a model missed, and straighten a curved pattern with a power transformation.
Textbook: Read Module 8.3, “Empirical Models.”
Fit a line, a polynomial, and a sine curve to wavy data and compare their predictions beyond the data, see why a polynomial that hits every BOD data point can still be wrong, and choose a function shape before fitting.
Pulling it together
Estimate the chance that two people in a room share a birthday with a Monte Carlo simulation, check the estimate against an exact answer, see how the chance grows with class size, and test what happens when birthdays aren’t spread evenly.
Watch three identical companies drift apart in a toy stock market, add a sell rule with break, and simulate 1,000 shares to estimate how often each ending happens. Good preparation for Project 4.
Cellular automata and agents
Build a forest on a grid where each tree sees only its four neighbors, watch a fire spread from one burning tree, and repeat the simulation across tree densities to find a tipping point.
Textbook: Read Module 10.3, “Spreading of Fire.”
Place a crowd of people in an AgentCubes world, add one sick person, and let everyone wander. Write if–then rules for a person agent, watch the outbreak emerge, and add chance and recovery to build an agent-based version of SIR.
Rebuild the R fire model in AgentCubes: tree agents with healthy, burning, and dead shapes, attributes for each tree, and a two-phase check-and-act rule that does the job of the old and new grids.