Description
Implementing Runge Kutta 4
CAPITALISED items are vectors
With start state BOAT(n), time t, timestep h and static context CONTEXT.
BOAT... is an instantaneous state vector
RCHANGE... is a rate of change vector
Where VECTOR1 = f(VECTOR0) means that for each element VECTOR1[i] of VECTOR1
VECTOR1[i] = f(VECTOR0[i])
RCHANGE = update_physics(BOAT, t, CONTEXT) gives the rate of change of BOAT[i] for all i at time t given constant
factors CONTEXT
if t(n+1) = t(n) + h
using t == t(n)
RCHANGE1 = update_physics(BOAT(n), t, CONTEXT)
BOAT1 = BOAT(n) + 0.5 * h * RCHANGE1
RCHANGE2 = update_physics(BOAT1, t + h / 2, CONTEXT)
BOAT2 = BOAT(n) + 0.5 * h * RCHANGE2
RCHANGE3 = update_physics(BOAT2, t + h / 2, CONTEXT)
BOAT3 = BOAT(n) + 0.5 * h * RCHANGE3
RCHANGE4 = update_physics(BOAT3, t + h, CONTEXT)
BOAT(n+1) = BOAT(n) + h * (RCHANGE1 + 2.0 * RCHANGE2 + 2.0 * RCHANGE3 + RCHANGE4) / 6.0
i.e. for all elements i of BOAT
BOAT(n+1)[i] = BOAT(n)[i] + h * (RCHANGE1[i] + 2.0 * RCHANGE2[i] + 2.0 * RCHANGE3[i] + RCHANGE4[i]) / 6.0