Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

3.1: Euler’s Method

( \newcommand{\kernel}{\mathrm{null}\,}\)

In this section we will look at the simplest method for solving first order equations, Euler’s Method. While it is not the most efficient method, it does provide us with a picture of how one proceeds and can be improved by introducing better techniques, which are typically covered in a numerical analysis text.

Let’s consider the class of first order initial value problems of the form

dydx=f(x,y),y(x0)=y0

We are interested in finding the solution y(x) of this equation which passes through the initial point (x0,y0) in the xy-plane for values of x in the interval [a,b], where a=x0. We will seek approximations of the solution at N points, labeled xn for n=1,,N. For equally spaced points we have Δx=x1x0=x2x1, etc. We can write these as

xn=x0+nΔx

In Figure 3.1.1 we show three such points on the x-axis.

clipboard_e2163bf35297d6f54490d304935f4942d.png
Figure 3.1.1: The basics of Euler’s Method are shown. An interval of the x axis is broken into N subintervals. The approximations to the solutions are found using the slope of the tangent to the solution, given by f(x,y). Knowing previous approximations at (xn1,yn1), one can determine the next approximation, yn.

The first step of Euler’s Method is to use the initial condition. We represent this as a point on the solution curve, (x0,y(x0))=(x0,y0), as shown in Figure 3.1.1. The next step is to develop a method for obtaining approximations to the solution for the other xns.

We first note that the differential equation gives the slope of the tangent line at (x,y(x)) of the solution curve since the slope is the derivative, y(x) From the differential equation the slope is f(x,y(x)). Referring to Figure 3.1.1, we see the tangent line drawn at (x0,y0). We look now at x=x1. The vertical line x=x1 intersects both the solution curve and the tangent line passing through (x0,y0). This is shown by a heavy dashed line.

While we do not know the solution at x=x1, we can determine the tangent line and find the intersection point that it makes with the vertical. As seen in the figure, this intersection point is in theory close to the point on the solution curve. So, we will designate y1 as the approximation of the solution y(x1). We just need to determine y1.

The idea is simple. We approximate the derivative in the differential equation by its difference quotient:

dydxy1y0x1x0=y1y0Δx

Since the slope of the tangent to the curve at (x0,y0) is y(x0)=f(x0,y0), we can write

y1y0Δxf(x0,y0)

Solving this equation for y1, we obtain

y1=y0+Δxf(x0,y0)

This gives y1 in terms of quantities that we know.

We now proceed to approximate y(x2). Referring to Figure 3.1.1, we see that this can be done by using the slope of the solution curve at (x1,y1). The corresponding tangent line is shown passing though (x1,y1) and we can then get the value of y2 from the intersection of the tangent line with a vertical line, x=x2. Following the previous arguments, we find that

y2=y1+Δxf(x1,y1)

Continuing this procedure for all xn,n=1,N, we arrive at the following scheme for determining a numerical solution to the initial value problem:

y0=y(x0),yn=yn1+Δxf(xn1,yn1),n=1,,N.

This is referred to as Euler’s Method.

Example 3.1.1

Use Euler’s Method to solve the initial value problem dydx=x+y,y(0)=1 and obtain an approximation for y(1).

Solution

First, we will do this by hand. We break up the interval [0,1], since we want the solution at x=1 and the initial value is at x=0. Let Δx=0.50. Then, x0=0,x1=0.5 and x2=1.0. Note that there are N=baΔx=2 subintervals and thus three points.

We next carry out Euler’s Method systematically by setting up a table for the needed values. Such a table is shown in Table 3.1. Note how the table is set up. There is a column for each xn and yn. The first row is the initial condition. We also made use of the function f(x,y) in computing the yn s from Equation 3.1.6. This sometimes makes the computation easier. As a result, we find that the desired approximation is given as y2=2.5.

Table 3.1.1: Application of Euler’s Method for y=x+y,y(0)=1 and Δx=0.5.
n xn yn=yn1+Δxf(xn1,yn1)=0.5xn1+1.5yn1
O o 1
1 0.5 0.5(0)+1.5(1.0)=1.5
2 1.0 0.5(0.5)+1.5(1.5)=2.5

Is this a good result? Well, we could make the spatial increments smaller. Let’s repeat the procedure for Δx=0.2, or N=5. The results are in Table 3.2.

Now we see that the approximation is y1=2.97664. So, it looks like the value is near 3 , but we cannot say much more. Decreasing Δx more shows that we are beginning to converge to a solution. We see this in Table 3.1.3.

Table 3.1.2: Application of Euler’s Method for y=x+y,y(0)=1 and Δx=0.2.
n xn yn=0.2xn1+1.2yn1
o o 1
1 0.2 0.2(0)+1.2(1.0)=1.2
2 0.4 0.2(0.2)+1.2(1.2)=1.48
3 0.6 0.2(0.4)+1.2(1.48)=1.856
4 0.8 0.2(0.6)+1.2(1.856)=2.3472
5 1.0 0.2(0.8)+1.2(2.3472)=2.97664
Table 3.1.3: Results of Euler’s Method for y=x+y,y(0)=1 and varying Δx
Δx yNy(1)
0.5 2.5
0.2 2.97664
0.1 3.187484920
0.01 3.409627659
0.001 3.433847864
0.0001 3.436291854

Of course, these values were not done by hand. The last computation would have taken 1000 lines in the table, or at least 40 pages! One could use a computer to do this. A simple code in Maple would look like the following:

Code 3.1.1

> restart:

> f:=(x,y)->y+x;

> a:=0: b:=1: N:=100: h:=(b-a)/N;

> x[0]:=0: y[0]:=1:

for i from 1 to N do

y[i]:=y[i-1]+h*f(x[i-1],y[i-1]):

x[i]:=x[0]+h*(i):

od:

evalf(y[N]);

clipboard_ed7aa46b00d7f25af81df3393fd18ef1b.png
Figure 3.1.2: A comparison of the results Euler’s Method to the exact solution for y=x+y,y(0)=1 and N=10.

In this case we could simply use the exact solution. The exact solution is

y(x)=2exx1

(The reader can verify this.) So, the value we are seeking is

y(1)=2e2=3.4365636

Adding a few extra lines for plotting, we can visually see how well the approximations compare to the exact solution. The Maple code for doing such a plot is given below.

Code 3.1.2:

> with(plots):

> Data:=[seq([x[i],y[i]],i=0..N)]:

> P1:=pointplot(Data,symbol=DIAMOND):

> Sol:=t->-t-1+2*exp(t);

> P2:=plot(Sol(t),t=a..b,Sol=0..Sol(b)):

> display({P1,P2});

clipboard_e12857745970ef13688195a47dbdb20ed.png
Figure 3.1.3: A comparison of the results Euler’s Method to the exact solution for y=x+y,y(0)=1 and N=100.

We show in Figures 3.23.3 the results for N=10 and N=100. In Figure 3.2 we can see how quickly the numerical solution diverges from the exact solution. In Figure 3.3 we can see that visually the solutions agree, but we note that from Table 3.1.3 that for Δx=0.01, the solution is still off in the second decimal place with a relative error of about o.8%.

Why would we use a numerical method when we have the exact solution? Exact solutions can serve as test cases for our methods. We can make sure our code works before applying them to problems whose solution is not known.

There are many other methods for solving first order equations. One commonly used method is the fourth order Runge-Kutta method. This method has smaller errors at each step as compared to Euler’s Method. It is well suited for programming and comes built-in in many packages like Maple and MATLAB. Typically, it is set up to handle systems of first order equations.

In fact, it is well known that nth order equations can be written as a system of n first order equations. Consider the simple second order equation

y=f(x,y)

This is a larger class of equations than the second order constant coefficient equation. We can turn this into a system of two first order differential equations by letting u=y and v=y=u. Then, v=y=f(x,u). So, we have the first order system

u=vv=f(x,u)

We will not go further into higher order methods until later in the chapter. We will discuss in depth higher order Taylor methods in Section 3.3 and Runge-Kutta Methods in Section 3.4. This will be followed by applications of numerical solutions of differential equations leading to interesting behaviors in Section 3.5. However, we will first discuss the numerical solution using built-in routines.


This page titled 3.1: Euler’s Method is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Russell Herman via source content that was edited to the style and standards of the LibreTexts platform.

  • Was this article helpful?

Support Center

How can we help?