Lecture 13 Integration
Lecture 13 Integration
Lecture 13 Integration
NEWTON-COTES FORMULA
TRAPEZOİD RULE
SİMPSON RULE
Integration and differentiation
d t
v(t ) y(t ) y (t ) v(t )dt
0
dt
Why do we need numerical integration?
b b
I f ( x)dx f n ( x)dx
a a
f (b) f (a)
b
I f (a) ( x a) dx First order polynomial
a
ba
Result of integration:
f (a) f (b)
I (b a) “Trapezoidal rule”
2
Error of the Trapezoidal Rule
An estimate for the local truncation error:
1 a<ξ<b
Et f ' ' ( )(b a ) 3
12
If the function being integrated is linear, the trapezoidal rule will be exact
because the second derivative of a straight line is zero.
Otherwise, for functions with second- and higher-order derivatives (i.e., with
curvature), some error can occur.
Example: Numerically integrate from a=0 to b=0.8:
f ( x) 0.2 25x 200x 2 675x3 900 x 4 400x5
Exact value of the integral = 1.640533
Solution:
f (a) f (b)
I (b a)
2
0.2 0.232
I (0.8 0) 0.1728
2
Truncation error:
Et 1.640533 0.1728 1.467733
t 89.5% percent relative error
Actually, we would not know the true value.
error estimate
1
Et f ' ' ( )(b a ) 3
12
2 3
( 400 4050 x 10800 x 8000 x )dx
f ' ' ( x) 0
60
0.8 0
c)
The Composite Trapezoidal Rule
(b a) 3 n f ' ' ( )
i n
Et
12n 3
f ' ' ( )
i 1
i f '' i 1
n
f ' ' ( i ) nf ' '
i 1
(b a) 3
Approximate error Ea 2
f ''
12n
Example: Use the two-segment trapezoidal rule to estimate the integral of
f ( x) 0.2 25x 200x 2 675x3 900 x 4 400x5
from a = 0 to b = 0.8. Estimate the error. Recall that the exact value of the
integral is 1.640533
I f ( x0 ) f ( x1 ) f ( x2 ) dx
x0
( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
a= x0 and b= x2
I f ( x0 ) 4 f ( x1 ) f ( x2 )
h
3
h (b a) / 2
“Simpson’s 1/3 rule” a= x0 b= x2
The label .1/3: h is divided by 3
(b a)
I f ( x0 ) 4 f ( x1 ) f ( x2 )
6
a x0
b x2
(a b) / 2 x1
(b a ) 5 ( 4 )
Et f ( ) Where a< ξ < b
2880
Solution: n = 2 (h = 0.4):
f (0) 0.2
0.2 4(2.456) 0.232
f (0.4) 2.4564 I 0.8 1.367467
6
f (0.8) 0.232
Et 1.640533 1.367467 0.2730667 t 16.6%
(0.8) 5
Approximate error: Ea (2400) 0.2730667
2880
an even number of
segments must be
utilized
to implement the
method
x2 x4 xn
I (b a )
3n
Error estimate
(b a ) 5 ( 4 ) where f (4) is the average fourth
Ea f
180n 4
derivative for the interval
EXAMPLE: Use composite Simson’s rule with n = 4 to estimate the integral of
f ( x) 0.2 25x 200x 2 675x3 900 x 4 400x5
from a = 0 to b = 0.8. Estimate the error. Recall that the exact integral is
1.640533.
Solution. n = 4 (h = 0.2):
I
3h
f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 ) h (b a) / 3
8
“Simpson’s 3/8 rule”
Error:
3h 5 ( 4 ) (b a)5 ( 4 )
Et f ( ) f ( )
80 6480
•The 3/8 rule is somewhat more accurate than the 1/3 rule.
•The 3/8 rule is useful when the number of segments is odd
•The combination of 1/3 rule and 3/8 rule can be used as well.
Example: 1/3 rule to the first two segments and 3/8 rule to the last.
Obtain an estimate with third-order accuracy across the entire
interval
EXAMPLE
(a) Use Simpson’s 3/8 rule to integrate
f ( x) 0.2 25x 200x 2 675x3 900 x 4 400x5
from a = 0 to b = 0.8.
(b) Use it in conjunction with Simpson’s 1/3 rule to integrate the same
function for five segments.
Solution.
(a) A single application of Simpson’s 3/8 rule requires four equally spaced
points:
f (0) 0.2
f (0.2667) 1.432724
f (0.5333) 3.487177
I
0.8
0.2 3(1.432724 3.487177) 0.232 1.51970
8
f (0.8) 0.232
(b) The data needed for a five-segment application (h = 0.16) are
f (0) 0.2 f (0.48) 3.186015
f (0.16) 1.296919 f (0.64) 3.181929
f (0.32) 1.743393 f (0.8) 0.232
The integral for the first two segments is obtained using Simpson’s 1/3 rule:
I
0.32
0.2 4(1.296919) 1.743393 0.3803237
6
For the last three segments, the 3/8 rule can be used to obtain
I
0.48
1.743393 3(3.186015 3.181929) 0.232 1.264754
8
% calculate integral
I=(h/2)*(y(1)+2*sum(y(2:nokta-1))+y(nokta))
I=
41.0811
clc
clear
%simpson 1/3 rule
segment=4;
nokta=2*segment+1;
a=1;
b=5;
h=(b-a)/(2*segment);
x=a:h:b;
% the function
y=x.^2-sin(x);
% calculate the integral
I=(h/3)*(y(1)+4*sum(y(2:2:nokta-1))+2*sum(y(3:2:nokta-
2))+y(nokta))
I=
41.0766
trapz Trapezoidal numerical integration.
Z = trapz(X,Y) computes the integral of Y with respect to X using
the trapezoidal method.
>> I2=quad('x.^2-sin(x)',1,5)
I2 =
41.0767
Integration With Unequal Segments
Solution.
d
b f ( x, y )dx dy b d f ( x, y )dy dx
c a a c
T ( x, y) 2 xy 2 x x 2 2 y 2 72
0
0 4 8m
1- Apply the two-segment trapezoidal rule along the x dimension for each
y value.
These values are integrated along the y-dir to give the final result of 2544.
Dividing this by the area yields the average temperature as 2544/(6 × 8) =
53.
n 1
f ( x0 ) 2 f ( xi ) f ( xn )
Two-segment (n=2) trapozoidal rule: I (b a) i 1
2n