ode numerik
TRANSCRIPT
-
8/13/2019 Ode Numerik
1/19
Numeri cal Di ff erentiation
DEFINITION
fdf
d
lim f f( )
( ) ( ) ( )x
x
x h
x h x
h0
Analytical solution employing this definition is demonstrated as follows
Example : What is y x( ) atx=agiven that f(x x) 3 ?Solution : Following the above definition;
y x hy x h y x
h
ha h a
h
h
a a h ah h a
h
ha h ah h
h
h a ah h
a
( )( ) ( )
( )
lim
lim
lim
lim
lim
0
0
0
3 3
03 3
0 3 3
3
3 3
3 2 2 3 3
2 2 3
2 2
2
Numerical solution of this problem is basically based on simplification on the limit term in such that value
of h h rather than h 0 . It is logical, therefore, the smaller one choose the value for hthe closerthe result to the true value (i.e. obtained by analytical solution). Accordingly, one way to express numerical
solution is as follows;
f
df
d
f f( )
( ) ( ) ( )x
x
x
x h x
h h x
or
fdf
d
f f( )
( ) ( ) ( )x
x
x
x x x
x
-
8/13/2019 Ode Numerik
2/19
TAYLOR SERIES
More flexible way to formulate derivative term numerically is based on Taylor series expansion. Taylors
theorem states that:
f f d fd
d fd
d fd
d f
d
1 2 3
4
( )!
( )!
( )!
( )!
( )
!
( ).....
x x x x x xx
x xx
x xx
x x
x
0
0
0
1
01
2
02
3
03
40
4
0 1 2 3
4
[1a]
or
f f d f
d
d f
d
d f
d
d f
d
1 2 3
4
( )!
( )!
( )
!
( )
!
( )
!
( ).....
x x x
x x x
x
x x
x
x x
x
x x
x
0
0
0
10
1
20
2
30
3
40
4
0 1 2 3
4
[1b]
The above two series provide a mean to predict value of functionf(x)atx0+xwhen values off(x0),x0, and
xare given.
For partial derivative:
f ff f
f f
f f f
( , ) ( , )!
( , )
!
( , )
!( , )
!( , )
!
( , )
!
( , )
!
( , )
x x y y x yx x y
x
y x y
y
x x yx
y x yy
x x y
x
y x y
y
x x y
0 0 0 0
1 10 01
1 10 0
1
2 20 02
2 20 02
3 30 03
3 30 03
4 40 0
1 1
2 2
3 3 4
x 4 .....
[2]
x0
x
x0+x
f(x0) (x0+x)
-
8/13/2019 Ode Numerik
3/19
Example : What is the error inyof equation y x x 2 3 atx=1.1 if it is predicted using Taylorsseries ?
Solution : By Taylors series expansion
y y
y x y x y x y x
x x x x
( . ) ( . )
( ) . ( ).
( ).
( )
.. .
( )
. . ( ) . ( )
. . .
.
11 1 01
0101
2
01
6
2 01 6 101
212
01
612
2 1 1 01 6 1 1 0 005 12 1 0 000167 12
3 0 7 0 06 0 002004
3762004
2 3
3 22 3
3 2
Analytical solution ofyatx=1.1 is y 2 11 11 3 7623. . .
-
8/13/2019 Ode Numerik
4/19
DERIVATIVE NUMERICAL FORMULATION BASED ON TAYLOR SERIES
A. First derivative
Forward difference
f fdf
d truncation( ) ( )
( )x x x x
x
x0 0
0
so that
df
d=
f ftruncation
( ) ( ) ( )x
x
x x x
x
0 0 0
or
df
d
f f( ) ( ) ( )x
x
x x x
x
0 0 0
Backward difference
f fdf
d truncation( ) ( )( )
x x x xx
x0 0 0
df
d
f f( ) ( ) ( )x
x
x x x
x
0 0 0
Central difference
f fdf
d truncation( ) ( )
( )x x x x
x
x0 0
0
f fdf
d truncation( ) ( )
( )x x x x
x
x0 0
0
f f dfd
( ) ( ) ( )x x x x x xx
0 002
so that
df
d
f f( ) ( ) ( )x
x
x x x x
x
0 0 0
2
-
8/13/2019 Ode Numerik
5/19
B. Second derivative
Central difference
f fdf
d
d f
d
2
truncation( ) ( )( ) ( )
x x x xx
x
x x
x0 0
02
0
2
f f dfd
d f
d
2truncation( ) ( )
( ) ( )x x x x xx
x x
x0 0
0 2 022
2
0
22
000d
)(fd)(f2)(f)(f
x
xxxxxxx
so that
2
000
2
0
2 )(f+)(f2)(f
d
)(fd
x
xxxxx
x
x
C. High accuracy first derivative
f fdf
d
d f
d
2
truncation( ) ( )( ) ( )
x x x xx
x
x x
x0 0
02
0
2
or
df
d=
f f d f
d
2
truncation
( ) ( ) ( ) ( )x
x
x x x
x
x x
x
0 0 0 0
2
Substituting the second derivative term the result obtained in (B) above:
dfd
= f f f f f
f f f f f
- f f f
truncation
truncation
( ) ( ) ( ) ( ) ( ) ( )
( ) ( ) ( ) ( ) ( )
( ) ( ) (
xx
x x xx
x x x x x x
x
x x x
x
x x x x x
x
x x x x
0 0 0 0 0 02
0 0 0 0 0
0 0
22
2
2
4 3
0
2
x
x
) truncation
or
df
d
- f f f ( ) ( ) ( ) ( )x
x
x x x x x
x
0 0 0 04 3
2
-
8/13/2019 Ode Numerik
6/19
Numeri cal I ntegration
DEFINITION
f x dx f u xii
n
( ) ( )
limx 0
1
Point uiis a point in x-axis choosen in such that the product off(ui).xrepresenting the shaded area and this
area should be regarded as the itharea which can be related to pointxi.
Alternative procedure to obtain solution of integral are:
1. Analitical approach;a) Employing definition of integralb) Deriving general form of an equation based on definition of integral to obtain Integration Rule or
Formula. For example based on derivation of antiderivative of polinomial, it can be shown that;
ax dxa
bx
b b
11
2. Numerical approach : most often the procedure is based on Interpolatory Numerical Integrationmethod
xix0=a xn=b
f(x)
x
ui(xi,x)
(ui)
(xi)
-
8/13/2019 Ode Numerik
7/19
PREVIEW ON ANALITICAL APPROACH
Example:
Find x dxa
b
2 using definition of integral and verify the result using antiderivative formula at a=2
and b=3Solution:
By definition:
f x dx f u xii
n
( ) ( )
limx 0
1
When x 0 then f u f xi i( ) ( ) , so
f x dx f x xii
n
( ) ( )
limx 0
1
So that
x dx x xii
n2 2
1
limx 0 ( )
The figure above shows thatxi= a + i.xin which i=1,2,3,...nin such thatx0=a,xn=band x= (a-b)/n.
Subtituting these, one will get;
x dxx
a i x x
x a x a i x i x
x a
b a
na i
b a
ni
b a
n
i
n
i
n
i
n
2 2
1
2 2 2 3
1
2
1
2
2
3
0
0 2
0 2
lim
lim
lim
( )
( )
Note that the term xhas been eliminated from the equation so that thr term of x 0 becomesmeaningless. On the otherhand, when the length of xdecreases, the value of nwill increase. This means
xix0=a xn=b
f(x)x
-
8/13/2019 Ode Numerik
8/19
that nwill be infinity as xbecomes infinitesimal. Based on this fact the above expression can be written as
the following:
x dxn
a b a
na i
b a
ni
b a
n
n a b a
n n a b a
ni
nb a
ni
i
n
i
n
i
n
i
n
2 2
2
2
3
1
2
1
2
1
3
2
1
2
2
lim
lim lim lim
Now, the first term becomes;
limn a b a
na b a n
i
n
2
1
2,
And since i = (n(n+1))/2 and i2= (n(n+1)(2n+1))/6, the second and the third terms become;
lim lim
lim
n a
b a
ni
n a
b a
n
n n
n a b
a b
na b
a b
na
a
n
a b a b a
i
n
2 2
1
2
2 2
2
2
1
2
22
22
33
2 2 3
( )
and
lim lim
lim
nb a
ni n
b a
n
n n n
n
b b
n
b
na b
a b
n
a b
na b
a
n
a b
n
a a
n
a
n
i
n
32
1
3
3 3 3
2
22 2
2
22 2
2
3 3 3
2
1 2 1
6
3 2 6
3
2 2
3
2 2 3 2 6
( ) ( )
1
3
1
3
3 2 2 3b a b a b a
Putting all the terms back together will result in the following:
xa
dx a b a a b a b a b a b a b a
b a a a b b
b
2 2 2 2 3 3 2 2 3
2 2
2 1
3
1
3
1
3
( ) ( )
Given those a=2 and b=3;
xa
dx b a a a b b
b
2 2 2
2 2
1
3
1
33 2 2 2 3 3
6 3333
.
Alternativelly, using power antiderivative formula, one may get;
-
8/13/2019 Ode Numerik
9/19
xa
dx x
b
2 3
2
3
2 2
1
3
1
33
1
32
6 3333
( ) ( )
.
-
8/13/2019 Ode Numerik
10/19
NUMERICAL APPROACH
f x dx g x dx( ) ( )
Whereg(x) is a continues function that:
1. Satisfyf(x) atxi, in which i=1, 2, ..., n.2. Relativelly easy to integrate.
Polynomials form is commonly used asg(x). Procedure:
1. Construct polynomials that pass through the given points. For example; use Lagrange interpolatingpolynomials.
2. Integrate the obtained polynomials
LAGRANGE INTERPOLATING POLYNOMIALS
g x f x x xx xi
j
i jjj i
n
i
n
( ) ( )
00
So that, for example, if n=2 then :
g xx x x x
x x x xf x
x x x x
x x x xf x
x x x x
x x x xf xo( ) ( ) ( ) ( )
1 2
0 1 0 2
0 2
1 0 1 21
0 1
2 0 2 12
And to constructg(x) that pass through pointsf(1)=0,f(2)=3,f(3)=16 then;
g x
x x x x x x
x x
( )
2 3
1 2 1 30
1 3
2 1 2 33
1 2
3 1 3 216
5 12 72
-
8/13/2019 Ode Numerik
11/19
NUMERICAL INTEGRATION EMPLOYING LAGRANGE POLYNOMIALS WITH n=2
f x dx
x x x x
x x x x f x
x x x x
x x x x f x
x x x x
x x x x f x dx
f x
hx x x x x x x dx
f x
hx x x x
a
b
ox
x
x
x
( )
( ) ( ) ( )
( )
( )
1 2
0 1 0 2
0 2
1 0 1 21
0 1
2 0 2 12
02
21 2 1 2
12
20
0
2
0
2
2
x x x dx
f x
h
x x x x x x x dx
hf x f x f x
x
x
x
x
2 0 2
2
2
20 1 0 1
0 1 2
0
2
0
2
2
34
( )
( ) ( ) ( )
NUMERICAL INTEGRATION EMPLOYING LAGRANGE POLYNOMIALS WITH n=1
f x dx
x x
x xf x
x x
x xf x dx
f x
hx x dx
f x
hx x dx
f x
hx x x
f x
hx x x
f x
a
b
o
x
x
o
x
x
x
x
o
x
x
x
x
o
( )
( ) ( )
( ) ( )
( ) ( )
( )
1
0 1
0
1 0
1
11
0
21
1 20
0
1
0
1
0
1
0
1
0
11
2
1
2
hx x x x x
f x
hx x x x x
f x
h x x x x f x
h x x x xo
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
12
12
02
0 11
12
0 1 02
02
12 0 1 02 1 02 0 1 12
( )
( ) ( )
f x
hx x
f x
hx x
hf x f x
o
o o
( )( )
( )( )
( ) ( )
1
2
1
2
2
1 02 1
1 02
-
8/13/2019 Ode Numerik
12/19
N Points Rules Name Formula
1 2 Trapezoidal( )
( ) ( )b a
f x f x
0 12
2 3 Simpsons 1/3( )
( ) ( ) ( )b a
f x f x f x
0 1 246
3 4 Simpsons 3/8( )
( ) ( ) ( ) ( )b a
f x f x f x f x
0 1 2 33 3
8
4 5 Booles( )
( ) ( ) ( ) ( ) ( )b a
f x f x f x f x f x
7 32 12 32 790
0 1 2 3 4
5 6( )
( ) ( ) ( ) ( ) ( ) ( )b a
f x f x f x f x f x f x
19 75 50 50 75 19288
0 1 2 3 4 5
OTHER APPROACH
1. Minimizing Trapezoidal rule error Ricradson Extrapolation, Romberg Integration
II I
j k
kj k j k
k,, ,
4
4 1
11 1 1
1
2. Area Substitution Gauss Quadrature
Two-points I f f
1
3
1
3.
Three Points see pp 517-519
-
8/13/2019 Ode Numerik
13/19
Ordinary dif ferential Equation
GENERAL FORM OF ODE
Speed (v) change of falling parachute with respect to time:
dv
dt
g c
m
v
In whichg,m,c are gravity acceleration, mass, and drag constant respectivelly. If these three variables are
regarded as constant parameter, this equation can be express mathematically as:
dv
dtv f v ( )
Note that the above equation state that: first derivative of vis function of vitself. This patern is the basic
form of ODE..
NUMERICAL FORMULATION OF ODEBASED ON GEOMETRIC INTERPRETATION.
Euler Method
Keep in mind thaty=f(x,y) is an ODE buty=f(x) is not. Graphicaly,y=f(x,y) can be plotted as shown in
figure 1. Recall that numerical formulation for first derivative using forward differnce is:
y x y x x y x
x
y x x y x y x y x
i
i i
i i i i
( ) ( ) ( )
( ) ( ) ( , )
Since, according to definition of ODE, y x y f x yi i i i( , ) ( , ) then:
y x x y x f x y xi i i i( ) ( ) ( , ) Plot of the last form is sown in figure 2.
y y
x x
y=f(x) y=f(x)
y(xiyi)=f(x,y)
Figure 1 Figure 2xixi
y(xi) y(xi+x)
x
xi+x
y(xiyi)=f(x,y)
-
8/13/2019 Ode Numerik
14/19
Example on Euler Method
Example: Ify is function ofx, plot numerically the first derivative ofx2.y+x.y3=x+ygiven thaty(2)=3.
Use x=0.1.
NOTE: - at least one initial condition should be known. In this case y(2)=3.
- in practical field implementation value of x is up to the modelerSolution:
x y x y x y2 3 First derivative of this function is:
2 3 12 3 2x y x y y x y y y After solving fory we get
y
x y y
x y x
1 2
3 1
3
2 2
or written in complete notation:
y x y x y x y x
x y x x
( , ) ( ) ( )
( )
1 2
3 1
3
2 2
First derivative numerical solution by Euler method:
y x x y x y x y x
y x x y x y x
x y x xx
i i i i
i
i i i
i i i
( ) ( ) ( , )
( ) ( ) ( )
( )
1 2
3 1
3
2 2
Therefore
y
y y y y
y
y y y y
y
( )
( . ) ( ) ( ) ( )
( ).
.
.
( . ) ( . ) . ( . ) ( . )
. ( . ) ..
. . . .
2 3
2 1 2 1 2 2 2 2
2 3 2 2 10 1
3 1 2 2 3 3
2 3 3 2 101
2 933
2 2 2 1 1 2 2 1 2 1 2 1
2 1 3 2 1 2 1 101
2 933 1 2 2 1 2 933 2
3
2 2
3
2 2
3
2 2
933
2 1 3 2 933 2 1 10 1
2870
2 3 2 809
3
2 2. . ..
.
( . ) .
y
-
8/13/2019 Ode Numerik
15/19
IMPROVEMENT ON EULER METHOD (PERDICTOR-CORRECTOR METHOD)
A. Heuns Method
Lets denote y x yi i( ) andy x x yi i x( ) , then formulation of:
Predictor: y y f x y xi x i i i 0 ( , )
Corrector: y yf x y f x x y
xi x ii i i i x
10
2
( , ) ( , )
B. Modif ied Euler M ethod
Predictor: y y f x yx
i x i i i 1
2
0
2
( , )
Corrector:
y y f x x y xi x i i i x
1 12
012
( , )
Note:
xi+ x means the value of xiadded by a length as much as x yi+x means the value ofyatx=xi+ x aproximated by the formula yi+ x.k means the value ofyatx=xiadded by a length as much as the product of
xand k.
General form isyi+x=yi+ .xwhere = average slope. Therefore, the three methods presented so far areonly different in the way they predict the average slope.
(xi,yi)
y=f(xi,yi)
x
x.f(xi,yi)(xi,yi)
y=f(xi,yi)
x
x.f(xi,yi)
y=f(xix,yi+x)
(xi,yi)
y=f(xi,yi)
x
x.f(xi,yi)
y=f(xix,yi+x)
Euler Heuns Modified Euler
-
8/13/2019 Ode Numerik
16/19
C. Runge-Ku tta Method
General form of numerical ODE solution
y y x y x xi x i i i ( , , )
Where(x ,y , x)=a k a k a k
k f x y
k f x p x y q x k
k f x p x y q x k q x k
k f x p x y q x k q x k q x k
k f x p x y
i i n n
i i
i i
i i
i i
n i n
1 1 2 2
1
2 1 11 1
3 2 21 1 22 2
4 3 31 1 32 2 33 3
1
( , )
( , )
( , )
( , )
( ,
i n n n n n
n i n i n j jj
n
q x k q x k q x k
k f x p x y x q k
1 1 1 1 2 2 1 1 1
1 11
1
, , ,
,
)
,
or
For example, derivation of the second order RK (n=2), in which:
y y a k a k x
k f x y
k f x p x y q k x
i x i
i i
i i
( )
( , )
( , )
1 1 2 2
1
2 1 11 1
Substituting the k1and k2it will becomey y a k a k x
y a k x a k x
y a x f x y a x f x p x y q k x
i x i
i
i i i i i
( )
( , ) ( , )
1 1 2 2
1 1 2 2
1 2 1 11 1
[1]
Taylor series expansion for a function with two dependent varibles:
g x r y s g x y rg x y
xs
x y
y( , ) ( , )
( , ) ( , )
Employing this expansion for the form off(xi+p1x,yi+q11k1x) in eqn. [1]:
f x p x y q k x
f x y p x f x yx
q k x f x yx
i i
i ii i i i
( , )
( , ) ( , ) ( , )
1 11 1
1 11 1
[2]
-
8/13/2019 Ode Numerik
17/19
substituting back [2] into [1]:
y y a x f x y a x f x p x y q k x
y a x f x y a x f x y p xf x y
xq k x
f x y
y
y a a x f x y a p xf x
i x i i i i i
i i i i ii i i i
i i i
1 2 1 11 1
1 2 1 11 1
1 2 2 1 2
( , ) ( , )
( , ) ( , )( , ) ( , )
( ) ( , )(
i i i i
y
xa q k x
f x y
y
, ) ( , )
2 11 12
Since k1=f(xi,yi) and after algebra manipulation one will get:
y y a a x f x y
a p xf x y
x
a q x f x yf x y
y
i x i i i
i i
i ii i
( ) ( , )
( , )
( , )( , )
1 2
2 12
2 112
[3]
Recall that based on Taylor series expansion:
y y x x y x dydx
x d ydx
i x i ( ) ........2 2
22
Since dy/dx=f(x,y), then
y y x f x yx df x y
dx
y x f x yx f x y
x
f x y
y
dy x
dx
i x i
i
( , )( , )
........
( , )( , ) ( , ) ( )
........
2
2
2
2
Or
y y x f x y
xf x y
x
x f x yf x y
y
i x i
1
1
2
1
2
2
2
( , )
( , )
( , )( , )
[4]
Comparing [3] and [4] we conclude that
a a
a p
a q
1 2
2 112
2 1112
1
[5]
Solving system of equation [5] and choosing a2to be then a1= andp1=q11=1, then
y y k k xi x i
1
2
1
21 2
-
8/13/2019 Ode Numerik
18/19
1. Secod Oder:
y y k k x
k f x y
k f x x y x k
i x i
i ii i
1
2
1
21 2
12 1
Where:
( , )
( , )
2. Third Order
y y k k k x
k f x y
k f x x y x k
k f x x y x k x k
i x i
i i
i i
i i
1
64
2
1 2 3
1
212
12 1
3 1 2
Where:
( , )
( , )
( , )
3. Fourth Order
y y k k k k x
k f x y
k f x x y x k
k f x x y x k
k f x x y x k
i x i
i i
i i
i i
i i
1
62 21 2 3 4
1
212
12 1
312
12 2
4 3
Where:
( , )
( , )
( , )
( , )
4. Fifth Order
y y k k k k k x
k f x y
k f x x y x k
k f x x y x k x k
k f x x y x k x k
k f x x y
i x i
i i
i i
i i
i i
i i
1
907 32 12 32 71 3 4 5 6
1
214
14 1
314
18 1
18 2
412
12 2 3
534
Where:
( , )
( , )
( , )
( , )
( , 3
16 19
16 4
637 1
27 2
127 3
127 4
87 5
x k x k
k f x x y x k x k x k x k x k i i
)
( , )
-
8/13/2019 Ode Numerik
19/19