Advertisement
Oppaceted

Degree row (sum)

May 18th, 2023
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! 93
  2. !
  3. program main
  4.     use Degree_row_module
  5.     implicit none
  6.     integer :: str, i
  7.     integer, allocatable :: n(:)
  8.     real(8), allocatable :: x(:), y(:), d(:)
  9.     real(8) :: low, high
  10.     real(8), parameter :: E = 1.0e-15
  11.     !
  12.     write (*,'(a$)') 'Enter number of strings: '
  13.     read (*,*) str
  14.     write (*,'(a$)') 'Enter low and high: '
  15.     read (*,*) low, high
  16.     !
  17.     allocate(n(str))
  18.     allocate(x(str))
  19.     allocate(y(str))
  20.     allocate(d(str))
  21.     !
  22.     n(:) = 0
  23.     d(:) = 0.0d0
  24.     y(:) = 0.0d0
  25.     do i =1,str
  26.         x(i) = low + ( ( (high-low)/(str-1) )*(i-1) )
  27.     end do
  28.     call ryad(str,x,n,y,d,E)
  29.     call output(str,x,n,y,d)
  30.     deallocate(n)
  31.     deallocate(x)
  32.     deallocate(y)
  33.     deallocate(d)
  34. end program main
  35.  
  36. module Degree_row_module
  37.     contains
  38.     !
  39.     subroutine output(string,x,n,y,d)
  40.         integer :: string,i
  41.         integer :: n(string)
  42.         real(8) :: x(string),y(string),d(string)
  43.         character(len = 72) :: cap = '+----+----------+------+----------+---------------+'
  44.         write (*,'(a)') cap
  45.         write (*,'(a)') '|  i |    x{i}  | n{i} |   y{i}   |      d{i}     |'
  46.         do i = 1,string
  47.             write (*,'(a)') cap
  48.             write (*,'(a, i3, a, f10.6, a, i6, a, f10.6, a, es15.6, a)') '|', i, ' |', x(i), '|', n(i), '|', y(i),'|',d(i),'|'
  49.         end do
  50.         write (*,'(a)') cap
  51.     end subroutine
  52.     !
  53.     subroutine ryad(str, x, n, y, d, E)
  54.         integer :: str
  55.         real(8) :: x(str), y(str), d(str)
  56.         integer :: n(str)
  57.         integer :: i
  58.         real(8) :: E, ui
  59.         do i =1, str
  60.             n(i) = 0
  61.             y(i) = log(2.0d0)
  62.             ui = -1.0d0
  63.             do while ( (abs(ui) >= (E * abs( y(i) ) ) ) .and. (n(i)<2500) )
  64.                 n(i) = n(i) + 1
  65.                 ui = -ui*x(i)*(0.5d0)
  66.                 y(i) = y(i) + ui/n(i)
  67.             end do
  68.             d(i) = abs( y(i)-log(x(i) + 2.0) )
  69.         end do
  70.     end subroutine
  71. end module
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement