← Back to the lecture

Playground

Run it yourself

Projectile with drag

The solver from the slides, running here. Change what you are throwing, how hard, and how finely the solver walks through time. Nothing is precomputed: every line on this page is integrated in the browser when you move a control.

Object

k = 0.0070 /m

Launch

Solver

194 steps to land. Coarsen h and watch Euler leave the true path while RK4 stays on it.

range62.58 m
in vacuum91.74 m
air takes29.2 m, 32%
off the fine run0.000 m

What this page is running

function rate(u: State, k: number): State {
  const [, , vx, vy] = u;
  const speed = Math.hypot(vx, vy);
  return [vx, vy, -k * speed * vx, -G - k * speed * vy];
}

const rk4Step: Stepper = (u, h, k) => {
  const a = rate(u, k);
  const b = rate(add(u, a, h / 2), k);
  const c = rate(add(u, b, h / 2), k);
  const d = rate(add(u, c, h), k);
  return u.map((ui, i) =>
    ui + (h / 6) * (a[i] + 2 * b[i] + 2 * c[i] + d[i]));
};

Same twelve lines either way. The physics is in rate, the numerics is in the stepper, and the choice of language is the least interesting decision in the file.