# Numerical Solutions of Differential Equations ```Numerical Solutions of
Differential Equations
Taylor Methods
Euler’s Method
We have previously seen Euler’s Method for estimating the solution of a
differential equation. That is to say given the derivative as a function of x and y (i.e.
f(x,y)) and an initial value y(x0)=y0 and a terminal value xn we can generate an
estimate for the corresponding yn. They are related in the following way:
 xk 1  xk  x
( xk 1 , yk 1 )  
 yk 1  yk  f ( xk , yk ) x
The value x = (xn-x0)/n and the accuracy increases with n.
Taylor Method of Order 1
Euler’s Method is one of a family of methods for solving differential equations
developed by Taylor. We would call this a Taylor Method of order 1. The 1 refers
to the fact that this method used the first derivative to generate the next
estimate. In terms of geometry it says you are moving along a line (i.e. the
tangent line) to get from one estimate to the next.
Taylor Method of Order 2
In this method instead of moving from point to point along a line we move from
point to point along a parabola. Not just any parabola but the parabola that most
closely approximates the function y we are interested in.
In intermediate calculus we discussed Taylor’s Theorem. This explained how to
get a polynomial of varying degrees that would estimate any function at a point a.
In particular a second degree polynomial (i.e. it graph is a parabola). How you do
this estimate is given below.
y( x)  y(a)  y' (a)( x  a) 
y ( x)  y (a) 
dy
dx
( x  a) 
y ''( a )
2
2
d
y
1
2 dx2
( x  a)
( x  a)
2
2
In order to be able to apply this we need to be able to resolve 2 questions:
1) How is the second or higher derivative found?
2) How is accuracy improved by increasing the number of subintervals?
Computing Higher Order Derivatives
The problem we are trying to solve we are given the first derivative expressed as
a function of x and y. How can we get the second, third or any higher derivative
from this piece of information?
We use a concept from multivariable calculus and a tool called partial derivatives.
The Problem:
Given :
dy
 f ( x, y )
dx
dy
dx
2
find
d y
dx 2
To the right is a tree that shows
how the variables depend on each
other. Remember y is a function of
x (i.e. y is the dependent variable x
is the independent variable).
The delta symbol  indicates a
partial derivative which means
treat the indicated variable as the
variable and all other variables as
a constant.
x
y
x
d 2 y d dy f f dy


 
2
dx
dx dx x y dx
Example:
Find the second derivative if the first derivative is given
to the right.
dy
 x2 y
dx
Set f(x,y) = x2y and plug it into the formula below.
d 2 y f f dy

 
2
dx
x y dx
Here we notice that:
 x y 
 2 xy  x
2
 2 xy  x 4 y
2
f
 2 xy and
x
f
 x2
y
Notice you get a function of x and y again!
Higher Derivatives
Third, fourth, fifth, … etc derivatives can
be computed with the same method.
This has a recursive definition given to
the right.
d n1 y  d n y   d n y  dy 


 

n 1
n
n 
dx
x dx  y dx  dx 
Subintervals
If we wish to apply Taylor’s Method to the general differential
equation given to the right on only one subinterval we simply
plug into the formula the following values:
x0 = a
y0 = f(x0)
x1 = x
dy
 f ( x, y )
dx
y ( x0 )  y0
y  y (a)  y ' (a)( x  a)  12 y ' ' (a)( x  a) 2
y1  y0 
dy
dx x  x0
y  y0
( x1  x0 ) 
2
1 d y
2 dx 2 x  x0
y  y0
y1  y0  f ( x0 , y0 )( x1  x0 )  12
( x1  x0 ) 2

f ( x0 , y0 )
x

 f ( x0y, y0 )  f ( x0 , y0 ) ( x1  x0 ) 2
Applying this to a subinterval with n parts to the partition this formula becomes:
 xk 1  xk  x

( xk 1 , yk 1 )  
1
yk 1  yk  dy
x  xk ( x )  2
dx

y  yk
Where:
d2y
dx
2
2
(

x
)
x  xk
y  yk
x 
xn  x0
n
Example:
Apply the second order Taylor Method to estimate the
solution to the differential equation to the right at x = 2 using
4 partitions.
dy
dx
 x2 y
y(0)  1
The recursive formula becomes:
1
x

x


k
2
 k 1
( xk 1 , yk 1 )  
2
4
1
1
1 2

 yk 1  yk  xk yk  2   2 2 xk yk  xk yk  2 
( x0 , y0 )  (0,1)
( x1 , y1 )  (.5,1)
( x2 , y2 )  (1,1.25781)
( x3 , y3 )  (1.5,2.3584)
( x4 , y4 )  (2,7.38842)
The estimate we have found for this
value is 7.38842
Higher Order Taylor Methods
Taylor’s Method can be extended to any order Taylor approximation by the following
recursive definition. This is the definition of a Taylor method of order n.
 xk 1  xk  x

( xk 1 , yk 1 )  
1
yk 1  yk  dy

x

x

x
dx
2
k

y  yk
d2y
dx 2 x  xk
y  yk
x 
2

n
1 d y
n! dx n x  xk
y  yk
Algorithm for Taylor’s Method
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
xi = x0
xprev = xi
yi = y0
for(i=1, in, i++,
xi = xi + deltax
yi = yi + f(xprev,yi)*deltax+…+(1/(n!))(y(n)(xprev,yi)*deltax)
xprev=xi
Return yi
x n
```