What to prepare
Exam 2 is Monday, November 9, 2026. It has 12 multiple-choice questions (12 points), five matching items (5 points), three R code-reading questions (3 points), and two short calculations (10 points), for 30 points total. Each multiple-choice, matching, or code-reading item is worth one point; each calculation is worth five. It is designed to fit within the 50-minute class. Circle one answer for each multiple-choice or code-reading question; write a letter for each matching item; and show your setup for the calculations. No calculator is needed. You may leave correct answers in equation form without simplifying the arithmetic. Any needed rate equations, and the RK4 weighting formula, will be supplied in the questions. I will confirm the notes policy in class before the exam.
For our Wednesday review, bring this guide. We will discuss the format and expectations, then work through selected practice problems together. To prepare, try the problems before opening the answer sections. These examples use different numbers and contexts from the exam.
Review the course modules for Modules 6.2, 6.3, 6.4, 9.2, 9.5, and 8.3; Numerical Methods in Practice; and Empirical Models in Practice. Project 3 is useful practice for Euler and RK2, but you will not have to write a whole Quarto report or run R on the paper exam.
By Monday, be ready to:
- carry out one Euler step and one RK2 step from a supplied rate, and explain what each RK4 trial change means;
- explain what a smaller time step or a higher-order method can and cannot fix;
- read a short Monte Carlo or random-walk simulation and say what its result estimates; and
- compute residuals for a fitted line, read a residual pattern, and explain why a model that fits the data can still predict badly.
Numerical methods: Euler, RK2, and RK4
All three methods answer the same question: given the population (or other stock) now and a formula for its rate, what is it one time step later? They differ in how they estimate the change over the step.
| Method | Rate evaluations per step | How it estimates the change |
|---|---|---|
| Euler | 1 | Use the rate at the start of the step for the whole step: \(P_{\text{new}}=P+\text{rate}(P)\,\Delta t\). |
| RK2 (Euler’s predictor-corrector) | 2 | Predict an endpoint with Euler, find the rate there, then redo the step from the old value using the average of the starting and predicted ending rates. |
| RK4 | 4 | Compute four trial changes from the same old value (start, two midpoints, endpoint) and combine them with weights \(1,2,2,1\) divided by 6. Update the stored value once. |
Reading RK2
For a rate \(f(P)\) and step \(\Delta t\):
- start rate \(=f(P)\)
- Euler prediction \(=P+f(P)\,\Delta t\)
- predicted end rate \(=f(\text{Euler prediction})\)
- average rate \(=(\text{start rate}+\text{predicted end rate})/2\)
- corrected value \(=P+(\text{average rate})\,\Delta t\)
The Euler prediction is used only to find the second rate. The corrected step still starts from the old value.
Reading RK4
The four trial changes \(\partial_1,\dots,\partial_4\) are each an estimate of the change over the full step:
\[ \begin{aligned} \partial_1 &= f(P)\,\Delta t, & \partial_2 &= f(P+\partial_1/2)\,\Delta t,\\ \partial_3 &= f(P+\partial_2/2)\,\Delta t, & \partial_4 &= f(P+\partial_3)\,\Delta t, \end{aligned} \qquad P_{\text{new}} = P+\frac{\partial_1+2\partial_2+2\partial_3+\partial_4}{6}. \]
Know why the midpoints use half a change, why \(\partial_4\) uses the full \(\partial_3\), and why none of the trial values becomes the stored population.
What step size and method can fix
- Smaller steps usually reduce numerical error, at the cost of more calculations. For our smooth growth model, halving \(\Delta t\) roughly halved Euler’s error (first order) and cut RK4’s error by about a factor of 16 once the step was small.
- At the same step size, RK2 was more accurate than Euler, and RK4 more accurate than RK2, on the models we tried. Compare methods at the same \(\Delta t\).
- A large step can mislead a decision: in Numerical Methods in Practice, the one-year Euler run reported reaching 500 a year later than RK2 and RK4, and a two-year Euler run overshot the carrying capacity.
- No numerical method can fix a model that leaves out something important or uses a wrong parameter. Accuracy compared with the equation is not evidence that the equation describes the world.
Monte Carlo simulation and random walks
- A stochastic model uses chance, so repeated correct runs can give different answers. A Monte Carlo simulation repeats random experiments many times to estimate a quantity or a probability.
- Computers make pseudorandom numbers with a deterministic rule that starts from a seed.
set.seed()replays the same draws, which helps with checking code and comparing changes fairly. runif(n, min, max)draws \(n\) values spread evenly over an interval.rnorm(n, mean, sd)draws values that cluster near the mean;sdsets the spread, not a hard limit. The distribution is part of the model: the dartboard estimate works only because the darts land uniformly in the square.- Dartboard estimate of π: for a circle of radius 1 inside a \(2\times2\) square, a dart at \((x,y)\) hits when \(x^2+y^2\le1\), and \(\pi\approx 4\times(\text{hits})/(\text{darts})\).
- More runs usually make an estimate more reliable, but a single larger run isn’t guaranteed to be closer than a smaller one. Report a simulation result with some sense of its variation.
- In our random walk, each step moves one unit east or west and one unit north or south, chosen by fair coin flips (
runif(1) < 0.5). After \(n\) steps the path length is always \(n\sqrt2\); the displacement \(\sqrt{x^2+y^2}\) is random and usually much smaller. mean(final_distances <= 5)gives the fraction of simulated walks that ended within 5 units, because R countsTRUEas 1 andFALSEas 0.
Empirical models
- A mechanistic model explains a system: each term stands for something real. An empirical model is chosen only because it follows the data, and it is used to predict, not explain.
lm(y ~ x)finds the least-squares line: the one with the smallest sum of squared residuals.lm()can fit any linear combination of terms, such aslm(y ~ x + I(x^2))for a quadratic orlm(y ~ sin(x))for a wave.- A residual is \(\text{observed } y - \text{predicted } y\). Residuals that look like random scatter around zero are what we want; a pattern (such as an arch) means the model is missing something.
- To straighten a concave-up pattern, try plotting \(y\) against \(x^p\) for a power \(p>1\), then fit a line. Always check the final curve against the original data.
- Extrapolation means predicting outside the range of the data. An empirical model has no evidence there.
- More terms are not always better. A degree-5 polynomial passes exactly through six points, with zero residuals, and still makes absurd predictions between and beyond them. Choose a shape that makes sense for the system before fitting.
Multiple-choice practice
The exam has 12 general multiple-choice questions; there are 20 practice questions here so you can choose extra ones to review. Try them before opening the answers. Each has one best answer.
- Euler’s method estimates the change over a step using the rate A. at the start of the step; B. at the end of the step; C. at the midpoint; D. averaged over several steps.
- A population of 100 has rate \(0.1P\) per year. One Euler step of 2 years gives A. 102; B. 110; C. 120; D. 200.
- For a smooth model, halving Euler’s time step typically makes the error about A. the same; B. half as large; C. one-fourth as large; D. one-sixteenth as large.
- In RK2 (Euler’s predictor-corrector), the corrected step uses A. only the starting rate; B. the average of the starting rate and the rate at the Euler-predicted endpoint; C. the largest of four trial rates; D. a random rate.
- In RK2, the Euler prediction is A. stored as the new population; B. used only to estimate the rate at the end of the step; C. thrown away without being used; D. the exact answer.
- RK4 combines its four trial changes with weights A. 1, 1, 1, 1 divided by 4; B. 1, 2, 2, 1 divided by 6; C. 2, 1, 1, 2 divided by 6; D. 1, 2, 3, 4 divided by 10.
- How many times does RK4 evaluate the rate in one step? A. 1; B. 2; C. 4; D. 6.
- All four RK4 trial changes are built from A. the same old value; B. four successive updated populations; C. the exact solution; D. random draws.
- A simulation’s prediction disagrees with field data because the model leaves out migration. Switching from Euler to RK4 will A. fix the problem; B. reduce numerical error but not this model error; C. add migration; D. make the time step larger.
- Two Monte Carlo runs with the same assumptions but different seeds give slightly different answers. This means A. one run has a bug; B. chance makes individual runs vary; C. the model is deterministic; D.
set.seed()failed. - The main reason to call
set.seed()in our code-alongs is to A. make the numbers truly random; B. reproduce the same draws when we rerun the code; C. make the simulation faster; D. switch from uniform to normal draws. runif(5, min = 10, max = 20)produces A. five values spread evenly between 10 and 20; B. five values centered near 15 that can fall outside 10–20; C. the numbers 10 through 14; D. one value between 5 and 20.rnorm(100, mean = 10, sd = 2)produces values that A. are all between 8 and 12; B. cluster near 10 but can fall outside 8–12; C. are spread evenly from 0 to 10; D. are all exactly 10.- In the dartboard simulation, 780 of 1,000 darts land inside the circle. The estimate of \(\pi\) is A. 0.78; B. 3.00; C. 3.12; D. 3.20.
- After 25 diagonal random-walk steps, which quantity is the same for every walk? A. the displacement; B. the final \(x\) coordinate; C. the path length, \(25\sqrt2\); D. whether the walk ends within 5 units.
mean(final_distances <= 5)computes A. the average final distance; B. the fraction of walks that ended within 5 units; C. the number of steps in each walk; D. the largest final distance.- An empirical model is based A. on the mechanism of the system; B. only on data, and is used to predict rather than explain; C. on random draws; D. on the exact solution of a rate equation.
- A line’s residuals form a clear arch: negative at both ends and positive in the middle. The best conclusion is A. the line is a perfect model; B. the model is missing a curved pattern; C. the data have no measurement error; D. we should extrapolate.
- A load cell was tested with loads from 150 to 3,000. Using the fitted line to predict the deflection at a load of 10,000 is A. interpolation; B. extrapolation; C. a residual; D. a Monte Carlo estimate.
- A degree-5 polynomial fits six data points with residuals of zero. What should you conclude? A. It is the best possible model; B. It may have memorized the points and should be checked for sensible predictions; C. Its predictions outside the data are guaranteed; D. Residuals are always zero for good models.
- A. Euler uses the starting rate for the whole step.
- C. \(100+0.1(100)(2)=120\).
- B. Euler is first order, so halving the step roughly halves the error.
- B. RK2 averages the starting rate and the predicted ending rate.
- B. The prediction only supplies the second rate; the step restarts from the old value.
- B. The midpoint changes count twice: \((\partial_1+2\partial_2+2\partial_3+\partial_4)/6\).
- C. One rate for each of the four trial changes.
- A. None of the trial values is stored until the final update.
- B. A better numerical method solves the same incomplete equations more accurately.
- B. Stochastic models give different results on different runs.
- B. A seed replays the same pseudorandom draws.
- A.
runif()spreads values evenly over the interval. - B.
sdcontrols the spread; it isn’t a cutoff. - C. \(4(780)/1000=3.12\).
- C. Every step has length \(\sqrt2\); only the displacement is random.
- B.
TRUEcounts as 1, so the mean is the fraction ofTRUEvalues. - B. That is the book’s definition of an empirical model.
- B. A pattern in the residuals means the model missed something; a quadratic fixed this one.
- B. 10,000 is far outside the tested range.
- B. Zero residuals on a few points are a warning sign, not a success.
Matching practice
Match each description to a method or idea. Use each letter once: A. Euler’s method; B. RK2; C. RK4; D. Monte Carlo simulation; E. empirical model.
- Combines four trial changes with weights 1, 2, 2, 1.
- Throws random darts at a square to estimate the area of a circle.
- Predicts an endpoint, then averages the starting and predicted ending rates.
- A curve fit to sensor measurements, trusted only inside the range of the data.
- Assumes the rate at the start of a step stays constant for the whole step.
1 C (RK4); 2 D (Monte Carlo); 3 B (RK2); 4 E (empirical model); 5 A (Euler).
R code-reading practice
The exam’s code questions will be short and selected-response. You will not have to write a program.
1. Which method does this step implement?
start_rate <- growth_fraction * old
prediction <- old + start_rate * delta_t
end_rate <- growth_fraction * prediction
population[i] <- old + (start_rate + end_rate) / 2 * delta_tA. Euler; B. RK2; C. RK4; D. a random walk.
2. What value does the last line produce?
x <- c(0.3, 0.8, 0.6, 0.1)
y <- c(0.9, 0.7, 0.7, 0.5)
inside <- x^2 + y^2 <= 1
4 * sum(inside) / length(x)A. 1; B. 3; C. 4; D. 3.14.
3. This code is meant to simulate 500 separate 25-step walks. What is wrong with it?
x_position <- 0
y_position <- 0
for (run in 1:500) {
for (step in 1:25) {
x_position <- x_position + ifelse(runif(1) < 0.5, 1, -1)
y_position <- y_position + ifelse(runif(1) < 0.5, 1, -1)
}
final_distances[run] <- sqrt(x_position^2 + y_position^2)
}A. Nothing; it is correct; B. the positions are never reset, so the walks join into one long path; C. runif(1) < 0.5 makes east more likely than west; D. the walk should use rnorm().
4. Which call fits a quadratic model of y as a function of x?
A. lm(y ~ x); B. lm(y ~ x + I(x^2)); C. lm(x ~ y); D. lm(y ~ 0 + x).
1 B. A start rate, an Euler prediction, an end rate, and their average form the RK2 step. 2 B. The four values of \(x^2+y^2\) are 0.90, 1.13, 0.85, and 0.26, so three darts are inside: \(4(3)/4=3\). 3 B. The reset to 0 belongs inside the run loop. 4 B. I(x^2) adds the squared term.
Short calculation practice
The exam has two calculations. Here are four kinds to practice.
- Euler and RK2. A population of 200 has rate \(0.05P\) per year. With a two-year step, find the Euler estimate. Then find the RK2 estimate, showing the start rate, the Euler prediction, the predicted end rate, and the average rate.
- RK2 with a different rate. A drink’s temperature \(T\) (°F) changes at a rate of \(20-0.1T\) degrees per minute. Starting at \(T=100\) with a one-minute step, find the RK2 estimate.
- RK4 trial changes. A population of 50 has rate \(0.2P\) per year. With a one-year step, find \(\partial_1\), \(\partial_2\), \(\partial_3\), and \(\partial_4\), then the RK4 estimate.
- Residuals. Three data points are \((1, 5)\), \((2, 9)\), and \((3, 10)\). For the line \(y=2+3x\), find each residual and the sum of squared residuals. Repeat for the line \(y=3+2.5x\). Which line would
lm()prefer, and why?
- Start rate \(=0.05(200)=10\) per year, so Euler gives \(200+10(2)=220\). Predicted end rate \(=0.05(220)=11\). Average rate \(=(10+11)/2=10.5\). RK2 gives \(200+10.5(2)=221\). (The exact answer for this model is about 221.03.)
- Start rate \(=20-0.1(100)=10\), so the Euler prediction is \(100+10(1)=110\). Predicted end rate \(=20-0.1(110)=9\). Average \(=9.5\), so RK2 gives \(100+9.5(1)=109.5\) °F.
- \(\partial_1=0.2(50)(1)=10\). \(\partial_2=0.2(50+5)(1)=11\). \(\partial_3=0.2(50+5.5)(1)=11.1\). \(\partial_4=0.2(50+11.1)(1)=12.22\). RK4 gives \(50+(10+2(11)+2(11.1)+12.22)/6=50+11.07=61.07\).
- For \(y=2+3x\): predictions 5, 8, 11; residuals \(0, 1, -1\); sum of squares \(0+1+1=2\). For \(y=3+2.5x\): predictions 5.5, 8, 10.5; residuals \(-0.5, 1, -0.5\); sum of squares \(0.25+1+0.25=1.5\).
lm()chooses the line with the smaller sum of squared residuals, so it prefers \(y=3+2.5x\) (in fact, that is the least-squares line for these points).
Outside this exam
You will not be asked to write a complete R program, memorize the RK4 formula, find an exact analytic solution, fit a model with a parameter search or nls(), trace a linear congruential generator, or use Quarto syntax. Exam 1 material is not the focus, but you should still be comfortable with stocks, rates, time steps, and absolute and relative error, since the new methods build on them.