You are on page 1of 2

1.

Simpson 1/3
program simpson sepertiga
implicit none
double precision h,a,b,l,x,s,f,l1,l2
integer n,r
print *, 'Masukkan nilai N genap'
read (*,*),n
a=1.0
b=5.0
l1=0.0
l2=0.0
h=(b-a)/n
x=a
l=f(a)+ f(b)

do r=1,n-1
x=x+h
if (mod(r,2).eq.1)then
l1=l1+4.0*f(x)
else
l2=l2+2.0*f(x)
endif
enddo
l=(l+l1+l2)*h/3.0
print *, 'Maka luasnya adalah',l
stop
end program simpson sepertiga

function f(x)
real*8 f,x
f=x**3
return
end


2. Simpson 3/8
program simpson tigaperdelapan
implicit none
double precision h,a,b,l,x,s,f,l1,l2
integer n,r
print *, 'Masukkan nilai N ganjil'
read (*,*),n
a=1.0
b=5.0
l1=0.0
l2=0.0
h=(b-a)/n
x=a
l=f(a)+ f(b)

do r=1,n-1
x=x+h
if (mod(r,3).eq.0)then
l1=l1+2.0*f(x)
else
l2=l2+3.0*f(x)
endif
enddo

l=(l+l1+l2)*3.0*h/8.0
print *, 'Maka luasnya adalah',l
stop
end program simpson tigaperdelapan

function f(x)
real*8 f,x
f=x**3
return
end

You might also like