Lec 24 Numerical Integral
Lec 24 Numerical Integral
on
Modeling and Simulation
Many subdivisions
can be done
between x=a and
x=b and then a
straight line fit gives
better comparison to
the actual curve.
Many trapezoids
• The same area for two sub-intervals is given by following:
(b − a)
T ( 1) = [ f ( xo ) + 2 f ( x1 ) + f ( x2 ) ]
2×2
(b − a)
T (2) = [ f ( x o ) + 2 f ( x 1 ) + 2 f ( x 2 ) + 2 f ( x 3 ) + f ( x 4 )]
2×4
• When there are eight sub-divisions in the same range [a, b], the area is
(b − a)
T ( 3) = [ f ( xo ) + 2 f ( x1 ) + 2 f ( x2 ) + 2 f ( x3 ) + 2 f ( x 4 )
2×8
+ 2 f ( x 5 ) + 2 f ( x6 ) + 2 f ( x7 ) + f ( x8 ) ]
Many trapezoid
Integral : Area under the curve
• When many sufficiently Strips = 18
small strips are added
we can generate the area f(x)
under the curve from x =
a to x = b with very
small error.
b
g b − g a = ∫ f ( x )dx a b x
a
Here with 18 Strips of different heights and same Width we get the
area under the curve.
Integral for N trapezoids
• The integral in general using N compound trapezoids within
the range, is given by
∆x
Integral ≈ { f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + + 2 f ( x N −1 ) + f ( x N ) }
2
(b − a )
• where, ∆x =
N
• and
xi = a + i∆x, i = 0, 1, 2, 3, , N
f1 = f (4.5) = 0.0494
• The approximate area under the curve is
(4.5 − 2.5)
Area = (0.16 + 0.0494) = 0.2094
2 ×1
Example 1 on integration
• For two subdivisions, we need to have:
f o = f (2.5) = 0.16
f1 = f (3.5) = 0.0816
f 2 = f (4.5) = 0.0494
• Thus
(b − a)
T ( 1)
= [ f ( xo ) + 2 f ( x1 ) + f ( x2 ) ]
2×2
(4.5 − 2.5)
Integral = (0.16 + 2. × 0.0816 + 0.0494)
2× 2
= 1863
Example 1 on integration
• If we divide the interval into four equal parts, then
∆x = (4.5 − 2.5) / 4 = 0.5
f o = f (2.5) = 0.16
f1 = f (4.5) = 0.0494
f1 = f (3.0) = 0.111
f 2 = f (3.5) = 0.0816
f 3 = f (4.0) = 0.0625
(b − a)
T (2) = [ f ( x o ) + 2 f ( x 1 ) + 2 f ( x 2 ) + 2 f ( x 3 ) + f ( x 4 )]
2×4
(4.5 − 2.5)
Integral = [0.16 + 2. × (0.111 + 0.0816 + 0.0625) + 0.0494]
2× 4
Example 1 on integration
∆x
xk
∫ f ( x)dx = { f ( xo ) + 4 f ( x1 ) + f ( x2 )}
x0
3
Simpson’s Rule
• . If we have 2I intervals and apply Simpson's rule repeatedly I
times, the integration formula is
∆x
b
∫
a
f ( x)dx =
3
[ f ( x o ) + 4 f ( x1 ) + 2 f ( x 2 ) + 4 f ( x3 ) + 2 f ( x 4 ) +
+ + 2 f ( x N − 2 ) + 4 f ( x N −1 ) + f ( x N )]
(b − a)(∆x) 4 ( 4 )
error = − f ( ξ)
180
f1 = f (3.5) = 0.0816
f 2 = f (4.5) = 0.0494
Example on Simpson’s Rule
30 30
y y
2
f(x)=1/ x f(x)=1/ x2
20 20
10 10
0
x 0
x
0.2 0.3 0.4 0.5 0.6 0.2 0.3 0.4 0.5 0.6
Example on Simpson’s Rule
• The approximate area under the curve is
(1.0)
Area = (0.16 + 4 × 0.0816 + 0.0494)
3
= 0.1786
f o = f (2.5) = 0.16
f1 = f (3.0) = 0.111
f 2 = f (3.5) = 0.0816
f 3 = f (4.0) = 0.0625
f 2 = f (4.5) = 0.0494
(0.5)
Area = [0.16 + 4 × 0.111 + 2. × 0.0816 + 4 × 0.0625 + 0.0494]
3
= 0.17783
The error is 0.04%.
Example on Simpson’s Rule
• Let us now try a sub-division into 8 equally-spaced sections,
then ∆x = (4.5 − 2.5) / 8 = 0.25
(0.25)
Area = (0.16 + 4 × 0.132 + 2. × 0.111 + 4 × 0.095 + 2 × 0.0816
3
+ 4 × 0.0711 + 2 × 0.0625 + 4 × 0.0554 + 0.0494)
= 0.1778