Solution (source code)

= Solution

Let $h=1/N$, $x_j=jh$, and let $y_j$ approximate $y(x_j)$. The <forward Euler method> gives the <difference equation>
$$
\boxed{y_{j+1}=y_j+h(-\lambda y_j)
=\left(1-\frac\lambda N\right)y_j,\qquad y_0=2.}
$$
This <geometric sequence> has solution
$$
\boxed{y_j=2\left(1-\frac\lambda N\right)^j\quad(0\le j\le N),
\qquad y_N=2\left(1-\frac\lambda N\right)^N.}
$$
For fixed $\lambda$, the <limit> as $N\to\infty$ is $2e^{-\lambda}$, as required by the exact solution.