summaryrefslogtreecommitdiff
path: root/1670/CH8/EX8.14/8_14.sce
blob: 394997551fb672033cd897d5e79ed28d94ad6a50 (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
30
31
32
33
34
35
36
37
38
39
40
41
//Example 8.14
//Trapezoidal Rule
//Page no. 284
clc;close;clear;

ax=1;bx=2;ay=1;by=2;h=0.25
n=(bx-ax)/h+1
n=5;
for i=1:n
    x(i)=ax+(i-1)*h
    y(i)=ay+(i-1)*h
end
printf(' y/x\t|')
for i=1:n
    printf('\t%g\t',x(i))
end
printf('\n--------|-------------------------------------------------------------------------------')
for i=1:n
     printf('\n%g\t|\t',y(i))
    for j=1:n
        z(i,j)=1/(x(j)+y(i))
        printf('%.5g\t\t',z(i,j))
    end
end

//trapezoidal rule
s=0;
for i=1:n
    for j=1:n
        if (i==1 | i==n) & (j==1 | j==n) then
            s=s+z(i,j)
        elseif i==1 | i==n | j==1 | j==n
            s=s+2*z(i,j)
        else
            s=s+4*z(i,j)
        end
    end
end
s=(s*(h^2))/4
printf('\n\n')
disp(s,'Trapezoidal Rule Sum = ')