# Euler’s Method · Differential Equation Numerical Solution

## What is Euler’s Method

Euler’s method approximates ordinary differential equations (ODEs).

This gives you useful information about even the least solvable differential equation.

It’s likely that all the ODEs you’ve met so far have been solvable. but, you may need to approximate one that isn’t.

Euler’s method is simple – use it on any first order ODE!

It is also a fantastic introduction to the world of numerical methods.

Finding the solution to an ODE is like finding the equation of an unknown curve.

To approximate the solution, build your own curve which roughly matches.

What you need to know is:

• The differential equation – the gradient of the tangent
• The curve’s starting point The approximation equation builds in little steps. It “chases” the ODE curve, copying its tangent as closely as it can! Each segment of the approximation equation’s gradient is the same as the tangent line at the previous point.

In simple terms, this means the slope of the approximation curve is one step behind the real ODE.

The smaller the step, the closer the approximation will be.

Moving along the approximation curve, you’ll find the gradient of the next section by pretending the current point is on the ODE curve.

Then you use the differential equation to find its tangent line.

## Euler’s Method Formula/Equation

The ODEs you’re given here are first order, which means any term is differentiated once at most.

Need a refresh on differential equations? Here’s an intuitive demonstration with examples.

Now, we’re particularly interested in ODEs with an initial value. They give us a starting point for the approximation curve.

These have the form:

\eqalign{ \frac{dy}{dx}=f(x , y) ,\:\: y(x_0)=y_0 }

$$y_n = y_{n-1} + f(x_{n-1} , y_{n-1})\Delta x$$

$$(x_{n-1}, y_{n-1})$$ is the last point you found, then choose $$x_n$$ by how big you want the steps to be. (Or, how much work you’re willing to put in!)

The step size is the last term $$\Delta x$$.

The smaller the step size, the more accurate the approximation will be, but the more work you’ll do.

### The Method

1. The first point is the initial value in the ODE, $$A_0=(x_0, y_0)$$
2. Pick the $$x$$ value of the second point, $$x_1$$.
3. Find $$f(x_0, y_0)$$ by plugging these values into the ODE. The second point is then $$y_1 = y_0 + f(x_0 , y_0)\Delta x$$
4. Find the third point in a similar way: find $$f(x_1, y_1)$$ using the original ODE. Then calculate $$y_2 = y_1 + f(x_1, y_1)(x_2 – x_1)$$
5. Repeat until you have found enough points to plot a good graph

### Euler’s Method Table

There are so many terms flying around, it’s hard to keep track!

Fill in a table, where each iteration gets its own row. This makes it easier to spot and correct any mistakes. For this worked example, keep your own table of values. Remember that each iteration gets its own row!

### Worked Example

Use Euler’s method on $$\large\frac{dy}{dx}\normalsize=2y, y(0)=1$$ with $$\Delta x=1$$. From now, $$\Delta x$$ means the change in $$x$$ from one point to the next – that’s the step size!

The solution to this ODE is $$y=e^{2x}$$, which you’ll see from $$\large\frac{d}{dx}\normalsize(e^{2x})= 2e^{2x}$$.

You don’t need to know the solution before starting – that would defeat the purpose of using the method! But while learning, it’s helpful to sketch the ODE curve: Begin by writing what you already know in a table: The step size, $$\Delta x=1$$ so $$x_1=x_0+1=1$$. Continue in this way, finding the new $$y_n$$ with Euler’s formula then $$y_n’=2y_n$$. Substitute $$x_3=3$$ into the actual solution $$y=e^{2x}$$.

The corresponding value $$y_3$$ should be $$e^6=403.43$$. Getting $$27$$ is a very rough approximation!! More accuracy, please! A smaller step size of $$\Delta x=0.5$$ should help.

Make a table like before but with $$x_n$$ values increasing by $$0.5$$ in each iteration: Then complete the table, at least far enough to see whether it is a better approximation. 64 is closer to
The smaller the steps, the more iterations you’ll need to see the “full picture” of the curve. It’s like painting a picture with a smaller brush – more detail, but more effort! What happens if the steps are super small? With $$\Delta x=0.1$$, you get the following table: Comparing the approximation graphs so far, it’s clear how important step size is. With $$\Delta x=1$$, shown in red, the approximation lags far behind the ODE and doesn’t look much like it at all! As $$\Delta x$$ decreases to $$0.5$$ (orange) and $$0.1$$ (green), the shape more closely mimics the true curve of the ODE.

It’s understandable why we use computers for most numerical applications. The number of tiny-step iterations needed to be accurate would take a long time to do by hand.

## The Improved Euler’s Method and Other Numerical Approximations

You’re probably thinking that this technique is unstoppable, that it always works. Why use more complicated methods when this one works fine?

The problem is how long it takes to make an accurate approximation.

It’s no good building an approximation that doesn’t come close to the original ODE.

That’s like painting a beautiful flower when you’re meant to paint a mountain!

Using a very small step does work well but takes a very, very long time even for a computer, and way longer to do by hand. You’d run out of time to do anything else!

You need to work smarter, not harder, to quickly make an accurate approximation.

The midpoint method does this. Instead of giving each segment the previous point’s, use the midpoint between x-values.

The approximation curve lags behind the ODE by half a step instead of one whole step. It’s quicker to react to changes in the ODE curve’s shape!

Other numerical techniques exist, but they are compex!

Stretch yourself by getting a flavor for the Runge-Kutta methods.

## Practice, Practice, Practice

Have a go at the following three questions to test your knowledge! Keep a table to help keep track of what numbers come next.

### Question 1

Use a step size of $$\Delta x=0.5$$ to approximate solutions to $$y’=e^y, y(0)=1$$ at values $$x=\{0, 0.5, 1\}$$.

The initial condition $$y(0)=1$$ gives $$(0,1)$$ as the starting point. Put in $$x_1=0, x_2=0.5,x_3=1$$ into a table. $$f(x_n, y_n) = e^{y_n}$$ gives the values in the right column.

$$y_n = y_{n-1} + f(x_{n-1} , y_{n-1})\Delta x$$ gives the new $$y$$ values.

Simplify to $$y_n = y_{n-1} + e^{y_{n-1}}\cdot0.5$$ by substituting in the step size and $$f(x_n, y_n)$$.

This gives the completed table: ### Question 2

Repeat question 1, but with a step size of $$\Delta x =0.2$$. Compare the values at $$x=0$$ and $$x=1$$ to the previous values found.

Start off with the same table, except this time the x-values are 0, 0.2, 0.4, 0.6, 0.8, and 1: Using the same equations, you can then fill out the table row by row again. You should get: Notice how the y-values and gradients get huge after only a few iterations! That’s the power of exponential functions right there.

With $$\Delta x=0.5$$, you get the points $$(0,1)$$ and $$(1, 7.649)$$. With $$\Delta x=0.2$$, these become $$(0,1)$$ and $$(1, 5.74×10^{12})$$. That’s a huge difference!

Even with the same starting point and function, step size is pivotal in controlling the approximation curve’s shape.

### Question 3

Use a step size of $$\Delta x=1$$ to approximate solutions to $$y’-y=\sin(x), y(0)=0$$ at values $$x=\{0, 1, 2, 3\}$$.

The first thing to notice is that the ODE isn’t quite in the right form. Rearrange it so all the differentiated terms are on one side: $$y’=y+\sin x, y(0)=0$$.

You’re now ready to do the table like before! Start by filling in what you know from the equation, without doing calculations. Euler’s formula tells you $$y_n = y_{n-1} + f(x_{n-1} , y_{n-1})\Delta x$$.

Simplify to $$y_n = 2\cdot y_{n-1} + \sin x_{n-1}$$ by substituting the ODE and $$\Delta x=1$$ in. ## Euler’s Method in a Nutshell

Euler’s method estimates “unsolvable” ODEs which won’t solve using techniques from calculus.

Build an approximation with the gradients of tangents to the ODE curve. The gradient of a segment depends on the gradient at its starting point, so the approximation “lags behind” the proper ODE.

Euler’s formula $$y_n = y_{n-1} + y_{n-1}’\Delta x$$ tells you which y-value you should plot next. The x-values are chosen according to the step size.

Don’t forget to set your values out in a nice table to avoid confusion!

The smaller the step, the more accurate the approximation but the longer it takes to work out!

For better results with less work, use the more sophisticated midpoint and Runge-Kutta methods.

That’s it for today! I hope you enjoyed this introduction to numerical analysis.

Please leave comments and questions below, whether you’re stuck on a problem or have invented a new approximation method!

Scroll to Top
Scroll to Top