Euler's Method

In general, the slope-field plot shows a distribution of slopes for the differential equation [Maple Math] where [Maple Math] is the right-hand side of the differential equation. At each point ( [Maple Math] , [Maple Math] ) a short line segment is drawn, with slope [Maple Math] given by the right-hand side.

For example, in the differential equation [Maple Math] of the previous section, the independent variable [Maple Math] is [Maple Math] , [Maple Math] and [Maple Math] . The particular solution found there is seen to be the curve that passes through the initial point (1790, 3.929) that 'follows' the slope field.

This suggests a simple way to approximate the desired particular solution of [Maple Math] numerically. Because the differential equation determines the slope at each point ( [Maple Math] , [Maple Math] ) of the curve, we can approximate a nearby point ( [Maple Math] , [Maple Math] ) on the curve by following its tangent line. Denoting by [Maple Math] [Maple Math] the increment in [Maple Math] we then have

[Maple Math]

[Maple Math]

Returning to the differential equation [Maple Math] , or [Maple Math] , we have [Maple Math] [Maple Math] [Maple Math] [Maple Math] [Maple Math] [Maple Math] ( [Maple Math] ). Taking [Maple Math] [Maple Math] = 0.1, for example, and starting at the initial point (1790, 3.929), we can generate the sequence of approximations


[Maple Math] [Maple Math]
----------------------------------------------------
1790 3.929
1790.1 3.941
1790.2 3.952
1790.3 3.964
1790.4 3.976
1790.5 3.987
1790.6 3.999
1790.7 4.011
1790.8 4.023
1790.9 4.035
1791 4.046

Compare these values with the last plot of the previous section. The simplicity of the idea is deceiving. The method (called Euler's Method ) and its numerical cousins, turns out to be one of the most useful and powerful techniques for exploring solutions of differential equations when exact solutions are too difficult or impossible to obtain. The fact that it looks tedious to generate the points is irrelevant. All we need to do is to call in our CAS reinforcements.

Below is the Maple code that was used to calculate the values in the table above. The procedure is to define a Maple function Euler that implements one step of Euler's method, and we then iterate this function. This generates the desired list of points on an approximate solution curve.

> K:=.0295;
f:=y->K*y;
P0:=[1790,3.929];
deltax:=0.1;
Euler:=P->[P[1]+deltax,P[2]+deltax*f(P[2])];

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> Euler(P0);
Euler(%);
Euler(%);
Euler(%);
Euler(%);
Euler(%);
Euler(%);
Euler(%);
Euler(%);
Euler(%);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Or we can use the repeated-composition operator @@ to obtain the final result with one statement.

> (Euler@@10)(P0);

[Maple Math]

Note that in defining the function Euler we gave it a point P = ( [Maple Math] , [Maple Math] ) as its independent variable. In Maple we represent a point as a list of two numbers, thus [Maple Math] = P[1] and [Maple Math] = P[2]. This explains the strange notation in the definition of the function Euler.

The final touch is to generate the whole list of points by calling upon the function iterate , that you must activate first, to apply Euler successively 10 times, starting with the initial point P0. In fact, let's apply Euler 100 times to see what the approximate population was in 1800.

> # This execution cell defines a useful function that enables
# us to iterate a function f a given number of times with a
# given starting value. It generates a list
# [a, f(a), f(f(a)), f(f(f(a))), ...] (with n+1 terms)

iterate:=proc(f,a,n)
local term,result,i;
term:=a;
result:=a;
for i from 1 to n do
term:=f(term);
result:=result,term;
od;
RETURN([result]);
end:

> solnEuler:=iterate(Euler,P0,100);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

This is a list of points on the approximate solution curve from 1790 to 1800. The approximation 5.275 million in 1800 compares favorably with the official number of 5.297 million people recorded in the census data. From this list we can generate either a table of values of the approximate solution or a plot of the approximate solution:

> with(math3):
plot(solnEuler,style=point);
plot(solnEuler);
printtable(solnEuler,"Numerical solution of P'=0.0295*P",["t","P"]);

[Maple Plot]

[Maple Plot]

                            Numerical solution of P'=0.0295*P

 

                                 t                     P

                              -----------------------------

                         1790.000000               3.929000

                         1790.100000               3.940591

                         1790.200000               3.952215

                         1790.300000               3.963874

                         1790.400000               3.975568

                         1790.500000               3.987296

                         1790.600000               3.999058

                         1790.700000               4.010855

                         1790.800000               4.022687

                         1790.900000               4.034554

                         1791.000000               4.046456

                         1791.100000               4.058393

                         1791.200000               4.070366

                         1791.300000               4.082373

                         1791.400000               4.094416

                         1791.500000               4.106495

                         1791.600000               4.118609

                         1791.700000               4.130759

                         1791.800000               4.142945

                         1791.900000               4.155166

                         1792.000000               4.167424

                         1792.100000               4.179718

                         1792.200000               4.192048

                         1792.300000               4.204415

                         1792.400000               4.216818

                         1792.500000               4.229257

                         1792.600000               4.241734

                         1792.700000               4.254247

                         1792.800000               4.266797

                         1792.900000               4.279384

                         1793.000000               4.292008

                         1793.100000               4.304669

                         1793.200000               4.317368

                         1793.300000               4.330104

                         1793.400000               4.342878

                         1793.500000               4.355690

                         1793.600000               4.368539

                         1793.700000               4.381426

                         1793.800000               4.394351

                         1793.900000               4.407315

                         1794.000000               4.420316

                         1794.100000               4.433356

                         1794.200000               4.446435

                         1794.300000               4.459552

                         1794.400000               4.472707

                         1794.500000               4.485902

                         1794.600000               4.499135

                         1794.700000               4.512408

                         1794.800000               4.525719

                         1794.900000               4.539070

                         1795.000000               4.552460

                         1795.100000               4.565890

                         1795.200000               4.579359

                         1795.300000               4.592869

                         1795.400000               4.606417

                         1795.500000               4.620006

                         1795.600000               4.633635

                         1795.700000               4.647305

                         1795.800000               4.661014

                         1795.900000               4.674764

                         1796.000000               4.688555

                         1796.100000               4.702386

                         1796.200000               4.716258

                         1796.300000               4.730171

                         1796.400000               4.744125

                         1796.500000               4.758120

                         1796.600000               4.772157

                         1796.700000               4.786234

                         1796.800000               4.800354

                         1796.900000               4.814515

                         1797.000000               4.828718

                         1797.100000               4.842962

                         1797.200000               4.857249

                         1797.300000               4.871578

                         1797.400000               4.885949

                         1797.500000               4.900363

                         1797.600000               4.914819

                         1797.700000               4.929318

                         1797.800000               4.943859

                         1797.900000               4.958443

                         1798.000000               4.973071

                         1798.100000               4.987741

                         1798.200000               5.002455

                         1798.300000               5.017212

                         1798.400000               5.032013

                         1798.500000               5.046858

                         1798.600000               5.061746

                         1798.700000               5.076678

                         1798.800000               5.091654

                         1798.900000               5.106675

                         1799.000000               5.121739

                         1799.100000               5.136848

                         1799.200000               5.152002

                         1799.300000               5.167201

                         1799.400000               5.182444

                         1799.500000               5.197732

                         1799.600000               5.213065

                         1799.700000               5.228444

                         1799.800000               5.243868

                         1799.900000               5.259337

                         1800.000000               5.274852

 

Let's see how close the Euler approximation comes to the recorded population of 23.261 million in 1850. We will suppress the printing of all but the last value.

> solnEuler:=iterate(Euler,P0,600):
solnEuler[nops(solnEuler)];

[Maple Math]

Not bad. The error is less than 1.1%.

The Euler Code for Copying and Pasting: What you need to use the Euler Method

Go back