Beyond the HSC: Tackling Differential Equations with the Runge-Kutta Method

#hsc-maths#extension-2#calculus

In the HSC course we focus on finding exact closed‑form solutions to differential equations, but many real‑world models cannot be cracked with algebra alone. This enrichment problem walks you through the Runge‑Kutta 4th Order (RK4) method, a numerical workhorse used in engineering and physics, and shows you exactly how it matches an exact solution you already know. By working the steps side‑by‑side, you’ll see how numerical approximations are built from the very same calculus ideas you’ve been using all year, and you’ll gain a powerful tool for tackling equations that go beyond the syllabus.

Problem Statement

If you are studying HSC Mathematics Extension 1 or 2, you’ve likely encountered differential equations (DEs). You’ve learned elegant algebraic methods to find exact solutions—separating variables, integrating, and solving for yy.

But what happens when you hit a differential equation that can't be integrated using standard HSC techniques? In real-world physics, engineering, and computer science, exact solutions are often mathematically impossible to find. Instead, we turn to numerical methods to approximate the solution.

Today, as an enrichment extension to your HSC studies, we are going to look at the Runge-Kutta 4th Order method (RK4)—the absolute workhorse of computational mathematics.

The Problem: A Simple Decay Model

Let’s take a differential equation that we can solve using Extension 2 methods, so we have a benchmark to compare our numerical approximation against.

Consider the initial value problem:

dydx=2xy\frac{dy}{dx} = -2xy

Given the initial condition y(0)=1y(0) = 1.

Our goal is to find the value of yy when x=0.1x = 0.1.


Hints

Consider solving the separable differential equation analytically first to find the exact solution before applying the RK4 numerical method.


Solutions

Method 1: The Traditional (Exact) HSC Way

Because this equation is separable, we can find the exact analytical solution. We start by moving the yy‑terms to one side and the xx‑terms to the other.

  1. Separate the variables:
dyy=2xdx\frac{dy}{y} = -2x \, dx

Now we integrate both sides. The left integral is the natural log, and the right is a simple power rule.

  1. Integrate both sides:
1ydy=2xdx\int \frac{1}{y} \, dy = \int -2x \, dx lny=x2+C\ln\vert{}y\vert{} = -x^2 + C

To solve for yy, we exponentiate both sides, allowing the constant to absorb the sign from the absolute value.

  1. Solve for yy:
y=Aex2y = A e^{-x^2}

We pin down the constant AA by substituting the given initial condition x=0,y=1x=0, y=1.

  1. Apply the initial condition (x=0,y=1x=0, y=1):
1=Ae0    A=11 = A e^{0} \implies A = 1

So, our exact solution is y=ex2y = e^{-x^2}.

To find the exact value at x=0.1x = 0.1:

y(0.1)=e(0.1)2=e0.010.99004983y(0.1) = e^{-(0.1)^2} = e^{-0.01} \approx \mathbf{0.99004983}

Method 2: The RK4 Numerical Approach

Instead of integrating, numerical methods take small "steps" along the curve. The basic idea is to calculate the slope (the derivative) at your current point, and use it to step forward by a small amount, hh.

While simpler methods (like Euler's Method) just use one slope, RK4 takes a weighted average of four different slopes (k1,k2,k3,k4k_1, k_2, k_3, k_4) across the interval to get an incredibly accurate next step. The first slope, k1k_1, is simply the derivative at the start of the step.

Here is the RK4 formula for a step size hh:

yn+1=yn+h6(k1+2k2+2k3+k4)y_{n+1} = y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4)

Let's apply this to our DE f(x,y)=2xyf(x,y) = -2xy, starting at (x0,y0)=(0,1)(x_0, y_0) = (0, 1) with a step size of h=0.1h = 0.1.

  • k1k_1 (Slope at the start):
k1=f(0,1)=2(0)(1)=0k_1 = f(0, 1) = -2(0)(1) = 0

We use k1k_1 to approximate the value of yy halfway through the interval, then evaluate the derivative at that midpoint to get k2k_2.

  • k2k_2 (Slope at the midpoint using k1k_1):
k2=f(x0+h2,y0+h2k1)=f(0.05,1)=2(0.05)(1)=0.1k_2 = f(x_0 + \frac{h}{2}, y_0 + \frac{h}{2}k_1) = f(0.05, 1) = -2(0.05)(1) = -0.1

Similarly, we re‑estimate the midpoint slope, this time using k2k_2 to nudge yy, giving us k3k_3.

  • k3k_3 (Slope at the midpoint using k2k_2):
k3=f(x0+h2,y0+h2k2)=f(0.05,10.005)=f(0.05,0.995)=0.0995k_3 = f(x_0 + \frac{h}{2}, y_0 + \frac{h}{2}k_2) = f(0.05, 1 - 0.005) = f(0.05, 0.995) = -0.0995

Finally, we advance a full step using k3k_3 and evaluate the derivative at the end of the interval to get k4k_4.

  • k4k_4 (Slope at the end using k3k_3):
k4=f(x0+h,y0+hk3)=f(0.1,10.00995)=f(0.1,0.99005)=0.19801k_4 = f(x_0 + h, y_0 + hk_3) = f(0.1, 1 - 0.00995) = f(0.1, 0.99005) = -0.19801

Now, plug these four slopes into the main formula to find our new yy value. The weighted average gives a very precise estimate of the overall slope over the step.

y(0.1)=1+0.16(0+2(0.1)+2(0.0995)+(0.19801))y(0.1) = 1 + \frac{0.1}{6}(0 + 2(-0.1) + 2(-0.0995) + (-0.19801)) y(0.1)=1+0.16(0.59701)=10.00995016=0.99004983y(0.1) = 1 + \frac{0.1}{6}(-0.59701) = 1 - 0.00995016 = \mathbf{0.99004983}

The Verdict: Comparing the Methods

Let's look at the results at x=0.1x = 0.1:

  • Exact Calculus Solution: 0.99004983...0.99004983...
  • RK4 Approximation: 0.99004983...0.99004983...

With just a single step, the RK4 method matched our exact analytical solution out to the 8th decimal place.

This is exactly why RK4 is so highly regarded. While it requires more arithmetic than basic algebraic integration, it allows us to crack complex differential equations that would otherwise be impossible to solve by hand.


Takeaways

Where to Go Next

Understanding the mathematics behind RK4 is just the beginning. If you are looking to push your mathematics and problem-solving skills further before university, here is how you can expand on this:

  1. Compare with Euler's Method: Try solving the same equation using Euler's method. You will quickly see how much faster the error accumulates compared to RK4.
  2. Write a Python Script: Calculating k1k_1 through k4k_4 by hand gets tedious. This algorithm is perfectly suited for automation. Try writing a simple Python loop that calculates RK4 over 100 steps.
  3. Data Visualization: Once you have generated the data points in Python, use a library like matplotlib to plot your RK4 curve against the exact solution.
  4. Performance Analysis: Experiment with your code. What happens to your error margin if you change the step size hh from 0.10.1 to 0.010.01? At what point does the computational cost outweigh the gain in precision?

Conclusion

The mathematics you learn in HSC Extension 1 and 2—calculus, functions, and algebra—form the fundamental vocabulary needed for higher-level problem solving. But as you transition into university-level STEM fields, the focus shifts from finding perfectly clean, exact solutions, to building robust, algorithmic approximations. Mastering numerical methods like RK4 is your first step into the world of computational engineering and applied mathematics.


Further Readings

HSC Integrals

Written by Vu Hung Nguyen

Mathematics Educator · LinkedIn · About