Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. subroutine ehpc(m,n,h,x,y,e,choice)
  2.     implicit none
  3.    
  4.     ! Dummy variables
  5.     integer :: m, n, choice
  6.     double precision :: h, e
  7.     double precision, dimension(1:n,0:m) :: y   ! Table of values
  8.     double precision, dimension(0:m) :: x       ! Time t
  9.    
  10.     ! Other variables
  11.     double precision, dimension(1:n) :: y0_i1   ! Initial estimate  
  12.     double precision, dimension(1:n) :: yc_i1   ! Modified initial estimate
  13.     double precision, dimension(1:n) :: yip     ! Previous initial estimate
  14.     double precision, dimension(1:n) :: yx_c    ! Current estimate (corrector)
  15.     double precision, dimension(1:n) :: yx_n    ! Next estimate (corrector)
  16.     double precision, dimension(1:n) :: et      ! Estimation of truncation error
  17.     double precision, dimension(1:n) :: err     ! Current error
  18.     double precision :: k1, k2, k3, k4, ek, s   ! Extra vars
  19.     integer :: i, p
  20.    
  21.     yx_c = 0
  22.     yx_n = 0
  23.     yip  = 0
  24.     do i = 4, m
  25.         y0_i1 = 0
  26.         ! Predictor equation
  27.        
  28.         ! Initial estimate
  29.         do p=1, n
  30.             call f(p, y(:, i-1), k1, choice)
  31.             call f(p, y(:, i-2), k2, choice)
  32.             call f(p, y(:, i-3), k3, choice)
  33.             y0_i1(p) = y(p, i-4) + ((4/3)*h*(2*k1 - k2 + 2*k3))
  34.         end do
  35.        
  36.         ! Improved initial estimate
  37.         do p=1, n
  38.             yc_i1(p) = y0_i1(p) + ((112/121)*(yip(p)))
  39.         end do
  40.        
  41.         yx_c = yc_i1
  42.        
  43.         ! Corrector equation
  44.         do
  45.             ek=0
  46.             s=0
  47.             ! Compute current terms
  48.             do p=1, n
  49.                 call f(p, yx_c,     k4, choice)
  50.                 call f(p, y(:,i-1), k1, choice)
  51.                 call f(p, y(:,i-2), k2, choice)
  52.                 yx_n(p) = ((9/8)*y(p,i-1)) - (y(p,i-3)/8) + ((3/8)*h*(k4+2*k1-k2))
  53.             end do
  54.            
  55.             ! Compute error
  56.            
  57.             do p=1, n
  58.                 err(p) = abs((yx_n(p) - yx_c(p))/yx_n(p))
  59.             end do
  60.            
  61.             ek = sum(err)/n
  62.         !    print *, ek
  63.             if (ek<e) then
  64.                 exit
  65.             else
  66.                 yx_c = yx_n
  67.                 yx_n = 0
  68.             end if            
  69.         end do
  70.        
  71.         ! Estimation of truncation error
  72.         do p=1,n
  73.             et(p) = (-9/121)*(yx_n(p) -y0_i1(p))
  74.         end do
  75.        
  76.         ! Final estimate computation
  77.         do p=1, n
  78.             y(p, i) = yx_n(p) + et(p)
  79.         end do
  80.         x(i) = x(i-1) + h
  81.        
  82.         ! For next iteration
  83.         do p=1, n
  84.             yip(p) = yx_n(p) - y0_i1(p)
  85.         end do
  86.     end do
  87. end subroutine ehpc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement