Euler method fails

numerical methodsordinary differential equations

Consider the differential equation $$y'=y-2e^{-x},$$
with initial value $y(0)=1$. It's not hard to see that $y=e^{-x}$ is the solution.

I am trying to solve this numerically via the forward Euler method. However, no matter how I shrink my step size $h$, the error of my numerical solution always diverges: in fact, the error at $x$ seems to be growing like $e^x$.

My question is why does the numerical solution error always diverge?

The numerical solution from the Euler method can be expressed in the form $$y_n=A(1+h)^n+Be^{-hn},$$
for appropriate constants $A,B$. I have a feeling that divergence has something to do with the fact that $|1+h|>1$, but I'm not sure how to formalize this.

As a follow-up, which numerical methods will solve this DE without the error blowing up?

Best Answer

The general solution of this ODE is $e^{-x}+C\,e^x$. With $y(0)=1$, we conclude $C=0$. But every rounding error in any numerical method will introduce a spurious $C\neq0$, and given the notorious behavior of exponential functions, this will overwhelm your numerical approximation.