next up previous
Next: About this document ...

Euler and improved Euler using SAGE

The goal is to find an approximate solution to the problem


\begin{displaymath}
y'=f(x,y),\ \ \ y(a)=c,
\end{displaymath} (1)

where $f(x,y)$ is some given function. We shall try to approximate the value of the solution at $x=b$, where $b>a$ is given. This will be explained mathematically and using the software package SAGE, available from http://sage.scipy.org. To use SAGE below on you machine, you will have to (a) install SAGE, (b) ``attach'' the file eulers_method.sage file in the examples subdirectory.

The basic idea can also be explained ``algebraically''. Recall from the definition of the derivative in calculus 1 that


\begin{displaymath}
y'(x)\cong \frac{y(x+h)-y(x)}{h},
\end{displaymath}

$h>0$ is a given and small. This an the DE together give $f(x,y(x))\cong \frac{y(x+h)-y(x)}{h}$. Now solve for $y(x+h)$:


\begin{displaymath}
y(x+h)\cong y(x)+h\cdot f(x,y(x)).
\end{displaymath}

If we call $h\cdot f(x,y(x))$ the ``correction term'' (for lack of anything better), call $y(x)$ the ``old value of $y$'', and call $y(x+h)$ the ``new value of $y$'', then this approximation can be re-expressed


\begin{displaymath}
y_{new}=y_{old}+h\cdot f(x,y_{old}).
\end{displaymath}

Tabular idea: Let $n>0$ be an integer, which we call the step size. This is related to the increment by


\begin{displaymath}
h=\frac{b-a}{n}.
\end{displaymath}

This can be expressed simplest using a table.

$x$ $y$ $hf(x,y)$
$a$ $c$ $hf(a,c)$
$a+h$ $c+hf(a,c)$  
$a+2h$    
     
$b$ ??? xxx

The goal is to fill out all the blanks of the table but the xxx entry and find the ??? entry, which is the Euler's method approximation for $y(b)$.

Improved Euler's method

Geometric idea: The basic idea can be easily expressed in geometric terms. As in Euler's method, we know the solution must go through the point $(a,c)$ and we know its slope there is $m=f(a,c)$. If we went out one step using the tangent line approximation to the solution curve, the approximate slope to the tangent line at $x=a+h, y=c+h\cdot f(a,c)$ would be $m'=f(a+h,c+h\cdot f(a,c))$. The idea is that instead of using $m=f(a,c)$ as the slope of the line to get our first approximation, use $\frac{m+m'}{2}$. The ``improved'' tangent-line approximation at $(a,c)$ is:


\begin{displaymath}
y(a+h)\cong c+h\cdot \frac{m+m'}{2}
=c+h\cdot \frac{f(a,c)+f(a+h,c+h\cdot f(a,c))}{2}.
\end{displaymath}

(This turns out to be a better apprpximation than the tangent-line approximation $y(a+h)\cong c+h\cdot f(a,c)$ used in Euler's method.) Now we know the solution passes through a point which is ``nearly'' equal to $(a+h,c+h\cdot \frac{m+m'}{2})$. We now repeat this tangent-line approximation with $(a,c)$ replaced by $(a+h,c+h\cdot f(a,c)$. Keep repeating this number-crunching at $x=a$, $x=a+h$, $x=a+2h$, ..., until you get to $x=b$.

Tabular idea: The integer step size $n>0$ is related to the increment by


\begin{displaymath}
h=\frac{b-a}{n},
\end{displaymath}

as before.

The improved Euler method can be expressed simplest using a table.

$x$ $y$ $h\frac{m+m'}{2}=h\frac{f(x,y)+f(x+h,y+h\cdot f(x,y))}{2}$
$a$ $c$ $h\frac{f(a,c)+f(a+h,c+h\cdot f(a,c))}{2}$
$a+h$ $c+h\frac{f(a,c)+f(a+h,c+h\cdot f(a,c))}{2}$  
$a+2h$    
     
$b$ ??? xxx

The goal is to fill out all the blanks of the table but the xxx entry and find the ??? entry, which is the improved Euler's method approximation for $y(b)$.

The idea for systems of ODEs is similar. This is implemented below as well.




next up previous
Next: About this document ...
David Joyner 2006-08-29