SHARE
TWEET

integrate_body

starm100 Apr 2nd, 2019 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program lab2
  2. use integrate
  3. implicit none
  4. real(8)::a,b,eps,h,s=0,z=0
  5. integer::i,method,n,k
  6. byte::ok=0
  7. interface !If a procedure has another procedure as dummy argument then one has to specify its type, just as the type of other parameters.
  8.           !An interface block is used for this case. It consists of the procedure statement with the definitions of its arguments.
  9.     real(8) function f(x)
  10.     real(8) :: x
  11.     end function f
  12.  
  13. end interface
  14.  
  15. print*, 'Input a,b,n,and eps'
  16. read(*,*) a,b,n,eps
  17. print*,'Choose method (1-left rect.,2-right,3-midpoint,4-trapezoidal,5-simpsons)'
  18. read(*,*) method
  19. do while (ok .EQ. 0)
  20.     select case (method) !Выбор метода
  21.         case (1)
  22.             k=1
  23.             call left(a,b,n,s,f)
  24.             n=n*2
  25.             call left(a,b,n,z,f)
  26.         case (2)
  27.             k=1
  28.             call right(a,b,n,s,f)
  29.             n=n*2
  30.             call right(a,b,n,z,f)
  31.         case (3)
  32.             k=2
  33.             call mid(a,b,n,s,f)
  34.             n=n*2
  35.             call mid(a,b,n,z,f)
  36.         case (4)
  37.             k=2
  38.             call tr(a,b,n,s,f)
  39.             n=n*2
  40.             call tr(a,b,n,z,f)
  41.         case (5)
  42.             k=4
  43.             call sim(a,b,n,s,f)
  44.             n=n*2
  45.             call sim(a,b,n,z,f)
  46.         case default
  47.             print*, 'Error'
  48.         end select
  49.     if (abs(z-s)/(2**k-1).LT.eps) then
  50.         s=z
  51.         ok=1
  52.     end if
  53. end do
  54. print*, 'Results::'
  55. print*, 'n=',n
  56. print*, 'sum=',s
  57. end program lab2
  58.    
  59.     function f(x)
  60.     implicit none
  61.     real(8)::f,x
  62.     f=3*sin(x-4)-x**5+5
  63.     end function f
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top