Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Numerical Integration
Mohammad Tawfik
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Objectives
• The student should be able to
– Understand the need for numerical integration
– Derive the trapezoidal rule using geometric
insight
– Apply the trapezoidal rule
– Apply Simpson’s rule
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Need for Numerical Integration!
 
6
11
01
2
1
3
1
23
1
1
0
231
0
2













  x
xx
dxxxI
  11
0
1
0
1 
  eedxeI xx



1
0
2
dxeI x
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Area under the graph!
• Definite integrations always result in the
area under the graph (in x-y plane)
• Are we capable of evaluating an
approximate value for the area?
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• To perform the
definite integration of
the function between
(x0 & x1), we may
assume that the area
is equal to that of the
trapezium:
   01
01
2
1
0
xx
yy
dxxf
x
x



Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Adding adjacent areas
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
The Trapezoidal Rule
  
  
2
2
12
12
01
01
yy
xx
yy
xxI




Integrating from x0 to x2:
       
2
212112101001 yxxyxxyxxyxx
I


Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
The Trapezoidal Rule
    hxxxx  1201
If the points are equidistant
2
2110 hyhyhyhy
I


 210 2
2
yyy
h
I 
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Dividing the whole interval into “n”
subintervals






 


n
n
i
i yyy
h
I
1
1
0 2
2
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
The Algorithm
• To integrate f(x) from a to b, determine the
number of intervals “n”
• Calculate the interval length h=(b-a)/n
• Evaluate the function at the points yi=f(xi)
where xi=x0+i*h
• Evaluate the integral by performing the
summation






 


n
n
i
i yyy
h
I
1
1
0 2
2
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Note that
X0=a
Xn=b
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Integrate
• Using the trapezoidal
rule
• Use 2,3,&4 points and
compare the results

1
0
2
dxxI
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
• Using 2 points (n=1),
h=(1-0)/(1)=1
• Substituting:
 21
2
1
yyI    5.010
2
1
I
YX
00
11
2 points, 1 interval
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
• Using 3 points (n=2),
h=(1-0)/(2)=0.5
• Substituting:
 321 2
2
5.0
yyyI 
  375.0125.0*20
2
5.0
I
YX
00
0.250.5
11
3 points, 2 interval
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
• Using 4 points (n=3),
h=(1-0)/(3)=0.333
• Substituting:
 4321 22
2
333.0
yyyyI 
  3519.01444.0*2111.0*20
2
333.0
I
YX
00
0.1110.33
0.4440.667
11
4 points, 3 interval
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Let’s use Interpolation!
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Interpolation!
• If we have a function that needs to be
integrated between two points
• We may use an approximate form of the
function to integrate!
• Polynomials are always integrable
• Why don’t we use a polynomial to
approximate the function, then evaluate
the integral
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• To perform the
definite integration of
the function between
(x0 & x1), we may
interpolate the
function between the
two points as a line.
   0
01
01
0 xx
xx
yy
yxf 



Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Performing the integration on the approximate
function:
    









1
0
1
0
0
01
01
0
x
x
x
x
dxxx
xx
yy
ydxxfI
1
0
0
2
01
01
0
2
x
x
xx
x
xx
yy
xyI 

















Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Performing the integration on the approximate
function:







































 00
2
0
01
01
0010
2
1
01
01
10
22
xx
x
xx
yy
xyxx
x
xx
yy
xyI
  
2
01
01
yy
xxI


• Which is equivalent to the area of the trapezium!
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
The Trapezoidal Rule
  
2
01
01
yy
xxI


  
  
2
2
12
12
01
01
yy
xx
yy
xxI




Integrating from x0 to x2:
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Simpson’s Rule
Using a parabola to join three
adjacent points!
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Quadratic Interpolation
• If we get to interpolate a quadratic equation
between every neighboring 3 points, we may use
Newton’s interpolation formula:
      103021 xxxxbxxbbxf 
      1010
2
3021 xxxxxxbxxbbxf 
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Integrating
      1010
2
3021 xxxxxxbxxbbxf 
       
2
0
2
0
1010
2
3021
x
x
x
x
dxxxxxxxbxxbbdxxf
   
2
0
2
0
10
2
10
3
30
2
21
232
x
x
x
x
xxx
x
xx
x
bxx
x
bxbdxxf 


















Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
After substitutions and
manipulation!
   210 4
3
2
0
yyy
h
dxxf
x
x

Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Working with three points!
   210 4
3
2
0
yyy
h
dxxf
x
x

Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
For 4-Intervals
   432210 44
3
4
0
yyyyyy
h
dxxf
x
x

Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
In General: Simpson’s Rule
  





 




n
n
i
i
n
i
i
x
x
yyyy
h
dxxf
n 2
,..4,2
1
,..3,1
0 24
30
NOTE: the number of intervals HAS TO BE even
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Integrate
• Using the Simpson
rule
• Use 3 points

1
0
2
dxxI
Numerical Integration
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
• Using 3 points (n=2),
h=(1-0)/(2)=0.5
• Substituting:
• Which is the exact
solution!
 210 4
3
5.0
yyyI 
 
3
1
125.0*40
3
5.0
I

Numerical Integration