! Program to find the value of integration using Simpson's 1/3 rule
write(*,*)'Enter the values of lower and upper limit of integration respectively:'
read(*,*)a,b
k=4
write(*,*)'Enter the number of even sub intervals:'
read(*,*)n
sum=f(a)+f(b)
h=(b-a)/n
do i=1,n-1
sum=sum+k*f(a+i*h)
k=6-k
end do
sum=sum*h/3.0
write(*,10)sum
10 format(2x,'The value of integration is',f16.3)
end
! Program sub function
function f(x)
f=sqrt(x)*exp(-x)
return
end
write(*,*)'Enter the values of lower and upper limit of integration respectively:'
read(*,*)a,b
k=4
write(*,*)'Enter the number of even sub intervals:'
read(*,*)n
sum=f(a)+f(b)
h=(b-a)/n
do i=1,n-1
sum=sum+k*f(a+i*h)
k=6-k
end do
sum=sum*h/3.0
write(*,10)sum
10 format(2x,'The value of integration is',f16.3)
end
! Program sub function
function f(x)
f=sqrt(x)*exp(-x)
return
end
Comments
Post a Comment