# Euler's method setup

How can we use Euler's method to approximate the solutions for the following IVP below: $$y' = -y + ty^{1/2},\text{ with }1 \leq t \leq 2,\ y(1) = 2,$$ and with $h = 0.5$

The main concern is the organization, i.e., set up of it for this particular example.

And, if the actual solution to the IVP above is: $$y(t) = (t-2+\sqrt{2} \mathrm{e} \cdot \mathrm{e}^{-t/2})^2$$, then, how to compare the actual error and compare the error bound?

Thanks

-
It all depends on the norm you are choosing. –  eccstartup Mar 15 '12 at 4:38
The exact solution you cite has $y(2) = 2$ and $y(1) = \left(\sqrt{2 \mathrm{e}} - 1 \right)^2$, i.e. it solve the different IVP. –  Sasha Mar 15 '12 at 5:22

Fix a small step $h$ and iterate: $$t_0 = 1 \\ y_0 = y(1) = 2 \\ t_{n+1} = t_{n} + h \\ y_{n+1} = y_{n} + h (-y_{n} + t_{n} y_{n}^{1/2})$$ and the value $y_{n} \approx y(t_n).$

Try different small step $h = 0.1, 0.01, \ldots,$ and compare for all values of $t_0, t_0 + h, t_0 + 2h, \ldots$ the accuracy between the actual solution $y(t_n)$ you have and $y_n$ you computed.

-
This sounds good, but is rather vague. You can use the exact solution and compare the error for that to the DE given. Can you show how to carry that out? –  mary Mar 15 '12 at 5:57
Pick $h = 0.1$ This means that $t_n = [1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0]$ and $n$ ranges from $0$ to $10$. –  user2468 Mar 15 '12 at 6:03
Next step is to iteratively compute $y_n$ starting from $y_0.$ You know that $y_0 = 2$ from the initial value specification of the problem. Now, $y_1 = y_0 + h(-y_0 + t_0 y_0^{1/2}) = 2 + 0.1(-2 + 1\times(2)^{1/2}) = 1.9414.$ –  user2468 Mar 15 '12 at 6:05
Next is computing $y_2 = y_1 + h(-y_1 + t_1 y_1^{1/2} = 1.9414 + 0.1(-1.9414 + 1.1 \times (1.9414)^{1/2}) = 1.9005$ and so on for $y_3, y_4,$ upto $y_{10}$. –  user2468 Mar 15 '12 at 6:08
To compare the error between $y_n$ and $y(t_n)= (t_n-2+\sqrt{2} \mathrm{e} \cdot \mathrm{e}^{-t_n/2})^2$, simply pick, for example, $y_1 = 1.9414$ and compare it with $y(t_1) = y(1.1) = (1.1-2+\sqrt{2} \mathrm{e} \cdot \mathrm{e}^{-1.1/2})^2 = 1.7369.$ So the error is $1.9141-1.7369$. Same for $y_2,$ and so on. –  user2468 Mar 15 '12 at 6:11

The exact solution to the stated IVP actually reads: $$y(t) = \mathrm{e}^{1-t} \left( 1 + \sqrt{2} + \mathrm{e}^{(t-1)/2} \cdot(t-2) \right)^2$$

Here is the implementation of the Euler's scheme in Mathematica, for $h=0.2$:

In[68]:= sol[t_] := E^(1 - t) (1 + Sqrt[2] + E^((t - 1)/2) (-2 + t))^2;

In[69]:= f[t_, y_] := t Sqrt[y] - y;

In[70]:= approx =
With[{h = 0.2},
NestWhileList[# + {h, h Apply[f, #]} &, {1.0, 2.0},
First[#] < 2.0 &]]

Out[70]= {{1., 2.}, {1.2, 1.88284}, {1.4, 1.83559}, {1.6,
1.84783}, {1.8, 1.91326}, {2., 2.02856}}

In[71]:= Table[{t, sol[t]}, {t, approx[[All, 1]]}] - approx

Out[71]= {{0., 4.44089*10^-16}, {0., 0.0339166}, {0., 0.0594082}, {0.,
0.080083}, {0., 0.0983063}, {0., 0.115599}}

-
Can you please do it without using technology? I think that the practice of me asking it was via hand. Thanks –  mary Mar 15 '12 at 5:41
@mary Please see J.D.'s answer for how to do it by hand, or with the help of a calculator. –  Sasha Mar 15 '12 at 5:43