0

Please note I am no mathematician, and this has been a struggle for me to understand the concepts below. I have several questions regarding the Runge-Kutta 4th order formula. "deltaTime" is my overall fixed time step.

(Q1) How to perform the math in the parenthesis?

(Q2) The second formula uses [t] in the function, but the first does not. How does that [t] calculate into it?

(Q3) I am understanding that this is used for finding the [Y] position at a given time step. Is this incorrect? If so, how can this be applied to an [X] coordinate as well?

(Q4) Is there a way to calculate angular positions and velocities with RK4?

(Q5) [f] & [g] simply mean: value(of everything in here) ???

Here is one version of the formula I have come across:

k1 = f(Position.Y, Velocity.Y)
k2 = f(Position.Y + (deltaTime / 2), Velocity.Y + (k1 / 2) * deltaTime)
k3 = f(Position.Y + (deltaTime / 2), Velocity.Y + (k2 / 2) * deltaTime)
k4 = f(Position.Y + deltaTime, Velocity.Y + k3 * deltaTime)

Position.Y += (1 / 6) * (k1 + (2 * k2) + (2 * k3) + k4) * deltaTime

Here is a second version I have come across:

k1 = deltaTime * f(Position.Y, Velocity.Y, t)
l1 = deltaTime * g(Velocity.Y)
k2 = deltaTime * f(Position.Y + (l1 / 2), Velocity.Y + (k1 / 2), t + (1 / 2))
l2 = deltaTime * g(Velocity.Y + (k1 / 2))
k3 = deltaTime * f(Position.Y + (l2 / 2), Velocity.Y + (k2 / 2), t + (1 / 2))
l3 = deltaTime * g(Velocity.Y + (k2 / 2))
k4 = deltaTime * f(Position.Y + l3, Velocity.Y + k3, t + 1.0)
l4 = deltaTime * g(Velocity.Y + k3)

Velocity.Y += (1.0 / 6.0) * (k1 + (2 * k2) + (2 * k3) + k4)
Position.Y += (1.0 / 6.0) * (l1 + (2 * l2) + (2 * l3) + l4)

(Q5) I see the difference in those two (one has more math in it) but what is one used for over the second one?

I have spent the last 3 days looking up how to apply these methods to a programming problem I am having, so I have already read the (overly complicated) wiki page, as well as several topics on various forums. That being said, I would appreciate any assistance I can get with my specific questions.

  • 1
    For Q5; The first bit of code is used to solve a single ODE, the second bit to solve a coupled system of ODEs. – Matthew Cassell May 29 '16 at 06:41
  • @Mattos - Thanks, I had no clue what the difference was. – Nicholas May 29 '16 at 06:56
  • May I ask you why do you need to dwelve into the details of Runge-Kutta 4. It is a very particular piece of applied mathematics that doesn't deserve to spend on it days ans days... (the weighted average k=(k1 + 2 * k2 + 2 * k3 + k4)/6 is a very witty way to cancel low order terms, OK, but it is at the same time so 'technical'...). Why don't you use powerful implementations such as rk4 in Matlab, as a blackbox ? It's good to spend time on some techniques in order to better understand them, but in this case, 3 whole days spent on this issue is already too much: it is not worth the value. – Jean Marie May 29 '16 at 07:16
  • @JeanMarie - I suck at advanced math...hence the questions. I'm not using this for Matlab. Maybe it would be nice to work a problem out on paper without using a calculator written by people much smarter than myself. Lastly, I'm an idiot and it takes a while for me to understand things...I thought by informing people that potentially may be able to help how much time I have spent on this would assist with me getting some assistance, instead of other questions. – Nicholas May 29 '16 at 15:06
  • I see now better your point of view. It has taken me also a while for understanding many things, and hard work on scientific issues is in general a key for a through understanding. The only thing I can say is that I have verified that generally I am more efficient when working in parallel a (mathematical) theory and its implementation (Matlab, and more and more on computer algebra systems). – Jean Marie May 29 '16 at 15:25
  • 1
    I have a programming loop with a fixed time step. I must calculate the position of a falling object with high precision during each loop. Because I have no experience in this area, I have no clue how to correctly write a function to produce a value for what is in the parenthesis. – Nicholas May 29 '16 at 15:40
  • I'm guessing that everyone uses Matlab to calculate this instead of trying to work this out on paper? – Nicholas May 29 '16 at 18:23
  • 1
    The first set of formulas actually doesn't make any sense, because for k2, k3, and k4 the first parameter of f is the sum of a position and an elapsed time; the dimensions are incompatible. – David K Oct 03 '16 at 05:23

0 Answers0