Why can one make a second-order ODE to first-order for ode45?
Such as in these examples:
https://www.sharetechnote.com/html/Octave_Matlab_DifferentialEquation.html
E.g.
$$m \frac{d^2x}{dt^2}+kx=0$$
turns into
$y_1=x$
$y_2=\frac{dy_1}{dt}=\frac{dx_1}{dt}$
Given a differential equation of the form
$$\frac{d^nx}{dt^n} = f\left(t, x(t), \frac{dx}{dt}, \frac{d^2x}{dt^2}, \ldots, \frac{d^{n-1}x}{dt^{n-1}} \right)$$
One can define the variables
$$\mathbf{y} = \begin{bmatrix} y_1 \\ y_2\\ y_3 \\ \vdots \\ y_n \end{bmatrix} = \begin{bmatrix} x \\ \frac{dx}{dt}\\ \frac{d^2x}{dt^2}\\ \vdots \\ \frac{d^{n-1}x}{dt^{n-1}}\end{bmatrix}$$
which give the first order system $\mathbf{y}'=\mathbf{F}(t,\mathbf{y}(t))$ whose solution can be approximated using ode45 (or an array of other solvers such as any Runge–Kutta method):
$$\mathbf{y}'= \begin{bmatrix} y_1' \\ y_2'\\ y_3' \\ \vdots \\ y_n' \end{bmatrix}= \begin{bmatrix} \frac{dx}{dt}\\ \frac{d^2x}{dt^2}\\ \frac{d^3x}{dt^3}\\\vdots \\ \frac{d^{n}x}{dt^{n}}\end{bmatrix} = \begin{bmatrix} y_2 \\ y_3\\ y_4 \\ \vdots \\ f \end{bmatrix} =: \mathbf{F} $$
The first coordinate of the solution $\mathbf{y}$ to this equation, $(x(t))$, is a solution to the original differential equation, which can be seen by repeated substitution
$$f = y_n' = (y_{n-1}')' = \ldots = \frac{d^{n}y_1}{dt^{n}} = \frac{d^{n}x}{dt^{n}}$$
in this case, $n=2$ and $f = -\frac{k}{m}x$.