how to perform Runge-Kutta 2 for 3 variables? I have recently learned about the Runge-Kutta 2 method; however, in my textbook, it has only talked about solving for 2 variables.
For 2 variables (ie differential equation with x,y), we use the following:-
$$y_{i+1} = y_i + h(ak_1 + bk_2)$$
$$k_1 = f(x_i, y_i)$$
$$k_2 = f(x_i + \alpha h, y_i+ \beta k_1h)$$
$$a+b = 1$$
$$\alpha a = 1/2$$
$$\beta b = 1/2 $$
Now I was wondering, how can I perform this for a differential equation with 3 variables(x,y,z)?
 A: You got something wrong there in your conclusions. What you wrote down is the general form of an explicit 2-stage RK scheme, as first explored by K. Heun in 1900. The order 2 order conditions are
$$
α=β, ~~ a+b=1,~~ a⋅0+b⋅β=\frac12.
$$
This can be seen like it was done from the start, by Taylor expansion. We know that $$y(x+h)=y(x)+f(x,y(x))h+(f_x+f_yf)\frac{h^2}2+O(h^3).$$ Now compare this against the expansion of the numerical method, $$y_{+1}=y+(a+b)f(x,y)h+b(αf_x+βf_yf)h^2+O(h^3).$$
Note that $x$ is the independent variable and $y$ the dependent or state variable, which can also be a vector with $3$ components. The named variants of this general method are

*

*the explicit midpoint rule $y_{i+1}=y_i+hf(x_i+\frac12h, y_i+\frac12hk_1)$

*the Ralston method $y_{i+1}=y_i+\frac14h\bigl(k_1+3f(x_i+\frac23h, y_i+\frac23hk_1)\bigr)$,

*and Heun's 2nd order method $y_{i+1}=y_i+\frac12h\bigl(k_1+f(x_i+h, y_i+hk_1)\bigr)$ (or expl. trapezium etc.)

See Among midpoint method, Heun's method and Ralston method, which method of solving ODE performs better in which case and why? for a graphical comparison of the methods, giving a slight advantage to the midpoint method.
This scheme as written can be used in a scalar and in a vector interpretation, that is, where $y,k_1,k_2$ are all vectors of the state dimension. This second interpretation you would use for systems with 3 components. A typical example with 3 components is the Lorenz system with a fractal attractor, so searching for "Runge-Kutta Lorenz" will produce examples of different implementation strategies. The vector based approaches are in general more readable and easy to extend to larger systems.
