Solving state-space function with using of Runge-Kutta method I need to implement my own integration routine that will take state space function $f$, free variable $t$, and initial state $x(0)$ as input and produce the solution $x(t)$ as output. I thought that using Runge-Kutta method will be great. But I cannot understand how to apply it to the state-space function matrix.
$$\dot{x}=f(t,x)$$
$$\dot{x}=A\cdot{x}$$
I have only $A$ matrix. How can I apply Runge-Kutta method?
For example, could you provide step-by-step solution for:
$$
\begin{bmatrix} 
0 & 1 & 0 \\
0 & 0 & 1 \\
-10 & -5 & -2 \\
\end{bmatrix}
\quad
$$
Thanks in advance!
 A: You have a system $\dot{x} = f(x)$ with
$$
f(x) = A x = \begin{pmatrix}
0 & 1 & 0 \\
0 & 0 & 1 \\
-10 & -5 & -2
\end{pmatrix} \begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix} = \begin{pmatrix}
x_2 \\
x_3 \\
-10 x_1 - 5 x_2 - 2 x_3
\end{pmatrix}
$$
The formula for Runge Kutta with step size $h$ is:
$$
\begin{align}
k_1 &= f(x(t)) \\
k_2 &= f(x(t) + \frac{h}{2}k_1) \\
k_3 &= f(x(t) + \frac{h}{2}k_2) \\
k_4 &= f(x(t) + h k_3) \\
x(t + h) &= x(t) + \frac{h}{6}(k_1 + 2 k_2 + 2 k_3 + k_4)
\end{align}
$$
So all you need to do is choose a step size $h$ and initial condition $x(0) = x_0$.

For example use $h = 0.01$ and
$$
x_0 = \begin{pmatrix}
5 \\
-2 \\
3
\end{pmatrix}
$$
Insert this:
$$
\begin{align}
k_1 &= f(x_0) = \begin{pmatrix}
-2 \\
3 \\
-46
\end{pmatrix} \\
k_2 &= f(x_0 + \frac{h}{2}k_1) = \begin{pmatrix}
-1.985 \\
2.77 \\
-45.515
\end{pmatrix} \\
k_3 &= f(x_0 + \frac{h}{2}k_2) = \begin{pmatrix}
-1.98615 \\
2.772425 \\
-45.51485
\end{pmatrix} \\
k_4 &= f(x_0 + h k_3) = \begin{pmatrix}
-1.97227575 \\
2.5448515 \\
-45.02970925
\end{pmatrix} \\
\end{align}
$$
And so:
$$
x(0.01) = x(0) + \frac{0.01}{6}(k_1 + 2 k_2 + 2 k_3 + k_4) = \begin{pmatrix}
4.98014237375 \\
-1.972283830833333 \\
2.544850984583333
\end{pmatrix}
$$
If you repeat this 500 times you get:

If you simulate even longer you can see this is an undamped oscillation which makes sense because the three eigenvalues of $A$ are $-2, \sqrt{5}i, -\sqrt{5}i$.
