Guest User

phase

a guest
Sep 26th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module global_vars
  2.     integer :: N = 100, l = 2
  3.     real :: R = 10.0, V_0 = 2, a = 5.0, lk = 0.1, rk = 10.0, dk = 0.05, k
  4.     save
  5. end module
  6.    
  7. function V(x)
  8.     use global_vars
  9.     real :: V
  10.     real, intent(in) :: x
  11.     if (x < a) then
  12.         V = -V_0
  13.     else
  14.         V = 0.0
  15.     end if
  16.     return
  17. end function
  18.  
  19. recursive function jl(x, l) result(ans)
  20.     real, intent(in) :: x
  21.     real :: ans
  22.     integer, intent(in) :: l
  23.     if (l == 0) then
  24.         ans = sin(x) / x
  25.     else if (l == 1) then
  26.         ans = sin(x) / x**2 - cos(x) / x
  27.     else
  28.         ans = (2 * (l - 1) + 1) * jl(x, l - 1) / x  - jl(x, l - 2)
  29.     end if
  30. end function
  31.  
  32. function jl_hat(x, l)
  33.     real, intent(in) :: x
  34.     integer, intent(in) :: l
  35.     real :: jl, jl_hat
  36.     jl_hat = jl(x, l) * x
  37.     return
  38. end function
  39.  
  40. recursive function nl(x, l) result(ans)
  41.     real, intent(in) :: x
  42.     real :: ans
  43.     integer, intent(in) :: l
  44.     if (l == 0) then
  45.         ans = -cos(x) / x
  46.     else if (l == 1) then
  47.         ans = -cos(x) / x**2 - sin(x) / x
  48.     else
  49.         ans = (2 * (l - 1) + 1) * nl(x, l - 1) / x  - nl(x, l - 2)
  50.     end if
  51. end function
  52.  
  53. function nl_hat(x, l)
  54.     real, intent(in) :: x
  55.     integer, intent(in) :: l
  56.     real :: nl, nl_hat
  57.     nl_hat = nl(x, l) * x
  58. end function
  59.  
  60. function dfac(x)
  61.     integer, intent(in) :: x
  62.     integer :: i, dfac
  63.     dfac = mod(x, 2)
  64.     i = dfac + 2
  65.     do while (i <= x)
  66.         dfac = dfac * i
  67.         i = i + 2
  68.     end do
  69.     return
  70. end function
  71.  
  72. function F(x, delta)
  73.     use global_vars
  74.     real :: nl, jl, jl_hat, nl_hat, F, V
  75.     real, intent(in) :: x, delta
  76.     F = -V(x) * (cos(delta) * jl_hat(k * x, l) - sin(delta) * nl_hat(k * x, l))**2 / k
  77.     return
  78. end function
  79.  
  80. subroutine RungeKutta(h, N, Y)
  81.     implicit none
  82.     integer :: i, N
  83.     real :: k, F, h, x, S(4), Y(N)
  84.     do i = 1, N - 1
  85.         x = h * i
  86.         S(1) =       F(x          , Y(i)                 )
  87.         S(2) = 2.0 * F(x + h / 2.0, Y(i) + h * S(1) / 2.0)
  88.         S(3) = 2.0 * F(x + h / 2.0, Y(i) + h * S(2) / 2.0)
  89.         S(4) =       F(x + h      , Y(i) + h * S(3)      )
  90.         Y(i + 1) = Y(i) + h * sum(S) / 6.0
  91.     end do
  92. end subroutine
  93.  
  94. program phase
  95.     use global_vars
  96.     implicit none
  97.     integer :: i, out = 42, dfac
  98.     real :: V, h
  99.     real, allocatable :: DELTA(:)
  100.     allocate(DELTA(N))
  101.     h = R / N
  102.     k = lk
  103.     open(unit = out, file = "output.txt")
  104.     write(out, *) "k               delta"
  105.     do while (k <= rk)
  106.         DELTA(1) = -V(0.0) * (k * h)**(2 * l + 1) * h**2 / ((2 * l + 3) * dfac(2*l + 1)**2)
  107.         call RungeKutta(h, N, DELTA)
  108.         write(out, *) k, DELTA(N)
  109.         k = k + dk
  110.     end do
  111.     close(out)
  112. end program
Advertisement
Add Comment
Please, Sign In to add comment