Let consider on $[0,20]$, the ODE : $y'(t)=y^2(t)-y^3(t)$ and $y(0)=1$.
I start to use a backward Euler method using : $y_{n+1}=y_n+h(y_{n+1}^2-y_{n+1}^3)$ with $h>0$ given.
I build $F:y_{n+1}\mapsto y_{n+1}-y_n-h(y_{n+1}^2-y_{n+1}^3)$ such that $F(y_{n+1})=0$.
If $F'(y_{n+1})\neq 0$, I can use the Newton's method to determine $y_{n+1}$.
Do I have to consider $y_{n+1}-\frac{F(y_{n+1})}{F'(y_{n+1})}=y_{n+1}-\frac{y_{n+1}-y_n-h(y_{n+1}^2-y_{n+1}^3)}{1-2hy_{n+1}+3hy_{n+1}^2}=\frac{y_n-hy_{n+1}^2+2hy_{n+1}^3}{1-2hy_{n+1}+3hy_{n+1}^2}$ ? Then how to continue ?
Thanks in advance !
Best Answer
obviously your ODE has the stationary solution $y(t)=1$.
Anyway,your ODE is clearly non-linear, so, as you stated, you have to set to zero the following function:
$F(x)=x-y_n - hf(x)$, where $f$ is defined as $ f=y^2 - y^3$.
So, $F'(x)= 1 - h\frac{df}{dx}(x)$ (i used this notation because $f$ could be a function of $t$)
In order to do this, you have to use Newton's method:
given $x_1=y_n$ (the current value of the solution is the initial guess for Newton's iteration), do $x_{k+1}=x_k - \frac{F(x_k)}{F'(x_k)}$ until the difference $|x_{k+1} - x_k|$ or the norm of the 'residue' is less than a given tolerance (or combination of absolute and relative tolerances)
This can be coded as follow. In this code I used Newton's method for non-linear systems.
And the result agrees with the previous calculation, as shown in the graphic.
Please notice that I set the 'tol' parameter proportional to $h^2$: this is due to the fact that the Backward Euler's error is $\mathcal{O}(k^2)$