First Order Differential Equations
The Euler Method
The Euler method is a numerical technique for approximating solutions to first-order differential equations. It's like taking baby steps along a curve, using the derivative to guide each step.
Consider a point $(x_n, y_n)$, where the derivative of this point is $$y_n'(x_n, y_n)$$. The tangent line at this point is given by
$$y - y_n= y_n'(x_n, y_n)(x-x_n)$$
$$y = y_n + y_n'(x_n, y_n)(x-x_n)$$
Now let us consider a new point $x_{n+1}, y_{n+1}$, where $x_{n+1}$ is defined by $x_{n+1}= x_{n}+h$ for some small $h$.
Here comes the approximation step. We can imagine that, for some small $h$, the rate of change at the points $(x_n, y_n)$ and $(x_{n+1}, y_{n+1})$ are incredibly similar to the point where they are effectively the same.
If the rate of change at these points are similar, the point $(x_{n+1}, y_{n+1})$ should lie on the tangent line of $(x_n, y_n)$
Therefore, by substituting the point $(x_{n+1}, y_{n+1})$ into the tangent line:
$$y_{n+1} = y_n + y_n'(x_n,y_n)(x_{n+1}-x_n)$$
$$y_{n+1} = y_n + y_n'(x_n)(h)$$
$$y_{n+1} = y_n + hy_n'(x_n)$$
Or alternatively, by letting $f(x_n, y_n) = y_n'(x_n,y_n)$
$$y_{n+1} = y_n + h\cdot f(x_n, y_n)$$
Where:
- $y_{n+1}$ is the next y-value
- $y_n$ is the current y-value
- $h$ is the step size
- $f(x_n, y_n)$ is the derivative at the current point
Thus obtaining a sequence of values $(x_n, y_n)$ that satisfy a differential equation.
TipChoose a smaller step size ($h$) for better accuracy, but be aware this increases computational work. For smaller $h$, the approximation of rate of changes being similar between $x_n$ and $x_{n+1}$ becomes more accurate.
ExampleSolve $\frac{dy}{dx} = x + y$ with initial condition $y(0) = 1$ using h = 0.2 for the first two steps.
Step 1: At x = 0, y = 1 $y_1 = 1 + 0.2(0 + 1) = 1.2$
Step 2: At x = 0.2, y = 1.2 $y_2 = 1.2 + 0.2(0.2 + 1.2) = 1.48$
TipRemember that the Euler's method is not foolproof. There are cases when it doesn't work, for example.
- When the rate of change increases rapidly such that the derivative approximation is invalid.
- Asymptotes—certain differential equations don't have solutions at certain points, but Euler's method neglects this and spits out a number anyway.