Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

The book here (sorry not in English) on page 676:

$$\begin{cases}y'=-y^{2} \\ y(0)=1\end{cases}$$

when $x_{k}=\frac{k}{5}$ which means $h=0.2$ i.e. $\Delta x=x_{k+1}-x_{k}=0.2:=h$. The task is to calculate 5 steps with the logic on pages 670-671:

$$\begin{align*} y_{k+1}&=y_{k}+hf(x_{k},y_{k}) \\ h&=x_{k+1}-x_{k} \\ k&=0,1,...\end{align*}$$ where $f(x_{k},y_{k})=y'$.

My solution

I calculated the Euler values on the left and the right having the exact values. For example, $y_{1}=y_{0}+h \left|y'(y_{0})\right|=1-0.2*(1)^{2}=\frac{4}{5}$. I got the same as the R verified values below but my exact values are $0.5, 0.66, 0.6, 0.625, 0.61...$ which I think are wrong. The way I calculated the exact values is this:

  1. separate-integrate $y'=-y^{2}$
  2. you get $y(x)=\frac{1}{x+1}$ because $y(0)=1$
  3. Then $y(y_{0})=y(1)=0.5, y(y_{1})=y(0.5)=2/3,...$ until recursion ends to the fifth.

Are my results correct?

R -verification for the Euler -method

I was eventually able to get the same values as here by hand.

> euler<-function(y){a<-y; for(i in 1:5){b<-a-0.2*a**2; print(b); a<-b}}
> euler(1)
[1] 0.8
[1] 0.672
[1] 0.5816832
[1] 0.5140121
[1] 0.4611704

Thanks to Julian, I had misunderstanding in the parameters. The below should be correct.

> 1/((1:5/5)+1)
[1] 0.8333333 0.7142857 0.6250000 0.5555556 0.5000000

Let's compare the values. The exact values are always greater than the Euler values because of the derivative $y'(x)=\frac{-1}{(x-1)^{2}}$, I am not yet sure how to vizualize this in R, basically the above values into data.frame and then matplot(df), investigating...

plot(1/(1:100+1), type='l' )

enter image description here

Perhaps related

  1. Euler's Method for slope fields
share|improve this question
    
...found instructions here how to verify this kind of things on Maple, unfortunately I have no Maple. Perhaps, there is some other way to check whether I am doing things correctly, investigating... –  hhh Feb 25 '12 at 21:20
    
You need to explain what is "the same book as earlier", what you meant by h, $y_0$ and $y_1$, where k has gone, how you came up with "recursion" (instead of iteration), ... lots of things –  nodakai Feb 25 '12 at 21:22
    
@nodakai: Wow, I just realized the book has become online! Cool -- now you can see it in the updated question. If I can understand the Euler method correctly, it is a recursive equation. Please, see the bottom: given $y_{0}$, then calculate $y_{1}$, then $y_{2}$ and so on. –  hhh Feb 25 '12 at 21:44

1 Answer 1

up vote 2 down vote accepted

You are confusing $x_k$ and $y_k$ in the exact values. Expresions like $y(y_1)$ make no sense.

$y_k$ is an approximation of the exact value $y(x_k)$. The exact values are $$ y(0)=1,\quad y(0.2)=\frac1{1+0.2}=0.833,\quad y(0.4)=\frac1{1+0.4}=0.714, $$ $$ y(0.6)=\frac1{1+0.6}=0.625,\quad y(0.8)=\frac1{1+0.8}=0.555,\quad y(1)=\frac1{1+1}=0.5. $$

share|improve this answer
    
You apparently approximate values with $y_{k+1}\approx y(x_{k+1})$ (the page 670) where $x_{k+1}=h+x_{k}$? Yes that is clear now, no recursion in this function. –  hhh Feb 25 '12 at 23:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.