starm100

integrate_lib

Apr 2nd, 2019
200
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module integrate
  2. contains
  3.    
  4. subroutine left(a,b,n,s,f)
  5. implicit none
  6. real(8)::a,b,h,s,f,x
  7. integer::i,n
  8.     h=(b-a)/n
  9. do i=0,(n-1)
  10.     x=a+h*i
  11.     s=s+f(x)
  12. end do
  13. s=s*h
  14. end subroutine left
  15.  
  16. subroutine right(a,b,n,s,f)
  17. implicit none
  18. real(8)::a,b,h,s,f,x
  19. integer::i,n
  20. h=(b-a)/n
  21. do i=1,n
  22.     x=a+h*i
  23.     s=s+f(x)
  24. end do
  25. s=s*h
  26. end subroutine right
  27.  
  28. subroutine mid(a,b,n,s,f)
  29. implicit none
  30. real(8)::a,b,h,s,f,x
  31. integer::i,n
  32. h=(b-a)/n
  33. do i=1,n
  34.     x=a+h*(i-1/2)
  35.     s=s+f(x)
  36. end do
  37. s=s*h
  38. end subroutine mid
  39.  
  40. subroutine tr(a,b,n,s,f)
  41. implicit none
  42. real(8)::a,b,h,s,f,x
  43. integer::i,n
  44. h=(b-a)/n
  45. s=(f(a)+f(b))/2
  46. do i=1,(n-1)
  47.     x=a+h*i
  48.     s=s+f(x)
  49. end do
  50. s=s*h
  51. end subroutine tr
  52.  
  53. subroutine sim(a,b,n,s,f)
  54. implicit none
  55. real(8)::a,b,h,s,s1,s2,f
  56. integer::i,n
  57. s1=0
  58. s2=0
  59. h=(b-a)/(2*n)
  60. s=f(a)+f(b)
  61. do i=1,(n-1)
  62.     s1=s1+f(a+(2*i)*h)
  63. end do
  64. s1=s1*2
  65. do i=1,n
  66.     s2=s2+f(a+(2*i-1)*h)
  67. end do
  68. s2=s2*4
  69. s=(s+s2+s1)*h/3
  70. print*,s
  71. end subroutine sim
  72.  
  73. end module integrate
RAW Paste Data