Anda di halaman 1dari 24

Numerical Integration

• Finding a close approximation of the area under a curve of function f(x).

 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  i2

% Integral Metode Trapezium

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
% mentukan Integral

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
2x 2
y  yi
yi 1  c b  i2 Substitution eq (b)
2x 
yi2  a x2  b x  c c  yi1

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 n1 x
x f (x) dx   Ai 
3
 y1  4y2  2y3  4y4  2y5  ...  2yn 1  4yn  yn 1 
1
i 1

x n1 x  in 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)

% 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 integral dengan metode Simpson
I= (deltx/3) *(y(1)+ (4*sum(y(2:2:m))) + (2*sum(y(3:2:m-1)))+y(m+1));

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 .

Newton-Cotes closed integration formulas. The step size is given by h = (b - a)/n

9
Gauss Quadrature Rule of Integration

Integration

The process of measuring the area under a curve.

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
ba ba
 f (a)  f (b)
2 2

The two-point Gauss Quadrature Rule is an extension of the Trapezoidal Rule


approximation where the arguments of the function are not predetermined as a and b
but as unknowns x1 and x2. In the two-point Gauss Quadrature Rule, the integral is
approximated as
b
I   f (x)dx  c1f (x1 )  c2f (x 2 )
a

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

Equating Equations the two previous two expressions yield

 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
ba ba
c1  ; c2 
2 2
Hence Two-Point Gaussian Quadrature Rule
b
 f (x) dx  c1 f  x1   c 2 f  x 2 
a
ba ba  1  ba  ba ba  1  ba 
 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 ;

% Menentukka nilai pada masing- masing node


for i=1:m+1 ;
x(i)= xb + (i-1)*deltx ;
y(i)= exp(x(i)) ;
end
% Mencari batas-batas quadratur
for i=1:m ;
xl(i)= (x(i+1)-x(i))/2*((-1/sqrt(3))+(x(i)+x(i+1))/2) ;
xR(i)= (x(i+1)-x(i))/2*((1/sqrt(3))+(x(i)+x(i+1))/2);
end
% Menghitung luas
I=0 ;
for i=1:m ;
I= I+(x(i+1)-x(i))/2*(exp(xl(i))+ exp(xR(i))) ;
end

15
Higher Point Gaussian Quadrature Formulas

b
 f (x)dx  c1f (x1 )  c 2 f (x 2 )  c3f (x 3 )
a

is called the three-point Gauss Quadrature Rule.


The coefficients c1, c2, and c3, and the functional arguments x1, x2, and x3 are
calculated by assuming the formula gives exact expressions for integrating a fifth
order polynomial

a 
b
2 3 4 5
 a 0  a1x  a 2 x  a 3 x  a 4 x  a 5 x dx

General n-point rules would approximate the integral

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.

1 n Points Weighting Function


 g(x)dx   ci g(x i ) Factors Arguments
1 i 1 2 c1 = 1.000000000 x1 = -0.577350269
c2 = 1.000000000 x2 = 0.577350269
as shown in Table 1.
3 c1 = 0.555555556 x1 = -0.774596669
c2 = 0.888888889 x2 = 0.000000000
c3 = 0.555555556 x3 = 0.774596669
4 c1 = 0.347854845 x1 = -0.861136312
c2 = 0.652145155 x2 = -0.339981044
c3 = 0.652145155 x3 = 0.339981044
c4 = 0.347854845 x4 = 0.861136312

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

ba ba
m c
Such that: 2
2

Hence
ba ba ba
x t dx  dt
2 2 2
19
Substituting our values of x, and dx into the integral gives us
b 1
ba ba ba
 f (x)dx  f
  t   dt
a 1  2 2  2

Example 1 : Derive the one-point Gaussian Quadrature


b
For an integral Rule  f (x)dx
a
The one-point Gaussian Quadrature Rule is :

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
 

Since the constants a0, and a1 are arbitrary

b  a  c1 b2  a 2
 c1x1
2
giving
ba
c1  b  a x1 
2

Hence One-Point Gaussian Quadrature Rule

b
ba
 f (x) dx  c1f  x1   (b  a) f  
a  2 
21
Example 2

a. Use two-point Gauss Quadrature Rule to approximate the distance covered by a


rocket from t=8 to t=30 as given by
30  
 140000 
y    2000 ln    9.8t  dt
8 140000  2100t  
b. Find the true error, for part (a).

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

Now we can use the Gauss Quadrature formula


1
11  f 11x  19  dx  11c1f 11x1  19   11c2 f 11x 2  19 
1

 11.f 11(0.5773503)  19   11.f 11(0.5773503)  19 

 11.f (12.64915)  11.f (25.35085)

 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

c. The absolute c. relative true error t , is (Exact value  11061.34m)

11061.34  11058.44
t   100%
11061.34

 0.0262%

24

Anda mungkin juga menyukai