Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module integrate
- contains
- subroutine left(a,b,n,s,f)
- implicit none
- real(8)::a,b,h,s,f,x
- integer::i,n
- h=(b-a)/n
- do i=0,(n-1)
- x=a+h*i
- s=s+f(x)
- end do
- s=s*h
- end subroutine left
- subroutine right(a,b,n,s,f)
- implicit none
- real(8)::a,b,h,s,f,x
- integer::i,n
- h=(b-a)/n
- do i=1,n
- x=a+h*i
- s=s+f(x)
- end do
- s=s*h
- end subroutine right
- subroutine mid(a,b,n,s,f)
- implicit none
- real(8)::a,b,h,s,f,x
- integer::i,n
- h=(b-a)/n
- do i=1,n
- x=a+h*(i-1/2)
- s=s+f(x)
- end do
- s=s*h
- end subroutine mid
- subroutine tr(a,b,n,s,f)
- implicit none
- real(8)::a,b,h,s,f,x
- integer::i,n
- h=(b-a)/n
- s=(f(a)+f(b))/2
- do i=1,(n-1)
- x=a+h*i
- s=s+f(x)
- end do
- s=s*h
- end subroutine tr
- subroutine sim(a,b,n,s,f)
- implicit none
- real(8)::a,b,h,s,s1,s2,f
- integer::i,n
- s1=0
- s2=0
- h=(b-a)/(2*n)
- s=f(a)+f(b)
- do i=1,(n-1)
- s1=s1+f(a+(2*i)*h)
- end do
- s1=s1*2
- do i=1,n
- s2=s2+f(a+(2*i-1)*h)
- end do
- s2=s2*4
- s=(s+s2+s1)*h/3
- print*,s
- end subroutine sim
- end module integrate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement