Euler's Method for Solving Ordinary Differential Equations
Wish to evaluate a generic function f(t). Suppose we know a starting value, for example, f(0) = c. We also know that we can express f(\cdot) through the ordinary differential equation
\begin{eqnarray*} \frac{\partial}{\partial t} \textrm{f}(t) = \textrm{g}(\textrm{f}(t)), \end{eqnarray*}
where \textrm{g}(\cdot) is a known function. Occasionally, we can solve the ordinary differential equation analytically. More often, a numerical solution is available. The easiest to explain and to implement is Euler's method. To see this, consider a small h and use a straight line approximation for the derivative
\begin{eqnarray*} \frac{\partial}{\partial t} \textrm{f}(t) \approx \frac{\textrm{f}(t+h)-\textrm{f}(t)}{h}. \end{eqnarray*}
With this, we have an approximation to the ordinary differential equation
\begin{eqnarray*} \textrm{f}(t+h) \approx \textrm{f}(t) + h \textrm{g}(\textrm{f}(t)) \end{eqnarray*}
that we can evaluate recursively.
\begin{eqnarray*} \frac{\partial}{\partial t} \textrm{f}(t) = \textrm{g}(\textrm{f}(t)), \end{eqnarray*}
where \textrm{g}(\cdot) is a known function. Occasionally, we can solve the ordinary differential equation analytically. More often, a numerical solution is available. The easiest to explain and to implement is Euler's method. To see this, consider a small h and use a straight line approximation for the derivative
\begin{eqnarray*} \frac{\partial}{\partial t} \textrm{f}(t) \approx \frac{\textrm{f}(t+h)-\textrm{f}(t)}{h}. \end{eqnarray*}
With this, we have an approximation to the ordinary differential equation
\begin{eqnarray*} \textrm{f}(t+h) \approx \textrm{f}(t) + h \textrm{g}(\textrm{f}(t)) \end{eqnarray*}
that we can evaluate recursively.

Suppose that \textrm{g}(t) = 0.05 t, a line, and f(0) = 1. Then, if h=0.001, we have
\begin{eqnarray*}
\textrm{f}(t+h) \approx \textrm{f}(t) + (0.001) (0.05) \textrm{f}(t) .
\end{eqnarray*}
t | 0 | 0.001 | 0.002 | 0.998 | 0.999 | 1.000 |
Approximate f(t) |
1.0000000000 | 1.0000500000 | 1.0001000025 | 1.0511646632 | 1.0512172215 | 1.0512697823 |
Exact f(t) | 1.0000000000 | 1.0000500013 | 1.0001000050 | 1.0511659745 | 1.0512185341 | 1.0512710964 |
Error | 0.0000000000 | 0.0000000013 | 0.0000000025 | 0.0000013113 | 0.0000013127 | 0.0000013140 |
For this example, we can evaluate f(\cdot) analytically, in that
\begin{eqnarray*}
\frac{\partial}{\partial t} \textrm{f}(t) = 0.05 \textrm{f}(t) \ \ \ \ \Rightarrow \ \ \ \ \frac{\partial}{\partial t} \ln \textrm{f}(t) = 0.05 ,
\end{eqnarray*}
and so that, with f(0) = 1, we have \textrm{f}(t) = e^{0.05 t}.