I have a question from my book and it says essentially, consider the IVP $x^{\bullet}=-x$ with $x(0)=1$, what is the exact value of x(1), then using Eulers method with step size1 , estimate $x(1)$ call this $x^{*}(1)$ , then repeat for step sizes of $10^{-n}$ for $n=1,2,3,4$ then finally plot $E=|x^{*}(1)-x(1)|$ as a function of step size and then as $lnE$ vs $lnt$.
Now I am having some issues and ill explain,
for the first part I get that $x(1)=e^{-1}$
We have $f(x)=-x$ and $x_{0}=1$
so I have that by Euler method
$x_{1}=x_{0}+f(x_{0})t$
which would imply that for $t=1 ,x_{1}=0$
and then for the second part it would imply $x_{1}=0.9$, then $0.99$, then $0.999$ and finally $0.9999$.
But this doesn't seem to make any sense to me. Seeing as none of these are close to $e^{-1}$
So I am confused in regard to where I am making mistakes, or where everything is going wrong. For the plotting part, I am also stuck because of this. I am looking for any help and advice.
Thanks
Let $h=1/m$ be the step size, Euler's methode applied to the discretization $(t_k)_{0\le k \le n}$ with $t_k=k/m$ yields the values $x_0,\ldots,x_m$ With $x_0=1$ and $$ x_{k+1}= x_k- hx_k=(1-h)x_k,\qquad k=0,\ldots,m-1$$ This implies, by an easy induction, that $$ x_{k}= \left(1-h\right)^k,\qquad k=0,\ldots,m$$ Now the estimate of $x(1)=e^{-1}$ given by Euler's corresponding to step size $h=1/m$ is $x^*(1)=x_m=(1-h)^m=\left(1-\frac1m\right)^m$, and the corresponding error is $$E=E(m)=\left|e^{-1}-\left(1-\frac1m\right)^m\right|= e^{-1}-\left(1-\frac1m\right)^m$$ In particular, $$E(m)=\frac{ e^{-1}}{2m}+\mathcal{O}\left(\frac{1}{m^2}\right)$$ Or equivalently, in terms of the step size $h$: $$E(h)=\frac{ e^{-1}}{2}h+\mathcal{O}\left(h^2\right)$$ So the plot $(\log h,\log E)$ should be very close to the line $y=x-\log2-1$. This is confirmed by WolframAlpha here and here.