TITLE: What does the code do and what ODE is that?
QUESTION [1 upvotes]: This exercise I came across asks what kind of method of solving ODE is that:
function x1 = Solve(N,T)
   h = T/N;
   x1(1) = 0; x2(1) = 1;
   for k = 2:N
      x1(k) = 2*x1(k-1) + h*x2(k-1);
      x2(k) = x2(k-1) + h*x2(k-1)*x1(k-1)^2;
   end
and the Matlab code also supposed to contain one error.
I guess, the error is in the following: for k = 2:N should be replaced with for k = 2:N+1. 
But what does the code do? It must be a differential equation of the second order transformed to a system of first order. 
\begin{align}
x^{(1)}_k & = 2x^{(1)}_{k-1} + h x^{(2)}_{k-1} \\
x^{(2)}_k & = x^{(2)}_{k-1} + h x^{(2)}_{k-1} (x^{(1)}_{k-1})^2 \\ 
\end{align}
The chapter I took it from doesn't discuss that many methods: forward Euler (and generally Taylor method), backward Euler, trapezoidal rule. But I can't recognize any of them in the code. Or maybe one needs to first see what kind of ODE the method is solving to see what the method is.
Any help is hugely appreciated.

REPLY [1 votes]: Expanding my comment: To me it looks like the update law
\begin{equation}
x_k^{(1)} = 2x^{(1)}_{k-1} + hx^{(2)}_{k-1}
\end{equation}
contains an error because of the $2$ coefficient in the first term on the right-hand side. If that were a $1$, we'd have a forward Euler update law for the ODE
\begin{equation}
\dot{x} = \left(\begin{array}{c} x_2 \\ x_2x_1^2 \end{array}\right).
\end{equation}
I've changed the superscript indices to subscripts, but hopefully the point is clear here.
{"set_name": "stack_exchange", "score": 1, "question_id": 1361357}