REMEMBERREMEMBERNUMERICAL DIFFERENTIATIONNUMERICAL DIFFERENTIATION
Forward Difference Formula
The derivative of y(x) at x0 is:
0 00 0
limh
y x h y xy x
h
An approximation to this is:
for small values of h. 0 00
y x h y xy x
h
school.edhole.com
0 00
( )y x h y xy x
h
0 0 0( )hy x y x h y x
0 0 0( )y x hy x y x h
0 0 0( )y x h y x hy x
Provided h is small.
school.edhole.com
0 0 0( )y x h y x hy x
0hy x
0x
0y x
0y x
h
0y x herror
x1
school.edhole.com
0 0 0( )y x h y x hy x
The value of a function at hx 0
can be approximated if we know its value
and its slope at an earlier point, 0xprovided h is small.
A sequence can be written as:
001 yhyy
school.edhole.com
1n n ny y hy
001 yhyy
In an initial value problem, ny is given
and often written as: nn yxf ,
nnnn yxhfyy ,1Therefore,
2 1 1y y hy
school.edhole.com
Euler’s Method
nnnn yxhfyy ,1
)( nn xyy Value of y at nxx
)( 11 nn xyy Value of y at 1 nxx
school.edhole.com
nnn xyyxf ,
First derivative of y at nxx h is a small number by which x is incremented.
hxx 01
hxhxx 2012 hxhxx 3023
nhxxn 0
school.edhole.com
So what are we doing in Euler’s method?
We are approximating the value of the function y at x = xn+1 based on the information that we obtained at the previous point, x = xn .
The previous information are:
The value of y at x = xn
The value of the first derivative of y at x = xn
school.edhole.com
nnnn yxhfyy ,1
Consider the following initial value problem.
500 .)( , yxyy
Find the value of y(0.8).
10. Let h
school.edhole.com
Given:
nnnnn xyxxyyxf ) at(,
5000 .)( yxxy at
where 00 x
Our starting point.
3010303
2010202
10100
03
02
01
..
..
..
hxx
hxx
hxx
school.edhole.com
Based on the sequence generated by Euler’s method we can write:
0001 yxhfyy ,
5505010501 .... y
500500000 ..),( xyyxf
school.edhole.com
1112 yxhfyy ,
5950450105502 .... y
450105501111 ...),( xyyxf
1010001 .. hxx
school.edhole.com
2223 yxhfyy ,
6345039501059503 .... y
39502059502222 ...),( xyyxf
201020202 .. hxx
Approximate value of y at x = x3 is 0.6345.
school.edhole.com
Therefore, we can write that
728205080
6345030
595020
55010
8
3
2
1
.).(
.
.
.).(
.).(
.).(
yy
yy
yy
yy
school.edhole.com
Modified Euler’s Method (Heun’s Method)
In the Modified Euler’s method an average value of the slope is used.
*,, 111 2
1nnnnnn yxfyxfhyy
Where*
1ny is calculated using the Euler’s method.
nnnn yxhfyy ,* 1
school.edhole.com
*1ny as calculated using the Euler’s
method shown above is used to obtain the 2nd slope.
nnnn yxhfyy ,* 1
*nn y,xf 11
school.edhole.com
Consider the previous initial value problem.
500 .)( , yxyy
Find the value of y(0.8).
10.h let Again,
school.edhole.com
5505010501 ....* y
500500000 ..),( xyyxf
450105501111 ...),( ** xyyxf
*,, 110001 2
1yxfyxfhyy
school.edhole.com
592250
4475010547502
.
...*
y
44750
10547501111
.
..),(
xyyxf
392250
205922502222
.
..),( **
xyyxf
school.edhole.com
*,, 221112 2
1yxfyxfhyy
5894870
392250447502
110547502
.
....
y
school.edhole.com
Taylor’s Method of Order Two
2
2
2Rxy
hxyhxyhxy )(
!)()()(
R2 is called Taylor’s remainder.
If h is small then:
)(!
)()()( xyh
xyhxyhxy 2
2
school.edhole.com
Taylor’s method of order two can be written in the form of the following sequence.
)(!
)()()( xyh
xyhxyhxy 2
2
nnnn yh
yhyy 2
2
1
school.edhole.com
Solve the following IVP by using Taylor’s method of order two.
10101 )( , , yxxyy
Solution:
xyxyyy 111 )(
nnnn yh
yhyy 2
2
1
school.edhole.com
nnn
nnn
xyy
xyy
1
nnnn yh
yhyy 2
2
1
)()( nnnnnn xyh
xyhyy 21
2
1
school.edhole.com
hxh
hyh
hy nnn
22
122
1
Let h = 0.1
10095090501 ... nnn xyy
school.edhole.com
n xn yn+1
0 0.0 1.005
1 0.1 1.019025
2 0.2 1.041218
3 0.3 1.070802
4 0.4 1.107076
Results with Taylor’s Method of Order Two
school.edhole.com
Interpolation produces a function that matches the given data exactly. The function then should provide a good approximation to the data values at intermediate points.
INTERPOLATIONINTERPOLATION
school.edhole.com
Interpolation may also be used to produce a smooth graph of a function for which values are known only at discrete points, either from measurements or calculations.
school.edhole.com
Given data points
Obtain a function, P(x)
P(x) goes through the data points
Use P(x)
To estimate values at intermediate points
school.edhole.com
Assume that a function goes through three points:
0 0 1 1 2 2, , , and , .x y x x y x x y x
( ) ( )y x P x
0 0 1 1 2 2P x L x y x L x y x L x y x
Lagrange Interpolating Polynomial
school.edhole.com
1 20
0 1 0 2
0 21
1 0 1 2
0 12
2 0 2 1
( )( )
( )( )
( )( )
( )( )
( )( )
( )( )
x x x xP x y x
x x x x
x x x xy x
x x x x
x x x xy x
x x x x
0 0 1 1 2 2P x L x y x L x y x L x y x
school.edhole.com
( ) ( )y x P x
1 20
0 1 0 2
0 21
1 0 1 2
0 12
2 0 2 1
2
( )( )
2
( )( )
2
( )( )
x x xP x y x
x x x x
x x xy x
x x x x
x x xy x
x x x x
school.edhole.com
NUMERICAL INTEGRATIONNUMERICAL INTEGRATION
( )b
a
y x dx area under the curve f(x) between
. to bxax
In many cases a mathematical expression for y(x) is unknown and in some cases even if y(x) is known its complex form makes it difficult to perform the integration.
school.edhole.com
Simpson’s Rule:
hxxhxx 20201 and
2 2
0 0
x x
x xy x dx P x dx
school.edhole.com
2 2
0 0
2
0
2
0
1 20
0 1 0 2
0 21
1 0 1 2
0 12
2 0 2 1
( )( )
( )( )
( )( )
( )( )
( )( )
( )( )
x x
x x
x
x
x
x
x x x xP x dx y x dx
x x x x
x x x xy x dx
x x x x
x x x xy x dx
x x x x
school.edhole.com
Runge-Kutta method uses a sampling of slopes through an interval and takes a weighted average slope to calculate the end point. By using fundamental theorem as shown in Figure 1 we can write:
school.edhole.com
0hy x
0x
0( )y x
hx 0
0y x
h
0y x herror
0 0 0( )y x h y x hy x
school.edhole.com
0hy x
0x
0( )y x
hx 0
0y x
h
0y x herror
school.edhole.com
(1) dxxydy
hxy n
nxy dxdy
nx hxn
school.edhole.com
Integrating both sides of Eqn. (1) we get
(2) dxxydy
Applying appropriate limits to Eqn. (2) we get
(3) 1
1 dxxyxyxyn
n
x
xnn
(4) dxxyxyhxyhx
xnn
n
n
school.edhole.com
Let us now concentrate on the right-hand side of Eqn. (4).
(5) dxxPdxxyhx
x
hx
x
n
n
n
n
P(x) can be generated by utilizing Lagrange Interpolating Polynomial. Assume that the only information we have about a function, f(x) is that it goes through three points:
0 0 1 1 2 2, , , and , .x y x x y x x y x
school.edhole.com
( ) ( )P x y x 0 0 1 1 2 2P x L x y x L x y x L x y x
1 20
0 1 0 2
0 21
1 0 1 2
0 12
2 0 2 1
( )( )
( )( )
( )( )
( )( )
( )( )
( )( )
x x x xP x y x
x x x x
x x x xy x
x x x x
x x x xy x
x x x x
school.edhole.com
Using Simpson’s Integration,
2 2
0 0
1 0 2 0and 2
x x
x xy x dx P x dx
x x h x x h
school.edhole.com
...………………….(6)
2 2
0 0
2
0
2
0
1 20
0 1 0 2
0 21
1 0 1 2
0 12
2 0 2 1
( )( )
( )( )
( )( )
( )( )
( )( )
( )( )
x x
x x
x
x
x
x
x x x xP x dx y x dx
x x x x
x x x xy x dx
x x x x
x x x xy x dx
x x x x
2 2
0 00 1 24
3
x x
x x
hy x dx P x dx y x y x y x
school.edhole.com
We can apply Simpson’s Integration to Eqn. (6) with the following substitutions:
nxx 0 hxx n 2; ;
2/hh and the midpoint, 21
hxx n
hxy
hxyxy
hdxxy nnn
hx
x
n
n 24
6
….(7)
school.edhole.com
Compared to Euler’s Formula, an average of six slopes is used in Eqn. (7) instead of just one slope. Actually, the slope at the midpoint has a weight of 4. The slope at the midpoint can be estimated in two ways.
hxy
hxy
hxyxy
hdxxy nnnn
hx
x
n
n 22
22
6
hxy
hxy
hxyxy
hxyhxy nnnnnn 2
22
26
hxy
hxy
hxyxy
hxyhxy nnnnnn 2
22
26
school.edhole.com
The slopes can be estimated in the following manner:
nnn yxfkxy ,1
12 2
,22
kh
yh
xfkh
xy nnn
11 2
22
26 nnnnnn xy
hxy
hxyxy
hxyxy
........... (8)
school.edhole.com
23 2
,22
kh
yh
xfkh
xy nnn
34 , hkyhxfkhxy nnn
Substituting the estimated slopes into Eqn. (8) gives the formula for Runge-Kutta Method of Fourth Order:
43211 226
kkkkh
yy nn
school.edhole.com