-
Notifications
You must be signed in to change notification settings - Fork 3
/
simpson_int.f
52 lines (46 loc) · 946 Bytes
/
simpson_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
43
44
45
46
47
48
49
50
51
52
implicit none
real*8 x(10000),f(10000),m,h,l,a
integer*8 i,n
m=0
l=0
n=100
open(8,file='int.dat',status='unknown')
do i=1,n,1
read(8,*)x(i),f(i)
enddo
close(8)
do i=2,n-1,2
m=m+4*f(i)
end do
do i=3,n-1,2
l=l+2*f(i)
enddo
a=l+f(1)+f(n)
h=x(2)-x(1)
print*,((m+a)*h)/3.0,'is the area under the curve'
! new method
open(9,file='data.dta' )
do
read(9,*,end=10) c,d
i=i+1
end do
10 close(9)
print*,i
open(9,file='data.dta' )
do j=1,100000
read(9,*) c,d
if(j==1 .and. j==i)then
sum1=sum1+d
else
sum1=sum1+d*2
endif
end do
close(9)
open(9,file='data.dta' )
read(9,*)k
read(9,*)l
area=(l-k)*sum1/2
close(9)
print*, i,area
stop
end