# How can I solve this Initial Value Problem using the Euler method?

My Problem is this given Initial Value Problem: $$y^{\prime}=\frac{3x-2y}{x}\quad y(1)=0$$ I am looking for a way to solve this problem using the Euler method. I have a given Interval of $[1,2]$ and a given step size $h$ of $h=0.1$

My Approach was: I can see, this is a differential Equation of first-order. I have one given initial condition $y(1)=0$. So this must be a initial value problem of first order. For the Euler Method, we need a step size of $h>0$. So our $0.1$ seems to be okay. Next thing, should be calculating: $$t_k=t_0+kh, \quad \quad k=0,1,2,\dots$$ And this is the point where i think i am stuck. I failed in calculating this and after reading the definitions i didn't succeed in making the connection from this method towards a solution for my given initial value problem, at all.

-
your "time" here is shown by $x$. your first time is $x=1$ at which $y=0$ by the initial condition. plug $x,y$ in right hand side side of your equation to get $y'=3$. this is your slope. Now calculate a rise for run of of $0.1$, remember rise is run*slope. So the rise is now $0.3$. Add this to the old value of $y$ which was 0 to get new value which is $0+.3=0.3$. Now you are the new point $(0.1,0.3)$. Repeat the process at this point. – Maesumi Jul 8 '13 at 21:40
Let me repeat, so i can see if i understood. Okay? We'll have a step size of 0.1. That's why we have to determine the value at $x$ for 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0. Right? The first was for $x=1$ at which $y=0$ ... plugged into the equation gives: $y^{\prime}=3$ as our slope. Now the next point gives: $y(1.1)=0.3$ ... again plugged into the equation: $y^{\prime}=\frac{3\cdot 1.1-2\cdot 0.3}{1.1}=\frac{2.7}{1.1}$ ... am i right? – Toralf Westström Jul 8 '13 at 22:02

We are given:

$$y'=\dfrac{3x-2y}{x}\quad y(1)=0$$

Interval is $x \in[1,2]$, and a given step size $h=0.1$

We have:

• $h = \dfrac{b-a}{N} = .1 = \dfrac{2-1}{N} \rightarrow N = 10$
• $x = a = 1$
• $y(a) = y(1) = \alpha = 0 \rightarrow a = 1, \alpha = 0$

Set:

• $x_0 = 1, x_i = 1 + 0.1 i, y_0 = 0$
• Using Euler's, we have: $y_i = y_{i-1} + hf(x, y) = y_{i-1} + .1\left(\dfrac{3 x_{i-1} - 2 y_{i-1}}{x_{i-1}}\right)$

For $i= 1$, we have:

$x_0 = 1, y_0 = 0, y_1 = y_{0} + .1\left(\dfrac{3 x_{0} - 2 y_{0}}{x_{0}}\right) = 0 + .1 \dfrac{3 (1) - 2(0)}{1.1} = 0.3$

For $i= 2$, we have:

$x_1 = 1.1, y_1 = 0.3, y_2 = y_{1} + .1\left(\dfrac{3 x_{1} - 2 y_{1}}{x_{1}}\right) = 0.3 + .1 \dfrac{3 (1.1) - 2(.3)}{1.1} = 0.5454$

Continuing this way, we generate the table:

$~~~~~\text{Step} ~~|~~ x ~~~|~~ y$

• $~~00 ~~| 1.0~~ | 0.$
• $~~01 ~~| 1.1 ~~| 0.3$
• $~~02 ~~| 1.2 ~~| 0.545455$
• $~~03 ~~| 1.3 ~~| 0.754545$
• $~~04 ~~| 1.4 ~~| 0.938462$
• $~~05 ~~| 1.5 ~~| 1.1044$
• $~~06 ~~| 1.6 ~~| 1.25714$
• $~~07 ~~| 1.7~~ | 1.4$
• $~~08 ~~| 1.8~~ | 1.53529$
• $~~09 ~~| 1.9 ~~| 1.66471$
• $~~10~~| 2.0~~ | 1.78947$

The exact solution is given by:

$$y(x) = \dfrac{x^3-1}{x^2}$$

At $x=2$, we have: $y(2) = \dfrac{7}{4} = 1.75$

Compare that to Euler's method, which has $1.78947$.

-
Excellent! Needs a TU! – amWhy Jul 9 '13 at 0:09
@amWhy: Appreciate the support! Thanks! – Amzoti Jul 9 '13 at 1:23

You want to use the following relations: $$y_{n+1} = y_n + hy'(t_n,y_n)$$ $$t_{n+1} = t_n + h$$ Set $t_0 = 1$ and try $h = 0.01$. Then: $$t_1 = 1.01, \ y(1.01) = y(1.00) + 0.01 \cdot\frac{3\cdot 1.00-2y(1.00)}{1.00} = 0.0300$$ $$t_2 = 1.02, \ y(1.02) = y(1.01) + 0.01 \cdot\frac{3\cdot 1.01-2y(1.01)}{1.01} = 0.0594$$ $$...$$ Similarly for $h=0.1$: $$y(1.1) = 0.300, \ y(1.2) = 0.545, \ y(1.3) = 0.754 ...$$, but the maximal error ($x \sim 1.5$) is larger , at $\rm{err} \sim 0.488$, vs. $\rm{err} \sim 0.0048$ for $h =0.01$.

Note that the exact solution is $y = x - 1/x^2$, which for large $x$ is just $y\sim x$. You can show that for a given choice of $h$, there exists a certain $x_h$ such that the error actually decreases after that point.

-
OP's $x$ step is $0.1$, not $0.01$ – Ross Millikan Jul 8 '13 at 23:13
@RossMillikan - edited, although one would think the method was clear enough. – nbubis Jul 8 '13 at 23:45
I agree, though your $t_1$ and $t_2$ lines still use the old step. – Ross Millikan Jul 8 '13 at 23:49