C04-Defferentiation and Integration
C04-Defferentiation and Integration
Numerical Differentiation
5/5/2012 by Adam Pamudji R 2
First Order Derivative
First Order Taylor Series for x closed to x
0
( ) ( )
( )
( )
0
0 1
0
0 0 0 1
) (
) ( '
) ( ' ) (
x x
x f x P
x f
x x x f x f x P
~
+ ~
5/5/2012 by Adam Pamudji R 3
graphical explanation
( ) ( )
( )
( )
0
0 1
0
0 0 0 1
) (
) ( '
) ( ' ) (
x x
x f x P
x f
x x x f x f x P
~
+ ~
x
0 x>x
0
x<x
0
forward difference
backward difference
) ( '
0
x f
) (
0
x f
( ) x P x f
1
) ( ~ ( ) x P x f
1
) ( ~
( )
( )
0
0
0
) (
) ( '
x x
x f x f
x f
~
5/5/2012 by Adam Pamudji R 4
( )
h
x f h x f
x f
) (
) ( '
0 0
0
+
~
If x = x
0
+ h, then for forward difference we have
If x = x
0
- h, then for backward difference we have
( ) ( )
h
h x f x f
h
x f h x f
x f
=
~
0 0 0 0
0
) ( ) (
) ( '
5/5/2012 by Adam Pamudji R 5
First Order Derivative
Second Order Taylor Series for x closed to x
0
( ) ( )
( )
( )
( )
( ) ( )
( ) ( )
h
h x f h x f
x f
x f h h x f h x f
h x f
h x f x f h x f
h x f
h x f x f h x f
x x x f
x x x f x f x P
2
) ( '
0 ) ( ' 2 0
2
) ( ' '
) ( ' ) (
2
) ( ' '
) ( ' ) (
! 2
) ( ' '
) ( ' ) (
0 0
0
0 0 0
2
0
0 0 0
2
0
0 0 0
2
0 0
0 0 0 2
+
~
+ + ~ +
+ ~
+ + ~ +
+ + ~
5/5/2012 by Adam Pamudji R 6
graphical explanation
( )
h
h x f h x f
x f
2
) (
) ( '
0 0
0
+
~
x
0
x
0
-h
central difference
) ( '
0
x f
) (
0
x f
) (
0
h x f + ) (
0
h x f
x
0
+h
5/5/2012 by Adam Pamudji R 7
Reading Assignment
Please read page 146 to 150 section 4.1
for another approach
Find about:
The three point formulas
The five point formulas
5/5/2012 by Adam Pamudji R 8
Second Order Derivative
Second Order Taylor Series for x closed to x
0
( )
( )
( ) ( )
( ) ( )
2
0 0 0
0
2
0 0 0 0
2
0
0 0 0
2
0
0 0 0
) ( 2
) ( ' '
) ( ' ' 0 ) ( 2
2
) ( ' '
) ( ' ) (
2
) ( ' '
) ( ' ) (
h
h x f x f h x f
x f
h x f x f h x f h x f
h x f
h x f x f h x f
h x f
h x f x f h x f
+ +
~
+ + ~ + +
+ ~
+ + ~ +
5/5/2012 by Adam Pamudji R 9
Differentiation from interpolation
function
The use of polynomials in approximation
problems allow us to find the derivative
and integral from that functions.
Read page 145 and 146
5/5/2012 by Adam Pamudji R 10
Differentiation and Integration
( ) ( )
( ) ( )
( ) ( )
} }
~
~
~
dx x f dx x P
x f x P
x f x P
n
n
n
' '
5/5/2012 by Adam Pamudji R 11
Differentiation
( ) ( ) ( )
( ) ( ) ( ) x L
dx
d
x f
x L x f
dx
d
x P
i n
n
i
i
n
i
i n i n
,
0
0
,
'
=
=
=
|
.
|
\
|
=
5/5/2012 by Adam Pamudji R 12
Differentiation
( )
( )
( )
( ) ( )
( )
( )
[
[
[
=
=
=
=
=
=
=
=
=
|
|
|
|
.
|
\
|
=
n
i j
j
n
i l
j l
l
l
n
i j
j
j i
i n
n
i j
j
j i
j
i n
x x
x x
x L
dx
d
x x
x x
x L
0 0
0
,
0
,
1
5/5/2012 by Adam Pamudji R 13
Numerical Integration
We can use the
interpolation function
to approximate an
integral
( ) ( )
( ) ( )
} }
~
~
dx x P dx x f
x P x f
n
n
( ) ( ) ( )
( ) ( ) ( )dx x L x f
dx x L x f dx x P
b
a
i n
n
i
i
b
a
n
i
i n i
b x
a x
n
}
}
}
=
=
=
=
=
|
.
|
\
|
=
,
0
0
,
5/5/2012 by Adam Pamudji R 14
Numerical Integration
For the first and second Lagrange
polynomials with equally spaced nodes
Trapezoidal rule
Simpsons rule
Read page 163 to 165
Learn about closed and open Newton-
Cotes formulas (p 168 to p 173)
5/5/2012 by Adam Pamudji R 15
Trapezoidal rule
For function f(x)
between x
0
=a and
x
1
=b
h = x
1
x
0
| | ) ( ' '
12
) ( ) (
2
) (
3
1 0
f
h
x f x f
h
dx x f
b
a
+ =
}
a=x
0
b=x
1
f
P
1
x
y
5/5/2012 by Adam Pamudji R 16
Simpson rule
| |
) (
90
) ( ) ( 4 ) (
3
) (
) 4 (
5
2 1 0
f
h
x f x f x f
h
dx x f
b
a
+ + =
}
For function f(x)
between x
0
=a and
x
2
=b
a=x
0
b=x
2
f
P
1
x
y
x
1
5/5/2012 by Adam Pamudji R 17
Closed and Open Newton-Cotes
Closed N-C
Trapezoidal rule
Simpsons rule
Simpsons three-eight rule
Open N-C
Midpoint rules: n=0
n=1
n=2
a=x
-1
b=x
1
f
P
1
x
y
x
0
5/5/2012 by Adam Pamudji R 18
Examples
See the excel file
5/5/2012 by Adam Pamudji R 19
Numerical Integration
Gaussian Quadrature
For a given known function
Optimizing accuracy by selecting best position
of nodes.
By using a standard tabulated coeff and node
positions, it is necessary to transform linearly
the function to an interval [-1,1]
5/5/2012 by Adam Pamudji R 20
Gauss Quadrature
Read page 198 to 204
Example file