Guest User

Untitled

a guest
May 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program integrate
  2. real*8 n, a, b, k
  3.  
  4. n = 1000
  5. k = 1
  6.  
  7. a = 0
  8. b = 1
  9.  
  10. call int_hopkins(a, b, k, n)
  11.  
  12. end program integrate
  13.  
  14. real*8 function f(x)
  15.     real*8 x
  16.     f = x
  17.     return
  18. end function f
  19.  
  20. real*8 function g(x)
  21.     real*8 x
  22.     g = x
  23.     return
  24. end function g
  25.  
  26. real*8 function dg(x)
  27.     real*8 x
  28.     dg = 0*x + 1
  29.     return
  30. end function
  31.  
  32. real*8 function sinc(x)
  33.     real*8 x
  34.     if(x < 0.000001) then
  35.         sinc = 1
  36.     else
  37.         sinc = dsin(x) / x
  38.     end if
  39.     return
  40. end function sinc
  41.  
  42. subroutine int_hopkins(a, b, k, nx)
  43.     real*8 a, b, nx, k, x, px
  44.     real*8 f, g, dg
  45.     real*8 h, xi, sx
  46.    
  47.     complex*8 I
  48.    
  49.     h = (b - a) / nx
  50.        
  51.     px = a
  52.     x = px + h
  53.    
  54.     I = 0
  55.     do while (x < b)
  56.         xi = (px + x) / 2
  57.         sx = k * dg(xi) * (x - px)
  58.        
  59.         I = I + (x - px) * f(xi) * sinc(sx) * cdexp(CMPLX(0,1) * k * g(xi))        
  60.        
  61.         px = x
  62.         x = x + h
  63.         end do
  64.  
  65.     write(*,*) I
  66.     return    
  67. end subroutine int_hopkins
Add Comment
Please, Sign In to add comment