As a simple exercise for a class in computational methods for physics, we've learned how to implement the RK4 (Runge-Kutta 4th-order) algorithm for a very simple exponential decay. E.g. the function y(t) is governed by

y and y dot definitions

Based on the RK4 definition from most sources, and specifically in this case Wikipedia,

wikipedia rk4 values

determining the 4 values k₁, k₂, k₃, and k₄ all depend on the function f(t,y) for different increments of t

y dot = f(t, y)

However, since I don't know y(t) for arbitrary times (that's what the RK4 approximation is trying to calculate), I can't easily get f(t+h/2, y+k₁/2) like in the Wikipedia notation for k₂.

My question is: When the time dependence of f(t, y) is not known in an exact form, would it be possible to just use Euler’s method of approximation for f(t, y) for all of the kn values instead of just k₁?


1 Answer 1


That's exactly what Runge-Kutta does: You have a differential equation y' = f (y, t), and you calculate those values and plug them into the Runge-Kutta formula. Of course you don't know y (t) exactly, that's what the formula produces for you.

You say "I can't easily get f(t+h/2, y+k1/2) like in the wikipedia notation for k2". Of course you can. You calculate t + h/2, y + k1/2 and use the results. That's what the formula says. It doesn't say "use y(t)". It says "use y + k1/2". You are totally overthinking this.

PS. Keep your fingers away from the Euler approximation. The coefficients in the Runge-Kutta formula are very, very cleverly calculated to give you the best possible results. If you mess with it by trying to somehow put Euler approximations in there, you just mess it up and totally destroy your precision.

  • $\begingroup$ So, since f(t, y)=-y/tau I can say that f(t+h/2, y+k1 / 2) is just -( y+ k1 / 2 )/ tau? I was thinking that since y was a function of t that I would have to do -( y(t+h /2)+ k1 / 2 )/ tau. Am I supposed to ignore that y is a function of t for the function f(t, y)? That's what your answer seems to say. $\endgroup$
    – WindowsNT
    Commented Sep 12, 2018 at 22:53
  • $\begingroup$ @WindowsNT: Yes, exactly that, you understood the answer correctly. $\endgroup$ Commented Sep 13, 2018 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.