Вы находитесь на странице: 1из 34

In mathematics and computational science, the Euler method (also called forward

Euler method) is a first-order numerical procedure for solving ordinary differential


equations (ODEs) with a given initial value. It is the most basic explicit
method for numerical integration of ordinary differential equations and is the
simplest Runge–Kutta method. The Euler method is named after Leonhard Euler, who
treated it in his book Institutionum calculi integralis (published 1768–1870).[1]
The Euler method is a first-order method, which means that the local error (error per
step) is proportional to the square of the step size, and the global error (error at a given
time) is proportional to the step size. The Euler method often serves as the basis to
construct more complex methods, e.g., predictor–corrector method.

Contents

 1Informal geometrical description


 2Example
o 2.1Using step size equal to 1 (h = 1)
o 2.2MATLAB code example
o 2.3R code example
o 2.4Using other step sizes
 3Derivation
 4Local truncation error
 5Global truncation error
 6Numerical stability
 7Rounding errors
 8Modifications and extensions
 9In popular culture
 10See also
 11Notes
 12References
 13External links

Informal geometrical description[edit]


Consider the problem of calculating the shape of an unknown curve which starts at a
given point and satisfies a given differential equation. Here, a differential equation can
be thought of as a formula by which the slope of the tangent line to the curve can be
computed at any point on the curve, once the position of that point has been calculated.
The idea is that while the curve is initially unknown, its starting point, which we denote
by  is known (see the picture on top right). Then, from the differential equation, the slope
to the curve at  can be computed, and so, the tangent line.
Take a small step along that tangent line up to a point  Along this small step, the slope
does not change too much, so  will be close to the curve. If we pretend that  is still on
the curve, the same reasoning as for the point  above can be used. After several steps,
a polygonal curve  is computed. In general, this curve does not diverge too far from the
original unknown curve, and the error between the two curves can be made small if the
step size is small enough and the interval of computation is finite:[2]
Choose a value  for the size of every step and set . Now,
one step of the Euler method from  to  is:[3]
The value of  is an approximation of the solution to the
ODE at time : . The Euler method is explicit, i.e. the
solution  is an explicit function of  for .
While the Euler method integrates a first-order ODE,
any ODE of order N can be represented as a system of
first-order ODEs: to treat the equation
,
we introduce auxiliary variables  and obtain the
equivalent equation:
This is a first-order system in the variable  and
can be handled by Euler's method or, in fact, by
any other scheme for first-order systems.[4]

Example[edit]
Given the initial value problem
we would like to use the Euler method to
approximate .[5]
Using step size equal to 1 (h = 1)
[edit]
Illustration of numerical integration for the
equation  Blue is the Euler method; green,
the midpoint method; red, the exact solution,  The
step size is h = 1.0 .

The Euler method is


so first we must compute . In this simple
differential equation, the function  is
defined by . We have
By doing the above step, we have
found the slope of the line that is
tangent to the solution curve at the
point . Recall that the slope is defined
as the change in  divided by the
change in , or .
The next step is to multiply the above
value by the step size , which we take
equal to one here:
Since the step size is the change
in , when we multiply the step size
and the slope of the tangent, we
get a change in  value. This value
is then added to the initial  value
to obtain the next value to be
used for computations.
The above steps should be
repeated to find ,  and .
Due to the repetitive
nature of this algorithm, it
can be helpful to organize
computations in a chart
form, as seen below, to
avoid making errors.

0 1 0 1 1 1 2

1 2 1 2 1 2 4

2 4 2 4 1 4 8
3 8 3 8 1 8 16

The conclusion of this


computation is that .
The exact solution of
the differential equation
is , so . Although the
approximation of the
Euler method was not
very precise in this
specific case,
particularly due to a
large value step size ,
its behaviour is
qualitatively correct as
the figure shows.
MATLAB code
example[edit]
clear; clc;
close('all');
y0 = 1;
t0 = 0;
h = 1; % try: h =
0.01
tn = 4; % equal to:
t0 + h*n, with n the
number of steps
[t, y] = Euler(t0,
y0, h, tn);
plot(t, y, 'b');

% exact solution
(y = e^t):
tt =
(t0:0.001:tn);
yy = exp(tt);
hold('on');
plot(tt, yy,
'r');
hold('off');
legend('Euler',
'Exact');

function [t, y] =
Euler(t0, y0, h, tn)
fprintf('%10s
%10s%10s%15s\n',
'i', 'yi', 'ti',
'f(yi,ti)');
fprintf('%10d%
+10.2f%+10.2f%
+15.2f\n', 0, y0,
t0, f(y0,t0));
t = (t0:h:tn)';
y =
zeros(size(t));
y(1) = y0;
for i =
1:1:length(t)-1
y(i+1) =
y(i) +
h*f(y(i),t(i));

fprintf('%10d%+10.2f
%+10.2f%+15.2f\n',
i, y(i+1), t(i+1),
f(y(i+1),t(i+1)));
end
end

% in this case,
f(y,t) = f(y)
function dydt =
f(y,t)
dydt = y;
end

% OUTPUT:
% i
yi ti
f(yi,ti)
% 0
+1.00 +0.00
+1.00
% 1
+2.00 +1.00
+2.00
% 2
+4.00 +2.00
+4.00
% 3
+8.00 +3.00
+8.00
% 4
+16.00 +4.00
+16.00
% NOTE: Code also
outputs a comparison
plot
R code
example[edit]

Graphical output of the R


programming language
code for the posed
example

Below is the code of


the example in the R
programming
language.

# ============
# SOLUTION to
# y' = y, where
y' = f(t,y)
# then:
f <- function(ti,y)
y

# INITIAL VALUES:
t0 <- 0
y0 <- 1
h <- 1
tn <- 4

# Euler's method:
function definition
Euler <-
function(t0, y0, h,
tn, dy.dt) {
# dy.dt:
derivative function

# t sequence:
tt <- seq(t0, tn,
by=h)
# table with as
many rows as tt
elements:
tbl <-
data.frame(ti=tt)
tbl$yi <- y0 #
Initializes yi with
y0
tbl$Dy.dt[1] <-
dy.dt(tbl$ti[1],y0)
# derivative
for (i in
2:nrow(tbl)) {
tbl$yi[i] <-
tbl$yi[i-1] +
h*tbl$Dy.dt[i-1]
# For next
iteration:
tbl$Dy.dt[i] <-
dy.dt(tbl$ti[i],tbl$
yi[i])
}
return(tbl)
}

# Euler's method:
function application
r <- Euler(t0, y0,
h, tn, f)
rownames(r) <- 0:
(nrow(r)-1) # to
coincide with index
n

# Exact solution for


this case: y =
exp(t)
# added as an
additional column to
r
r$y <- exp(r$ti)

# TABLE with
results:
print(r)

plot(r$ti, r$y,
type="l", col="red",
lwd=2)
lines(r$ti, r$yi,
col="blue", lwd=2)
grid(col="black")
legend("top",
legend = c("Exact",
"Euler"), lwd=2,
col = c("red",
"blue"))

# OUTPUT:
#
# ti yi Dy.dt
y
# 0 0 1 1
1.000000
# 1 1 2 2
2.718282
# 2 2 4 4
7.389056
# 3 3 8 8
20.085537
# 4 4 16 16
54.598150
# NOTE: Code also
outputs a comparison
plot

Using other step


sizes[edit]

The same illustration


for h = 0.25.

As suggested in the
introduction, the Euler
method is more
accurate if the step
size  is smaller. The
table below shows the
result with different
step sizes. The top row
corresponds to the
example in the
previous section, and
the second row is
illustrated in the figure.

step
result of Euler's method error
size

1 16.00 38.60

0.25 35.53 19.07

0.1 45.26 9.34

0.05 49.56 5.04

0.025 51.98 2.62

0.0125 53.26 1.34

The error recorded


in the last column
of the table is the
difference between
the exact solution
at  and the Euler
approximation. In
the bottom of the
table, the step size
is half the step size
in the previous row,
and the error is
also approximately
half the error in the
previous row. This
suggests that the
error is roughly
proportional to the
step size, at least
for fairly small
values of the step
size. This is true in
general, also for
other equations;
see the
section Global
truncation error for
more details.
Other methods,
such as
the midpoint
method also
illustrated in the
figures, behave
more favourably:
the global error of
the midpoint
method is roughly
proportional to
the square of the
step size. For this
reason, the Euler
method is said to
be a first-order
method, while the
midpoint method is
second order.
We can extrapolate
from the above
table that the step
size needed to get
an answer that is
correct to three
decimal places is
approximately
0.00001, meaning
that we need
400,000 steps. This
large number of
steps entails a high
computational cost.
For this reason,
people usually
employ alternative,
higher-order
methods such
as Runge–Kutta
methods or linear
multistep methods,
especially if a high
accuracy is
desired.[6]

Derivation[edi
t]
The Euler method
can be derived in a
number of ways.
Firstly, there is the
geometrical
description above.
Another possibility
is to consider
the Taylor
expansion of the
function  around :
The differential
equation states
that . If this is
substituted in
the Taylor
expansion and
the quadratic
and higher-
order terms are
ignored, the
Euler method
arises.[7] The
Taylor
expansion is
used below to
analyze the
error committed
by the Euler
method, and it
can be
extended to
produce Runge
–Kutta
methods.
A closely
related
derivation is to
substitute the
forward finite
difference form
ula for the
derivative,
in the
differential
equation .
Again, this
yields the
Euler
method.[8] A
similar
computation
leads to
the midpoint
method and
the backwar
d Euler
method.
Finally, one
can
integrate the
differential
equation
from 
 to  and
apply
the fundame
ntal theorem
of
calculus to
get:
Now
approxi
mate the
integral
by the
left-hand 
rectangl
e
method (
with only
one
rectangl
e):
Com
binin
g
both
equa
tions,
one
finds
agai
n the
Euler
meth
od.[9] 
This
line
of
thou
ght
can
be
conti
nued
to
arriv
e at
vario
us lin
ear
multi
step
meth
ods.

Loc
al
tru
nca
tio
n
err
or[e
dit]
The l
ocal
trunc
ation
error 
of
the
Euler
meth
od is
the
error
mad
e in
a
singl
e
step.
It is
the
differ
ence
betw
een
the
num
erical
soluti
on
after
one
step, 
, and
the
exact
soluti
on at
time 
. The
num
erical
soluti
on is
given
by
F
o
r
t
h
e
e
x
a
ct
s
ol
u
ti
o
n
,
w
e
u
s
e
t
h
e
T
a
yl
o
r
e
x
p
a
n
si
o
n
m
e
n
ti
o
n
e
d
in
t
h
e
s
e
ct
io

D
e
ri
v
a
ti
o

a
b
o
v
e
:
T
h
e
lo
c
al
tr
u
n
c
at
io
n
er
ro
r
(L
T
E
)
in
tr
o
d
u
c
e
d
b
y
th
e
E
ul
er
m
et
h
o
d
is
gi
v
e
n
b
y
th
e
di
ff
er
e
n
c
e
b
et
w
e
e
n
th
e
s
e
e
q
u
at
io
n
s:
This
result
is
valid
if 
 has
a
boun
ded
third
deriv
ative.
[10]

This
show
s that
for
small 
, the
local
trunc
ation
error
is
appro
ximat
ely
propo
rtiona
l to .
This
make
s the
Euler
meth
od
less
accur
ate
(for
small 
) than
other
highe
r-
order
techn
iques
such
as R
unge-
Kutta
meth
ods a
nd lin
ear
multi
step
meth
ods,
for
which
the
local
trunc
ation
error
is
propo
rtiona
l to a
highe
r
powe
r of
the
step
size.
A
slightl
y
differ
ent
formu
lation
for
the
local
trunc
ation
error
can
be
obtai
ned
by
using
the
Lagra
nge
form
for
the
remai
nder
term
in Ta
ylor's
theor
em.
If 
 has
a
conti
nuou
s
seco
nd
deriv
ative,
then
there
exists

 such
that
[11]
In the
above
expressi
ons for
the error,
the
second
derivativ
e of the
unknown
exact
solution 
 can be
replaced
by an
expressi
on
involving
the right-
hand
side of
the
differenti
al
equation.
Indeed, it
follows
from the
equation 
 that
[12]

Global
truncati
on
error[edit]
The global
truncation
error is the
error at a
fixed time ,
after
however
many steps
the methods
needs to
take to reach
that time
from the
initial time.
The global
truncation
error is the
cumulative
effect of the
local
truncation
errors
committed in
each step.
[13]
 The
number of
steps is
easily
determined
to be , which
is
proportional
to , and the
error
committed in
each step is
proportional
to  (see the
previous
section).
Thus, it is to
be expected
that the
global
truncation
error will be
proportional
to .[14]
This intuitive
reasoning
can be made
precise. If
the
solution  has
a bounded
second
derivative
and 
 is Lipschitz
continuous i
n its second
argument,
then the
global
truncation
error (GTE)
is bounded
by
where  is an
upper bound o
the second
derivative of  o
the given
interval and  is
the Lipschitz
constant of .[15]
The precise
form of this
bound is of litt
practical
importance, as
in most cases
the bound vas
overestimates
the actual erro
committed by
the Euler
method.[16] Wha
is important is
that it shows
that the global
truncation erro
is
(approximately
proportional to
For this reaso
the Euler
method is said
to be first orde
[17]
Numerica
stability[e
]

Solution of  comp
with the Euler me
with step size  (blu
squares) and  (red
circles). The black
shows the exact
solution.

The Euler
method can al
be
numerically un
able, especial
for stiff
equations,
meaning that
the numerical
solution grows
very large for
equations whe
the exact
solution does
not. This can b
illustrated usin
the linear
equation
The exact solu
is , which deca
zero as . How
if the Euler me
is applied to th
equation with
size , then the
numerical solu
is qualitatively
wrong: It oscil
and grows (se
figure). This is
it means to be
unstable. If a
smaller step s
used, for insta
then the nume
solution does
to zero.

The pink disk sho


stability region for
method.

If the Euler me
is applied to th
linear equation
then the nume
solution is uns
if the product  
outside the reg
illustrated on t
This region is
(linear) stabilit
[18]
 In the exam
−2.3, so if  the
is outside the
region, and th
numerical solu
unstable.
This limitation
with its slow
convergence o
with h— mean
Euler method
often used, ex
simple examp
numerical inte

Rounding
errors[edit]
The discussio
now has ignor
consequences
of rounding er
step n of the E
method, the ro
error is roughl
magnitude εyn
is the machine
Assuming that
rounding error
of approximate
same size, the
combined roun
error in N step
roughly Nεy0 if
points in the s
direction. Sinc
number of ste
inversely prop
to the step siz
total rounding
proportional to
reality, howev
extremely unli
all rounding er
in the same di
instead it is as
that the round
are independe
random variab
the expected t
rounding error
proportional to
Thus, for extre
small values o
size, the trunc
error will be sm
the effect of ro
error may be b
of the effect of
error can be e
avoided if com
summation is
the formula fo
Euler method.

Modificat
and
extension
A simple modi
the Euler meth
eliminates the
problems note
previous secti
the backward
method:
This differs fro
(standard, or f
Euler method
function  is ev
end point of th
instead of the
point. The bac
method is an i
method, mean
formula for the
Euler method
sides, so when
the backward
we have to so
equation. This
implementatio
costly.
Other modifica
Euler method
stability yield
the exponentia
method or the
Euler method.
More complica
can achieve a
(and more acc
possibility is to
function evalu
is illustrated b
the midpoint m
is already men
article:
.
This leads to t
of Runge–Kut
The other pos
more past valu
by the two-ste
Bashforth met
This leads to t
multistep meth
other modifica
techniques fro
sensing to min
usage[21]

In popula
In the film Hid
Figures, Kathe
to the Euler m
the re-entry of
Glenn from Ea

See also[e
 Crank–Nic
 Gradient d
finite steps
of function
 List of Run
 Linear mul
 Numerical
calculating
 Numerical
differential
Notes[edit]
1. ^ Butcher 200
Wanner 1993
2. ^ Atkinson 19
p. 60
3. ^ Butcher 200
Wanner 1993
4. ^ Butcher 200
Wanner 1993
5. ^ See also At
6. ^ Hairer, Nør
7. ^ Atkinson 19
Wanner 1993
8. ^ Atkinson 19
9. ^ Atkinson 19
10. ^ Butcher 200
11. ^ Atkinson 19
12. ^ Stoer & Bul
13. ^ Atkinson 19
14. ^ Butcher 200
15. ^ Atkinson 19
equation (1.1
16. ^ Iserles 1996
17. ^ Butcher 200
18. ^ Butcher 200
19. ^ Butcher 200
20. ^ Butcher 200
21. ^ Unni, M. P.
(March 2017)
numerical sol
using compre
13th Internati
Processing Its
84. doi:10.11
N  978-1-5090
22. ^ Khan, Amin
mathematicia
into space".  L
Retrieved  12

Reference
 Atkinson, K
(1989). An
Numerical
New York:
Sons. ISBN
0.
 Ascher, Ur
R. (1998). 
for Ordinar
Equations
Algebraic E
Philadelph
Industrial a
Mathemati
89871-412
 Butcher, Jo
C. (2003). 
for Ordinar
Equations.
Wiley & So
471-96758
 Hairer, Ern
Paul; Wan
(1993). So
differential
problems.
York: Sprin
78-3-540-5
 Iserles, Ari
Course in t
Analysis of
Equations.
University
521-55655
 Stoer, Jose
(2002). Int
Numerical
Berlin, New
Verlag. ISB
95452-3.
 Lakoba, Ta
(2012), Sim
and its
modificatio
notes for M
University
retrieved 2
 Unni, M P.
reduction f
solution of
equations
sensing". 2
Internation
Signal Pro
Application
CSPA. pp.
84. doi:10.
64928. ISB
1184-1.

External l

  Media re
method at
Commons
 Euler meth
in different
languages
 Hazewinke
(2001) [199
method", E
Mathemati
Science+B
B.V. / Kluw
Publishers
55608-010
hide

Numerical methods for integration

thod
d Euler
plicit Euler
ial Euler
egration
Verlet
dal rule
algorithm
method
ethod
k-beta method
integration

ial integrator
utta methods
unge–Kutta methods
ultistep method
inear methods
d differentiation formula

ic integrator
Categories: 
 Numerical
equations
 Runge–Ku
 First order
 Leonhard E
Navig
ation
menu
 Not
logge
d in
 Talk
 Contri
bution
s
 Creat
e
accou
nt
 Log in
 Article
 Talk
 Re
ad
 Edit
 Vie
w
hist
ory
Search
Search Go

 Main
page
 Conten
ts
 Current
events
 Rando
m
article
 About
Wikipe
dia
 Contact
us
 Donate
Contribute
 Help
 Comm
unity
portal
 Recent
change
s
 Upload
file
Tools
 What
links
here
 Related
change
s
 Special
pages
 Perma
nent
link
 Page
informa
tion
 Wikidat
a item
 Cite
this
page
In other projects
 Wikime
dia
Comm
ons
Print/export
 Downlo
ad as
PDF
 Printabl
e
version
Languages
 Deutsc
h
 Españo
l
 Françai
s
 한국어
 Italiano
 Русски
й
 Tagalo
g
 Tiếng
Việt
 中文
16 more
Edit links
 This page was
2020, at 14:06
 Text is availab
Commons Attr
License; addit
By using this s
the Terms of U
Wikipedia® is
of the Wikimed
non-profit orga

Вам также может понравиться