100% found this document useful (1 vote)
412 views

Euler's Method

Euler's method is a numerical technique for approximating solutions to differential equations. It works by taking small steps to iteratively calculate next y-values based on the slope of the tangent line at each point. The document provides an example of using Euler's method to solve the initial value problem dy/dx = y/x, y(2) = e, calculating values from x=2 to x=3 in steps of h=0.1. The approximated solution follows the shape of the actual solution curve closely, with an error of only 1.42% at x=3.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
412 views

Euler's Method

Euler's method is a numerical technique for approximating solutions to differential equations. It works by taking small steps to iteratively calculate next y-values based on the slope of the tangent line at each point. The document provides an example of using Euler's method to solve the initial value problem dy/dx = y/x, y(2) = e, calculating values from x=2 to x=3 in steps of h=0.1. The approximated solution follows the shape of the actual solution curve closely, with an error of only 1.42% at x=3.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Euler's Method - a numerical solution for Differential Equations

Why Numerical Solutions?

For many of the differential equations we need to solve in the real world, there is no "nice" algebraic
solution. That is, we can't solve it using the techniques we have met in this chapter (separation of
variables, integrable combinations, or using an integrating factor), or other similar means.

As a result, we need to resort to using numerical methods for solving such DEs. The concept is similar
to the numerical approaches we saw in an earlier integration chapter (Trapezoidal Rule, Simpson's Rule
and Riemann Sums).

Even if we can solve some differential equations algebraically, the solutions may be quite complicated
and so are not very useful. In such cases, a numerical approach gives us a good approximate solution.

The General Initial Value Problem

We are trying to solve problems that are presented in the following way:

𝑑𝑦
= 𝑓(𝑥, 𝑦); 𝑎𝑛𝑑
𝑑𝑥

𝑦 (𝑎) (𝑡ℎ𝑒 𝑖𝑛𝑖𝑡𝑖𝑎𝑙 𝑣𝑎𝑙𝑢𝑒)𝑖𝑠 𝑘𝑛𝑜𝑤𝑛,

Where, 𝑓(𝑥, 𝑦) is some function of the variables x, and y that are involved in the problem.

Examples of Initial Value Problems

𝑑𝑦 𝑦
(𝑎) =6−2
𝑑𝑥 𝑥

𝑦(3) = 1

𝑑𝑦 𝑦𝐼𝑛𝑦
(𝑏) =
𝑑𝑥 𝑥

𝑦(2) = 𝑒

𝑑𝑦 50𝑥 2 − 10𝑦
(𝑐) =
𝑑𝑥 3

𝑦(0) = 0

Note that the right-hand side is a function of and in each case.

Let's now see how to solve such problems using a numerical approach.
Euler's Method

Euler's Method assumes our solution is written in the form of a Taylor's Series.

That is, we'll have a function of the form:

ℎ2 𝑦 ,, (𝑥) ℎ3 𝑦 ,,, (𝑥) ℎ4 𝑦 𝑖𝑣 (𝑥)


𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑦 ′ (𝑥) + + + + ⋯ … … ..
2! 3! 4!

This gives us a reasonably good approximation if we take plenty of terms, and if the value of is
reasonably small.

For Euler's Method, we just take the first 2 terms only.

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑦 ′ (𝑥)

𝑑𝑦
The last term is just ‘h’ times our 𝑑𝑥 expression, so we can write Euler's Method as follows:

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

How do we use this formula?

We start with some known value for y , which we could call y0 . It has this value when x = x0. (We
make use of the initial value (x0 , y0) .)

The result of using this formula is the value for y , one h step to the right of the current value. Let's call
it y1. So, we have:

𝑦1 ≈ 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 )

where

𝑦1 is the next estimated solution value;

𝑦0 is the current value;

ℎ is the interval between steps; and

𝑓(𝑥0 , 𝑦0 ) is the value of the derivative at the starting point (𝑥0 , 𝑦0 ).

Next value: To get the next value 𝑦2 , we would use the value we just found for 𝑦1 as follows:

𝑦2 ≈ 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )

Where
𝑦2 is the next estimated solution value;

𝑦1 is the current value;

ℎ is the interval between steps;

𝑥1 = 𝑥0 + ℎ; 𝑎𝑛𝑑

𝑓(𝑥1 , 𝑦1 ) is the value of the derivative at the current (𝑥1 , 𝑦1 ) point.

We continue this process for as many steps as required.

What's going on?

The right-hand side of the formula above means, "start at the known value, then move one step ‘h’ units
𝑑𝑦
to the right in the direction of the slope at that point, which is 𝑑𝑥 = 𝑓(𝑥, 𝑦). We will arrive at a good
approximation to the curve's y-value at that new point."

We'll do this for each of the sub-points, apart, from some starting value 𝑥 = 𝑎 to some finishing value,
𝑥 = 𝑏, as shown in the graph below.
Example: Euler's Method

Let's solve example (b) from above. We had the initial value problem:

𝑑𝑦 𝑦 𝐼𝑛 𝑦
=
𝑑𝑥 𝑥

𝑦(2) = 𝑒

Step 1

We'll start at the point (𝑥0 , 𝑦0 ) = (2, 𝑒) and use step size of ℎ = 0.1 and proceed for 10 steps. That is,
we'll approximate the solution from t =2 to t = 3 for our differential equation. We'll finish with a set of
points that represent the solution, numerically.

We already know the first value, when 𝑥0 = 2, which is 𝑦0 = 𝑒 (the initial value).

We now calculate the value of the derivative at this initial point. (This tells us the direction to move.)

𝑑𝑦 𝑒 𝐼𝑛 𝑒 𝑒
= 𝑓(2, 𝑒) = = ≡ 1.3591409
𝑑𝑥 2 2

This means the slope of the line from t =2 to t =2.1 is approximately 1.3591409.

Step 2

Now, for the second step, (since ℎ = 0.1 , the next point is 𝑥 + ℎ = 2 + 0.1 = 2.1 ), we substitute what
we know into Euler's Method formula, and we have:

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

𝑒
𝑦1 = 𝑦(2.1) ≈ 𝑒 + 0.1 ( ) = 2.8541959
2

This means the approximate value of the solution when x = 2.1 is 2.8540959.

Let's see what we've done on a graph.


We'll need the new slope at this point, so we'll know where to head next.

𝑑𝑦 2.8541959 𝐼𝑛 2.8541959
= 𝑓(2.1, 2.8541959) = = 1.4254536
𝑑𝑥 2.1

This means the slope of the approximation line from 𝑥 = 2.1 to 𝑥 = 2.2 is 1.42. So, it's a little bit
steeper than the first slope we found.

Step 3

Now we are trying to find the solution value when 𝑥 = 2.2 . We substitute our known values:

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

𝑦(2.2) ≈ 2.8540959 + 0.1(1.4254536) = 2.99664126

With this new value, our graph is now:


We'll need the new slope at this point, so we'll know where to head next.

2.99664126 𝐼𝑛 2.99664126
𝑓(2.2, 2.99664126) = = 1.49490457
2.2

This means the slope of the approximation line from 𝑥 = 2.2 to 𝑥 = 2.3 is 1.49490456. So, it's a little
steeper than the first 2 slopes we found.

Step 4

Now we are trying to find the solution value when 𝑥 = 2.3. We substitute our known values:

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

𝑦(2.3) ≈ 2.99664126 + 0.1(1.49490456) = 3.1461317

With this new value, our graph is now:

Subsequent Steps

We present all the values up to x = 3 in the following table.

Of course, most of the time we'll use computers to find these approximations. I used a spreadsheet to
obtain the following values. Don't use your calculator for these problems - it's very tedious and prone
to error. You could use an online calculator or google search.
𝑑𝑦
(There's no final 𝑑𝑥 value because we don't need it. We've found all the required y values.)

Here is the graph of our estimated solution values from to x = 2 to x = 3.


How good is it?

This question actually is easy to solve algebraically, and we did it back in the Separation of Variables
section. (It was Example 7.)

Our solution was 𝑦 = 𝑒 𝑥⁄2. In the next graph, we see the estimated values we got using Euler's Method
(the dark-coloured curve) and the graph of the real solution 𝑦 = 𝑒 𝑥⁄2 in magenta (pinkish). We can see
they are very close.

In this case, the solution graph is only slightly curved, so it's "easy" for Euler's Method to produce a
fairly close result.

In fact, at x = 3 the actual solution is y = 4.4816890703, and we obtained the approximation y =


4.4180722576, so the error is only:

4.4816890703 − 4.4180722576
= 1.42%
4.4816890703

Exercise

The following question cannot be solved using the algebraic techniques we learned earlier in this chapter,
so the only way to solve it is numerically.

Solve using Euler's Method:

𝑑𝑦
= sin(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥
𝑦(0) = 4

𝑢𝑠𝑒 ℎ = 0.1

Answer

Step 1

We start at the initial value (0,4) and calculate the value of the derivative at this point. We have:

𝑑𝑦
= 𝑠𝑖𝑛(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥

= sin(0 + 4) − 𝑒 0

= −1.75680249531

We substitute our starting point and the derivative we just found to obtain the next point along.

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

𝑦(0.1) ≈ 4 + 0.1(−1.75680249531)

≈ 3.82431975047

Step 2

Now we need to calculate the value of the derivative at this new point (0.1, 3.82431975047). We have:

𝑑𝑦
= sin(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥

= sin(0.1 + 3.82431975047) − 𝑒 0.1

= −1.8103864498

Once again, we substitute our current point and the derivative we just found to obtain the next point
along.

𝑦(𝑥 + ℎ) ≈ 𝑦(𝑥) + ℎ𝑓(𝑥, 𝑦)

𝑦(0.2) ≈ 3.82431975047 + 0.1(−1.8103864498)

≈ 3.64328110549

We proceed for the required number of steps and obtain these values:
Here's the graph of this solution.

In the next section, we see a more sophisticated numerical solution method for differential equations,
called the Runge- Kutta Method.

You might also like