University of Palestine
Gaza Strip
Civil Engineering College
Numerical analysis
CIVL 3309
Formerly CVL 3308
Dr. Suhail Lubbad
Discussion
Numerical Integration
TRAPEZOIDAL RULE
THE TRAPEZOIDAL RULE
b b
I = ∫ f 1 x 2 dx≈ ∫ f 1 1 x 2 dx
a a
∫[
I= f 1 1 x 2=f 1a 2.
f 1 b2 − f 1 a 2
b−a ]
1x − a 2 dx = 1b − a 2
f 1a2.f 1b2
2
a
Error of the Trapezoidal Rule
APPROXIMATE or TRUNCATION ERROR ETr≡Ea
1 3
Ea=ETr = − f ′ ′ 1 3 21 b − a 2
12
a/3/b , Better use the average value of f ' '
∫ f 1 x2dx
a
Average (Mean) of f 1 x2 =
b−a
EXAMPLE 21.1
Use the trapezoidal Rule to numerically integrate
2 3 4 5
f 1x2=0.2.25x − 200x .675x − 900x .400x
from a = 0 to b = 0.8. The exact value of the integral can be determined
analytically to be 1.640533.
I = 0.1728
Et =1.640533−0.1728=1.467733
Ea = 2.56
Thus
Composite/Multiple Application Trapezoidal Rule
For n.1 equally spaced base points 1 x 0, x 1, x 2, . . . , xn 2 .
b−a
Consequently, n segments of equal width=h=
n
x1 x2 xn
I = ∫ f 1 x 2 dx . ∫ f 1 x 2 dx . ⋯ . ∫ f 1x 2 dx
x0 x1 xn−1
n−1
f01x2 . 2 ∑ fi 1x2 . fn1x2
[ ]
n−1
=
h
f01x2 . 2 ∑ f i1x2 . fn1x2 =1-
b−a 2
i=1
2 i=1 width -
2n
average height
3
1 b−a 2
Error analysis is then: Ea = − 2 f ' ' 132
0
12n
n
∑ f ' ' 1 3i 2
i=1
f ' ' 13 2 =
where 0
n
Using our matlab script
2 3 4 5
f 1x2 = 0.2.25∗x−200∗x .675∗x −900∗x .400∗x
[ x1=0.0, x2=0.8, n=3000 ]
The value of integration is 1.64053
The approximate error Ea is 2.84444e-07
Question 21.1
4
2
∫ 18.4cosx2 dx
0
Analytically and
by trapezoid rule
This is a script that performs numerical integration using the
TRAPAZOIDAL rule
By Deaa El-Khateeb as a contribution to NUMERICAL ANALYSIS
2014, with help from Mohammad Radwan for a constructive help
F = 8 + 4*cos(x)
x1 : 0, x2 : pi/2, n : 1
The value of integration is : 15.708
The approximate error Ea is : 0.822467
n = 4
The value of integration is : 16.5148
The approximate error Ea is : 0.0514042
Different examples
2 3
f 1x2 = x .x
a = 0, b = 5, n = 1, 4.
n=1
The value of integration is 375
The approximate error Ea is -177.083
n=4
The value of integration is 208.984
The approximate error Ea is -11.0677
2
∫ ln 1x2 dx
1
use n = 5
The value of integration is 0.384632
The approximate error Ea is 0.00166667
2
ln 1x2
∫ dx
1 x
use n = 4
f 1x2= log 1x2/x
[ x1=1 , x2=2 , n=4 ]
The value of integration is 0.235473
The approximate error Ea is 0.00480879
Find the distance from the following data
points
Time Velocity
0 160
0.5 144
1 128
1.5 112
2 96
2.5 80
3 64
3.5 48
4 32
4.5 16
5 0
Can you suggest a way to compute the
APPROXIMATE ERROR?
To compute the approximate error, we computet the forward derivative at the end points
The forward numerical derivative at x = 0
f 1 0.52−f 10 2 144−160
f ' 10 2 = = = −32
0.5 0.5
The backward numerical derivative at x = 5
f 14.52−f 152 16−0
f ' 152 = = = 32
0.5 0.5
Thus
5
∫ f ' ' 132 d 3 =
0f ' ' 1 3 2=
f ' 152−f ' 10 2
5−0
=
64
5
0
3
1 1 b=52−1a=02 2 5
3
64
Ea = − 2
0f ' ' 1 3 2 = − ×
12 1n=102 12×100 5
To compute the approximate error, we computet the forward derivative at the end points
The forward numerical derivative at x = 0
f 1 0.52−f 10 2 144−160
f ' 10 2 = = = −32
0.5 0.5
The backward numerical derivative at x = 5
f 14.52−f 152 16−0
f ' 152 = = = − 32 CORRECTED from 32 ! !
− 0.5 − 0.5
Thus
5
∫ f ' ' 132 d 3 =
0f ' ' 1 3 2=
f ' 152−f ' 10 2
5−0
=
64
5
CORRECTION = 0
0
3
1 1 b=52−1a=02 2 5
3
64
Ea = − 2
0f ' ' 1 3 2 = − × CORRECTION = 0
12 1n=102 12×100 5
160-32*t
x1 = 0 x2 = 5 n = 10
The value of integration is 400
The approximate error Ea is -0
∫ ln 1x2 dx
let ln 1x 2 = u dx = dv
1
dx = du x = v
x
I = xln 1x2−x.c