Professional Documents
Culture Documents
Numerical Integration
Numerical Integration
CLASS: 05
Course Teachers :
Dr. Md. Mamun
MD. JAMIL HOSSAIN
Mohd. Aminul Hoque
Sourav Saha
Satyajit Mojumder
Saif Khan Alen
Numerical Integration
9 May 2016
9 May 2016
f(x)
x0
x1
ME262 Numerical Analysis Sessional
xn-1
xn
9 May 2016
fn (x): linear
fn (x): quadratic
fn (x): higher-order
polynomial
9 May 2016
Simpsons 1/3-Rule
6
h
f ( x)dx f ( x0 ) 4 f ( x1 ) f ( x2 )
3
L(x)
f(x)
x0
x1
x2
9 May 2016
6
ba
n
f(x)
...
x0
x1 h
x2 h
x3 h
x4
xn-2
xn-1
xn
x
9 May 2016
h
h
I f ( x0 ) 4 f ( x1 ) f ( x2 ) I = f(x0 )+ 4 f(xi )+ 2 f(xi )+ f(xn )
3
i=1,3,5
i=2,4,6
3
Applicable only if
the number of segments is
even
i=0
. .
n-1 n
9 May 2016
8
h m
I =
f
3 k 1
x2k - 2 + 4f x2k -1
x2k
ba
h
n
x0 x1 x2 x3
x4 x5 x6 . . .
n
m
2
xn-1 xn
9 May 2016
MATLAB Code
10
I xe 2 x dx
0
fvalue.m
function s = fvalue(x)
s = x*exp(2*x);
simpsn3.m
a = 0; b = 4;
n=input(Enter the value of n);
h = (b - a)/n;
S = 0; m = n/2;
for k = 1 : m
S = S + fvalue(a+h*(2*k-2))+4*fvalue(a+h*(2*k-1))+fvalue(a+h*2*k);
end
I = h*S/3;
disp(I);
ME262 Numerical Analysis Sessional
9 May 2016
2x
I
xe
dx
Evaluate the integral
0
n=2
n=4
h
I f (0) 4 f (2) f (4)
3
2
0 4(2e4 ) 4e8 8240.411
3
57.96%
h
f (0) 4 f (1) 2 f (2) 4 f (3) f (4)
3
1
0 4(e2 ) 2(2e4 ) 4(3e6 ) 4e8 5670.975 8.70%
3
9 May 2016
Simpsons 3/8-Rule
12
f(x)
n must be a multiple of 3
m
x0
x1
x2
x3
n
3
3h
f ( x)dx
f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 )
8
3h m
f x3k -3 + 3f x3k -2 3 f x3k -1 f x3k
I=
8 k 1
ME262 Numerical Analysis Sessional
9 May 2016
12
I
Simpsons 1/3-Rule
xe 2 x dx
xe 2 x dx
h
f (0 ) 4 f ( 2 ) f ( 4 )
3
2
0 4 ( 2 e 4 ) 4 e 8 8240.411
3
5216.926 8240.411
57.96%
5216.926
I xe 2 x dx
0
Simpsons 3/8-Rule
3h
4
8
f
(
0
)
3
f
(
)
3
f
(
)
f
(
4
)
8
3
3
3( 4/3 )
0 3( 19.18922 ) 3( 552.33933 ) 11923.832 6819.209
8
5216.926 6819.209
30.71%
5216.926
9 May 2016
I I 1/p3 I 3q/ 8
p
I 1/ 3
q
I 3/8
p
2
h
= f x2j -2 + 4f x2j -1 f x2j
3 j 1
q
3
3h
f x3k -3 + 3f x3k -2 3 f x3k -1 f x3k
8 k 1
p and q must be a multiple of 2 and 3 respectively
ME262 Numerical Analysis Sessional
9 May 2016
9 May 2016
a = 0; b = 4;
p=input('Enter p');
q=input('Enter q');
n=p+q;
h = (b - a)/n;
S1 = 0;
for k = 1 : (p/2)
S1 = S1 + fvalue(a+h*(2*k-2))...
+4*fvalue(a+h*(2*k-1))+fvalue(a+h*2*k);
end
I1 = h*S1/3;
S2 = 0;
%starting point d:
d=a+p*h;
for k = 1 : (q/3)
S2 = S2 + fvalue(d+h*(3*k-3))+3*fvalue(d+h*(3*k-2))...
+3*fvalue(d+h*(3*k-1)) +fvalue(d+h*3*k);
end
I2 = 3*h*S2/8;
16
I=I1+I2
9 May 2016
17
integral
integral2
integral3
quadgk
Numerical integration
quad2d
cumtrapz
trapz
polyint
9 May 2016
18
9 May 2016
19
9 May 2016
Q = trapz(Y)
Q = trapz(X,Y)
20
9 May 2016