Trapezoid Method
y y
A1 x 1 2
2
y y3
A 2 x 2
2
.
.
.
y y n 1
A n x n
2
1
b
A f (x) dx A1 A 2 A3 .... A n x y 2y 2y .... 2y y
a 1 2 3 n n 1
2
x n
A y1 2 yi y n 1
2 i2
clc;
close all;
clear all;
% contoh untuk fungsi exp(x)
% Panjang interval ;
m = 4; % jumlah interval harus genap
deltx = (xa-xb)/m ; % jarak interval ;
I= deltx/2*(y(1)+2*sum(y(2:m))+y(m+1)) ;
2
Simpson 1/3 Method
x
x 2
ax 3 bx 2
A 2 strip (ax bx c) dx cx (a)
x
3 2 x
2 2
A 2 strip a x 2 c x (b)
3
3
The constans a and c can be determined from fact that point (-Δx, yi) ,(0,yi+1) (Δx,yi+2) must
statisfy equation y = ax2 + bx + c.
yi 2 yi 1 yi 2
yi a x 2 b x c a
2x 2
y yi
yi 1 c b i2 Substitution eq (b)
2x
yi2 a x2 b x c c yi1
x
A 2 strip yi 4yi 1 yi 2
3
4
x
A1 y1 4 y 2 y3
3
x
A2 y3 4 y 4 y5
3
x
A3 y 4 4 y5 y 6
3
x
.
A
. n/2
y n 1 4 y n y n 1
Summing this area 3
.
i n/2
x n1 x
x f (x) dx Ai
3
y1 4y2 2y3 4y4 2y5 ... 2yn 1 4yn yn 1
1
i 1
x n1 x in i n 1
x1 f ( x ) dx y1 4 yi 2 yi y n 1
3
i 2, 4,6,.. i 3,5,7,..
5
% Program Integral Simpson 1/3 (1)
clc;
close all;
clear all;
% contoh untuk fungsi exp(x)
% Batas batas integral
xb =input('Batas bawah integral =');
xa =input('Batas atas integral integral =');
% Panjang interval ;
m = 4; % jumlah interval harus genap
deltx = (xa-xb)/m ; % jarak interval ;
% Menentukka nilai pada masing- masing node
for i=1:m+1 ;
x(i)= xb + (i-1)*deltx ;
y(i)= exp(x(i)) ;
end
% menghitung jumlah noda genap
sum1 =0 ;
for i=2:2:m
sum1=sum1+y(i);
end
% menghitung jumlah nona ganjil
sum2= 0 ;
for i=3:2:m-1
sum2=sum2+y(i);
end
% Menghitung integral dengan metode Simpson
I= (deltx/3) *(y(1)+ (4*sum1) + (2*sum2)+y(m+1));
% Program Integral Simpson 1/3 (2)
clc;
close all;
clear all;
% contoh untuk fungsi exp(x)
% Panjang interval ;
m = 4; % jumlah interval harus genap
deltx = (xa-xb)/m ; % jarak interval ;
7
% Program Integral Simpson 1/3 (3)
clc;
close all;
clear all;
% contoh untuk fungsi exp(x)
% Batas batas integral
xb =input('Batas bawah integral =');
xa =input('Batas atas integral integral =');
% Panjang interval ;
m = 4; % jumlah interval harus genap
deltx = (xa-xb)/m ; % jarak interval ;
% Menentukka nilai pada masing- masing node
for i=1:m+1 ;
x(i)= xb + (i-1)*deltx ;
y(i)= exp(x(i)) ;
end
% menghitung masing luas eleen
for i=2:2:m
k=i/2;
A(k)= deltx/3*(y(i-1)+4*y(i)+y(i+1));
end
I=sum(A); % integral
8
HIGHER-ORDER NEWTON-COTES FORMULAS
The trapezoidal rule and both of Simpson’s rules are members of a family of integrating
equations known as the Newton-Cotes closed integration formulas .
9
Gauss Quadrature Rule of Integration
Integration
b
I f (x)dx
a
Where:
f(x) is the integrand
a= lower limit of integration
b= upper limit of integration
10
Basis of the Gaussian Quadrature Rule
Previously, the Trapezoidal Rule was developed . The result of that development is
summarized below.
b
f (x)dx c1f (a) c2f (b)
a
ba ba
f (a) f (b)
2 2
11
The four unknowns x1, x2, c1 and c2 are found by assuming that the formula gives
exact results for integrating a general third order polynomial,
f (x) a 0 a1x a 2 x 2 a 3 x 3.
Hence
a
b b
2 3
f (x)dx a 0 a1x a 2 x a 3 x dx
a
2 3 4 b
x x x
a 0 x a1 a2 a3
2 3 4
a
b2 a 2 b3 a 3 b4 a 4
a 0 b a a1 a a
2 2 3 3 4
12
It follows that
b
2 3 2 3
f (x)dx c1 a 0 a1x1 a 2 x1 a 3 x1 c2 a 0 a1x 2 a 2 x 2 a 3 x 2
a
b2 a 2 b3 a 3 b4 a 4
a 0 b a a1 a a
2 2 3 3 4
c1 a 0 a1x1 a 2 x12 a 3 x13 c 2 a 0 a1x 2 a 2 x 22 a 3 x 23
a 0 c1 c 2 a1 c1x1 c 2 x 2 a 2 c1x12 c 2 x 22 a 3 c1x13 c 2 x 23
13
Since the constants a0, a1, a2, a3 are arbitrary
b2 a 2
b a c1 c 2 ; c1x1 c 2 x 2 ;
2
b3 a 3 2 2 b4 a 4
c1x1 c 2 x 2 ; c1x13 c 2 x 23
3 4
four simultaneous nonlinear Equations have only one acceptable solution
b a 1 b a b a 1 b a
x1 ; x
2 ;
2 3 2 2 3 2
ba ba
c1 ; c2
2 2
Hence Two-Point Gaussian Quadrature Rule
b
f (x) dx c1 f x1 c 2 f x 2
a
ba ba 1 ba ba ba 1 ba
f f
2 2 3 2 2 2 3 2
14
% Program Integral Gauss Quadratur 2 point
clc;
close all;
clear all;
% contoh untuk fungsi exp(x)
% Batas batas integral
xb =input('Batas bawah integral =');
xa =input('Batas atas integral integral =');
% Panjang interval ;
m = input('Jumlah interval =');
deltx =(xa-xb)/m ; % jarak interval ;
15
Higher Point Gaussian Quadrature Formulas
b
f (x)dx c1f (x1 ) c 2 f (x 2 ) c3f (x 3 )
a
a
b
2 3 4 5
a 0 a1x a 2 x a 3 x a 4 x a 5 x dx
b
f (x)dx c1f (x1 ) c 2 f (x 2 ) . . . . . . . c n f (x n )
a
16
Arguments and Weighing Factors for n-point Gauss
Quadrature Formulas
Coefficients and arguments given for n-point Gauss Quadrature Rule are given for
integrals
Table 1: Weighting factors c and function arguments x
used in Gauss Quadrature Formulas.
17
Table 1 : Weighting factors c and function arguments x used in Gauss
Quadrature Formulas.
Weighting Function
Points
Factors Arguments
c1 = 0.236926885 x1 = -0.906179846
c2 = 0.478628670 x2 = -0.538469310
5 c3 = 0.568888889 x3 = 0.000000000
c4 = 0.478628670 x4 = 0.538469310
c5 = 0.236926885 x5 = 0.906179846
c1 = 0.171324492 x1 = -0.932469514
c2 = 0.360761573 x2 = -0.661209386
c3 = 0.467913935 x3 = -0.2386191860
6
c4 = 0.467913935 x4 = 0.2386191860
c5 = 0.360761573 x5 = 0.661209386
c6 = 0.171324492 x6 = 0.932469514
18
Arguments and Weighing Factors for n-point Gauss Quadrature Formulas
1 b
So if the table is given for g(x) dx integrals, how does one solve f (x ) dx ?
1 a
The answer lies in that any integral with limits of [a,b] can be converted into an
integral with limits [-1,1] .
Let x mt c
If x = a then t = -1
If x = b then t = 1
ba ba
m c
Such that: 2
2
Hence
ba ba ba
x t dx dt
2 2 2
19
Substituting our values of x, and dx into the integral gives us
b 1
ba ba ba
f (x)dx f
t dt
a 1 2 2 2
b
f (x)dx c1f x1
a
The two unknowns x1, and c1 are found by assuming that the formula gives exact
results for integrating a general first order polynomial,
f (x) a 0 a1x.
b
b b x2 b2 a 2
f (x) dx a 0 a1x dx a 0 x a1 a 0 b a a1
a a 2 a 2
20
b
It follows that
f (x)dx c1 a 0 a1x1
a
Equating Equations, the two previous two expressions yield :
b2 a 2
a 0 b a a1 c a a x a 0 (c1) a1(c1x1)
2 1 0 1 1
b a c1 b2 a 2
c1x1
2
giving
ba
c1 b a x1
2
b
ba
f (x) dx c1f x1 (b a) f
a 2
21
Example 2
c. Also, find the absolute relative true error, for part (a).
Solution
First, change the limits of integration from [8,30] to [-1,1] by previous relations as
follows
30 30 8 1 30 8 30 8 1
f (t) dt f x dx 11 f 11x 19 dx
8 2 1 2 2 1
22
Next, get weighting factors and function argument values from Table 1 for the
two point rule,
c1 1.000000000 x1 0.577350269
c 2 1.000000000 x 2 0.577350269
11(296.8317) 11(708.4811)
11058.44 m
23
since
140000
f (12.64915) 2000 ln 9.8(12.64915) 296.8317
140000 2100(12.64915)
140000
f (25.35085) 2000ln 9.8(25.35085) 708.4811
140000 2100(25.35085)
a. The true error, Et is :
E t True Value Approximate Value
11061.34 11058.44
11061.34 11058.44
t 100%
11061.34
0.0262%
24