You are on page 1of 9

Numerical Solutions of

Differential Equations
Eulers Method
Differential Equations
A differential equation is a relation between the independent variable (x), the
dependent variable (y) and its derivatives (y,y,y,y
(4)
,). Some of these
variables might be missing from the equation. Many situations in not only
mathematics, but physics, engineering, biology, chemistry, economics as well as
many other disciplines can be described using differential equations. Here are
some examples:
0
2
2
= + u
u
l
g
dt
d
Harmonic Oscillator
g
dt
s d
=
2
2
Free Falling Body
) (
m
T T k
dt
dT
=
Newtons Law of
Cooling
( )
2
2
2
1
dx
dy
k
dx
y d
+ =
Shape of a
hanging string
kP
dt
dP
=
Population Growth
) ( bP a P
dt
dP
=
Population Growth
(limited resources)
kxy
dt
dx
= Spread of Disease
Predator-Prey
)
`

+ =
=
) (
) (
y x
x y
dt
dx
dt
dy
o
| o
Given equations like these we would like to solve them.
There are many known methods to solve differential equations using non-
numerical techniques (i.e. by hand). Most of these involve integration methods. As
we have previously mentioned it is not always possible to find a closed form
antiderivative for a given function made up of functions we commonly use.
To the right is an example of an explicit solution of a
separable (Newtons Law of Cooling) differential equation
by non-numerical methods.
Notice the c
0
term that appears in the solution. This come
from not knowing the constant (+C) when you integrate.
If we knew a certain value for the function say T(1)=95,
for example, we could find the value for c
0
and thus have
everything we need to solve the differential equation.
This specific piece of information is sometime called a
boundary condition for the differential equation. This
will become an important part of generating a numerical
solution for a differential equation.
Since some antiderivatives do not have a closed form
made up of common function neither will the solutions to
some differential equations.
) (
m
T T k
dt
dT
=
dt k dT
T T
m
=

1
} }
=

dt k dT
m
T T
1
( ) C kt T T
m
+ = ln
C kt T T
e e
m
+
=
) ln(
kt
m
e c T T
0
=
kt
m
e c T T
0
+ =
First Order Degree 1 Differential Equations
The study of differential equation is a subject of its own. The way they are
normally studied is much like solving algebraic equations, look to see if the
differential equation fits a certain pattern and then apply a certain technique to it.
The methods we will focus on here will all have the same initial problem. We will
be given a differential equation with the derivative a function of the dependent and
independent variable and an initial condition.
0 0
) ( ) , ( y x y and y x f
dx
dy
= =
The solution which we call a function y(x) to
such an equation can be pictured
graphically. The point (x
0
,y
0
) must be on the
graph. The function y(x) would also satisfy
the differential equation if you plugged y(x) in
for y. y
0
x
0
(x
0
,y
0
)

y(x)

)) ( , ( ) ( '
) , (
x y x f x y
y x f
dx
dy
=
=
Solutions to Equations
The solution to a differential equation (unlike an algebraic equation) is a function.
The problem with this is there are many ways to describe functions. Some can
be described in terms of some equation relating the dependent and independent
variable, some by a graph and some by a very complicated rule.
The way we will solve a differential equation is to use the definition of a
function. That is to say if we are given a differential equation y(x) = f(x,y) with a
boundary condition y(x
0
) = y
0
and another value of x, say x
act
we can find a
number y
act
so that y(x
act
) = y
act
.
y
0
x
0
(x
0
,y
0
)

y(x)

(x
act
,y
act
)

y
act
x
act
The problem that exists is that y
n
can not
be exactly computed only estimated.
There are several different ways in which
to estimate the value for y
n
. We will study
a couple of them in this section.
The point (x
0
,y
0
) is called the initial point
and the point (x
act
,y
act
) is called the
terminal point.
Eulers Method
The method that Euler used to estimate a solution (i.e. the corresponding value of y
for a given value of x) of a differential equation was to follow the tangent line from
the initial point to the terminal point.
y
0
x
0
(x
0
,y
0
)

y(x)

(x
act
,y
act
)

y
act
x
act
y
n
Here we use the value y
n
to estimate the
value of y
act
. This can be directly computed
from the information given by the following
equation.
) )( , (
) )( , (
0 0 0 0
0 0 0 0
x x y x f y y
x x y x f y y
act n
act n
+ =
=
The insight that Euler had was to see how this estimate could be improved on.
The strategy he used was to divide the interval [x
0
,x
act
] (or [x
act
,x
0
] in the case
x
act
<x
0
) into equal subintervals and recompute the tangent line as you go. This
would not allow the tangent line to drift far from the function itself. This would
hopefully produce a more accurate estimate for y
act
at the end.
(x
4
,y
4
)
(x
3
,y
3
)
(x
2
,y
2
)
(x
1
,y
1
)
x
0
(x
0
,y
0
)

(x
act
,y
act
)

x
4
x
1
x
2
x
3
To Apply Eulers Method
1. Divide the interval n equal subintervals. (In
our example 4.)
2. Compute the width of each subinterval
which is Ax=h=(x
n
-x
0
)/n.
3. Compute the sequence of points as
follows:
Ax
y
0

A + =
A + =
=
x y x f y y
x x x
y x
) , (
) , (
0 0 0 1
0 1
1 1

A + =
A + =
=
x y x f y y
x x x
y x
) , (
) , (
1 1 1 2
1 2
2 2

A + =
A + =
=
x y x f y y
x x x
y x
) , (
) , (
2 2 2 3
2 3
3 3

A + =
A + =
=
x y x f y y
x x x
y x
) , (
) , (
3 3 3 4
3 4
4 4
In general the coordinates of the
point (x
n+1
,y
n+1
) can be computed
from the coordinates of the point
(x
n
,y
n
) as follows:

A + =
A + =
=
+
+
+ +
x y x f y y
x x x
y x
n n n n
n n
n n
) , (
) , (
1
1
1 1
Example:
Given the differential equation to the right with its boundary
conditions find the value of y(2) using Eulers method with
4 iterations.
1 ) 0 (
2
=
=
y
y x
dx
dy
2
1
4
0 2
. 2 = = A =

x h
2 1 0 . 1
4 0 0
= = = x and y and x
( )

= + =
= + =
1 1 0 1
0
. 3
2
1
2
1
2
1
2
1
1
y
x
( ) ( )

= + = + =
= + =
125 . 1 1 1 1
1
. 4
8
1
2
1
2
2
1
2
2
1
2
1
2
y
x
( ) ( )

= + = + =
= + =
6875 . 1 5625 . 125 . 1 125 . 1 1 125 . 1
5 . 1 1
. 5
2
1
2
3
2
1
3
y
x
( ) ( )

= + = + =
= + =
58594 . 3 89844 . 1 6875 . 1 6875 . 1 5 . 1 6875 . 1
2 5 . 1
. 6
2
1
2
4
2
1
4
y
x
The actual solution
is:
3
3
1
x
e y =
3919 . 14 ) 2 (
3
8
= =e y
Algorithm for Eulers Method
Given
f(x,y) (* expression for x and y *)
x0 (* initial value for x *)
y0 (* initial value for y *)
xn (* terminal value for x *)
n (* number of partitions of the interval *)

deltax = (xn-x0)/n

x
i
= x0
xprev = x
i
yi = y0
for(i=1, isn, i++,
x
i
= x
i
+ deltax
y
i
= y
i
+ f(xprev,y
i
)*deltax)
xprev=x
i

Return y
i

You might also like