summaryrefslogtreecommitdiff
path: root/243/CH12/EX12.2/12_02.sce
blob: 56e7eb842e00bce1950a16e6695338d88d263d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Example No. 12_02
//Tapezoidal rule
//Pg No. 376
clear ;close ;clc ;

deff('F = f(x)','F = exp(x)');
a = -1 ;
b = 1 ;

//case(a)
n = 2
h = (b-a)/n 
I = 0
for i = 1:n
    I = I + f(a+(i-1)*h)+f(a+i*h);
end
I = h*I/2 ;
disp(I,'intergral for case(a),Ia = ')

//case(b)
n = 4
h = (b-a)/n 
I = 0
for i = 1:n
    I = I + f(a+(i-1)*h)+f(a+i*h);
end
I = h*I/2 ;
Iexact = 2.35040
disp('n = 4 case is better than n = 2 case',Iexact,'exact integral,Iexact = ',I,'intergral for case(b),Ib = ')