!    蜿ｰ蠖｢蜑�
!    f(x)=e^(x) 縺ｮ 0<=x<=1 縺ｫ縺翫￠繧狗ｩ榊�
!    蛻�牡謨ｰ縺�1, 2, 4, 8, 16, 32縺ｮ蝣ｴ蜷�
!    2013/08/01 譚第ｩ狗ｩｶ逅�渕 譁ｰ隕丈ｽ懈�
!    2013/08/08 譚第ｩ狗ｩｶ逅�渕 譖ｴ譁ｰ 遨榊�遽�峇繧�99 - 100縺ｫ螟画峩

program daikei2
implicit none

integer :: n     ! 繝ｫ繝ｼ繝怜､画焚
integer :: set   ! 蜿ｰ蠖｢縺ｮ蛻�牡謨ｰ
integer :: setmax ! 蛻�牡謨ｰ縺ｮ譛螟ｧ蛟､
real(8) :: max   ! 遨榊�蛹ｺ髢薙�荳顔ｫｯ
real(8) :: min   ! 遨榊�蛹ｺ髢薙�荳狗ｫｯ
real(8) :: fmax  ! 陲ｫ遨榊�髢｢謨ｰ縺ｮ蠑墓焚max縺ｮ蛟､
real(8) :: fmin  ! 陲ｫ遨榊�髢｢謨ｰ縺ｮ蠑墓焚min縺ｮ蛟､
real(8) :: div   ! 蛻�牡縺励◆荳蛹ｺ髢薙�蟷�
real(8) :: sum   ! 驛ｨ蛻�柱縺ｮ菫晏ｭ倥☆繧句､画焚
real(8) :: f     ! 髢｢謨ｰ縺ｮ蛟､繧定ｨ育ｮ励☆繧句､画焚
real(8) :: res   ! 謨ｰ蛟､險育ｮ励�邨先棡繧貞�繧後ｋ螟画焚
real(8) :: error ! 謨ｰ蛟､隗｣縺ｨ隗｣譫占ｧ｣縺ｮ蟾ｮ縺九ｉ蠕励ｉ繧後ｋ隱､蟾ｮ

! 遨榊�蛹ｺ髢薙�荳顔ｫｯ縺ｨ荳狗ｫｯ繧定ｨｭ螳�
min = 99.0d0
max = 100.0d0

! 遨榊�蛹ｺ髢薙�荳顔ｫｯ縺ｨ荳狗ｫｯ縺ｫ縺翫￠繧矩未謨ｰf縺ｮ蛟､繧定ｨ育ｮ�
fmin = exp(min)
fmax = exp(max)

! 蛻�牡謨ｰ繧呈怙蛻昴�1縺ｫ險ｭ螳�
set = 1
setmax = 512

write(*,*) '蛻�牡謨ｰ, 謨ｰ蛟､隗｣, 隱､蟾ｮ'

! 蛻�牡謨ｰ縺茎etmax縺ｫ縺ｪ繧九∪縺ｧ繝ｫ繝ｼ繝励ｒ蝗槭☆
do while(set <= setmax)

   ! 荳蛹ｺ髢薙�蟷�ｒ險育ｮ�
   div = abs(max - min) / dble(set)

   ! 蜥後ｒ0縺ｧ蛻晄悄蛹�
   sum = 0.0d0

   do n = 1, set - 1
      f = exp(min + dble(n)*div)

      sum = sum + f
      !write(*,*) n
   enddo

   ! 謨ｰ蛟､隗｣縺ｮ險育ｮ�
   res = div*(fmin/2.0d0 + sum + fmax/2.0d0)

   ! 隱､蟾ｮ縺ｮ險育ｮ�
   error = res - (exp(max) - exp(min))

   ! 邨先棡縺ｮ陦ｨ遉ｺ
   !write(*,*) set, error
   write(*, *) set, '&', error, '&'!, error*4.0d0, '\\ \hline'

   ! 蛻�牡謨ｰ繧剃ｺ悟阪↓蠅励ｄ縺�
   set = set * 2

enddo

endprogram