What is Euler’s Method

Formula/Equation

Method

Table

Worked Example

Other Numerical Approximations

Practice, Practice, Practice

Question 1

Question 2

Question 3

Euler’s Method in a Nutshell

## What is Euler’s Method

Euler’s method approximates ordinary differential equations (ODEs), giving you useful information about even the least solvable.

It’s likely that all the ODEs you’ve met so far have been solvable. After all, being asked unsolvable questions isn’t beneficial to learning!

The method is fairly simple – you can use it on any first order ODE, making it a fantastic introduction to the world of numerical methods.

Finding the solution to an ODE is similar to finding the equation of an unknown curve. So, to approximate the solution, build your own curve which roughly matches.

All you need to know is:

- The differential equation – the gradient of the tangent
- The curve’s starting point

The approximation equation is built in little steps. It “chases” the ODE curve, copying its tangent as closely as it can!

The gradient of each segment of the approximation equation is the same as the tangent line at the previous point. This means the tangent of the approximation curve is one step behind the real ODE.

The bigger the step, the further behind the approximation will be.

Moving along the approximation curve, the gradient of the next section is found by pretending the current point is on the ODE curve and using the differential equation to find its tangent line.

## Euler’s Method Formula/Equation

The ODEs you’re working with today are **first order**, which means any term has only been differentiated once or not at all.

If you’re drawing a blank on differential equations, here’s an intuitive demonstration with examples.

We’re particularly interested in ODEs with an initial value – they give us a starting point for the approximation curve. It’s much easier to trace a shape when you start with your pen on it!

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 \(x_n\) is chosen according to how big you want the steps.

The step size is the last term \(\Delta x\). The smaller the step size, the more accurate the approximation will be.

### The Method

- The first point is the initial value in the ODE, \(A_0=(x_0, y_0)\)
- Pick the \(x\) value of the second point, \(x_1\).
- 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\)
- The third point is found 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) \)
- 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! Filling in a table, where each iteration gets its own row, makes it easier to 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\).

Substituting \(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 are needed 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 very far from the ODE and doesn’t look much like it at all!

As \(\Delta x\) decreases to \(0.5\) and \(0.1\), shown in orange and green respectively, the shape mimics the exponential curve of the ODE much better.

It’s understandable why computers are used 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 just 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 each segment having the gradient from the previous point, the midpoint between x-values is used instead.

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 complicated! 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, which can be simplified 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 following 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 for you.

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 plays a pivotal role 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\), which is simplified 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 is used to approximate tricky, “unsolvable” ODEs with an initial value which cannot be solved 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! The midpoint and Runge-Kutta methods are more sophisticated.

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!