How it works...

First, it is important to understand that the RK4 measure is intended to be used within a table or other visualization that provides the values of time (t) that correspond with the chosen step sizes (h) for the time period of interest. Second, because subsequent steps of the implementation of the Runge-Kutta formulas require the values from the previous calculations of the Runge-Kutta formulas, the implementation of the Runge-Kutta method is essentially a recursive process. Because there is no true recursion in DAX, this recipe simulates recursion by using nested variables. 

We start by capturing the current value of our t column from the R03_Table table within the current context and store this value in the tCurrent variable. Next, we define the initial parameters of our Runge-Kutta implementation. The initial value for t is set to 0. The initial value of our line at time 0, w, is set to .5. Finally, our step size, h, is set to our chosen value of .5

We now define the step1 variable. step1 is intended to calculate the first step of our Runge-Kutta calculation. However, we may be at time equal to 0 and thus not need to run through our Runge-Kutta calculations. Thus, we first check to see if tCurrent is equal to 0. If so, we simply return the current value of our variable, w. Otherwise, we implement our Runge-Kutta calculations. To do this, we first set our k1t variable to t. Next, we increment our t variable by h. We can reuse variable names here because we are working within nested variables. The scope of this new value for t is only used for calculations further down within the nested variables. In other words, the value of t outside of the step1 variable is still the original value of t (0). We also set our k1w variable equal to w. We can now calculate our values for k1, k2, k3, and k4 using k1t, k1w, and h and plugging these values into our Runge-Kutta formulas. Finally, we compute the next point on our line, w.  

The next variable, step2, is a essentially a repeat of step1. Here, we first check if tCurrent is equal to our step size of h. If so, we set step2 equal to the current value of w. Critically, the value of w is the value computed during step1, which is the next point on our line. Otherwise, we repeat the process, setting k1t equal to t (which is the value of t computed in step1). We also increment t (the value of t computed in step1) by h. Additionally, we set k1w to the value of w (which is the value of w computed in step1). 

We repeat this pattern for step3 and step4. Thus, at the first increment of h, step1, we are actually returning the w value computed in step1 as the value of step2, which then becomes the value of step1 and thus the value of RK4. At the second increment of h, step2, we are actually returning the w value computed in step2 as the value of step3, which becomes the value of step2, which becomes the value of step1, which becomes the value of RK4, and so on.

It is OK if your brain hurts.