-
Notifications
You must be signed in to change notification settings - Fork 0
/
int.f
42 lines (40 loc) · 954 Bytes
/
int.f
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
42
program int
implicit none
real(8) :: pint,p
print *, ' n ', 'Trapezoidal ',
& 'Simpson ', 'EV ',
& 'Error(T) ', 'Error (S)'
p = pint(50)
p = pint(100)
p = pint(500)
p = pint(1000)
end
function pint(n)
implicit none
integer :: i,n
real(8) :: pint,tr,si,x1,x2,x3,h,f,a,b,ip
a = 0.
b = 3.
tr = 0.
si = 0.
h=(b-a)/n
x1 = a
do i = 1,n
x2 = x1+h
tr = tr+(f(x1)+f(x2))
if ((i/2)*2.ne.i) then
x3 = x2+h
si = si+(f(x1)+4.*f(x2)+f(x3))
end if
x1 = x1+h
end do
tr = tr*h/2.
si = si*h/3.
ip = log(cosh(b))-log(cosh(a))
print*,n,tr,si,ip,abs((ip-tr)/ip),abs((ip-si)/ip)
end
real(8) function f(x)
implicit none
real(8) :: x
f = tanh(x)
end