# Euler method differential equation

I have an example of Euler's numeric method:

$$\frac{dy}{dx}=2xy$$

$$y(x)=2$$

So $f(x,y)=2xy$ and the step: $x_{i+1} = x_i +h$ where $h=0.1$

$$y_{i+1} = y_i +h f(x_i,y_i)$$

The first iteration is

$$y_{1} = y_0 + h \cdot f(0,2)= 0 +0.1 \times (2 \times 0 \times 2)=2$$

$$x_{1} = x_0 + h = 0 +0.1 = 0.1 .$$

The second iteration is

$$y_{2} = y_1 + h \times f(0.1,2)= 0 +0.1 \times (2 \times 0.1 \times 2)=2.4$$

$$x_{2} = x_1 + h = 0.1 +0.1 = 0.2 .$$

etc...

My question is that I am facing a problem like:

$$\frac{dy}{dt} = \frac{t}{y} ,$$ with $y(0)=1$ and $y(t)=\sqrt{1+t^{2}}$.

In the example, besides the obvious switch $(x,t)$, The $y(t)=\sqrt{1+t^{2}}$ is not given so to solve the problem I do not know hw to apply the Euler method Could you help in this one?

-

## 1 Answer

You are given $y(0)=y(t_0)=y_0=1$. Let's say that, as with your first example, we have $h=0.1$. Then $t_1=t_0+h=0+0.1=0.1$, $t_2=t_1+h=0.1+0.1=0.2$, $\dots$, $t_k=0.1\cdot k$.

The differential equation $y'=t/y$ means $f(t,y)=t/y$. Euler's method says $y(t_{n+1}) \approx y_{n+1} = y_n + f(t_n,y_n)h$

$y(0) = y(t_0) = y_0 = 1$

$y(0.1) = y(t_1) \approx y_1 = y_0+f(t_0,y_0)h = 1+f(0,1)0.1 = 1+(0/1)0.1=1$

$y(0.2) = y(t_2) \approx y_2 = y_1+f(t_1,y_1)h = 1+f(0.1,1)0.1 = 1+(0.1/1)0.1 = 1.01$

$y(0.3) = y(t_3) \approx y_3 = y_2+f(t_2,y_2)h = 1.01+f(0.2,1.01)0.1 = 1.01+(0.2/1.01)0.1 = \dots$

You don't need the actual solution $y(t) =\sqrt{1+t^2}$ unless you need to find the error.

-
How is the error computed? –  cMinor Nov 14 '11 at 1:45
Let's say we want error at $t_2=0.2$. Then the actual answer is $y(t_2)=y(0.2)=\sqrt{1+(0.2)^2}=\sqrt{1.04}$. However, the approximate answer is $y_2=1.01$. The error at $t=t_2=0.2$ is $y(t_2)-y_2 = \sqrt{1.04}-1.01 \approx 0.098$. –  Bill Cook Nov 14 '11 at 2:17