Guest User

Untitled

a guest
Apr 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   1 program trapezoidh3p31
  2.   2 implicit none
  3.   3
  4.   4 double precision :: a,b,h,pi,u,ans,f,iter
  5.   5 integer :: i
  6.   6
  7.   7 pi=4*atan(1.0)
  8.   8 a=0.0d0
  9.   9 b=sqrt(2.0d0)
  10.  10 iter=68659
  11.  11 h=(b-a)/iter
  12.  12 ans=0.0d0
  13.  13 u=a
  14.  14
  15.  15 ans=ans+(2.0d0/sqrt(pi))*f(a)
  16.  16 ans=ans+(2.0d0/sqrt(pi))*f(b)
  17.  17 do i=1,iter-1
  18.  18    u=u+h
  19.  19    ans=ans+2*(2.0d0/sqrt(pi))*f(u)
  20.  20 end do
  21.  21 ans=(h/2.0d0)*ans
  22.  22 print* , "Answer is:"
  23.  23 print* , ans
  24.  24 stop
  25.  25 end
  26.  26
  27.  27
  28.  28
  29.  29 double precision function f(u)
  30.  30 implicit none
  31.  31
  32.  32 double precision :: u
  33.  33
  34.  34 f=exp(-u**2)
  35.  35
  36.  36 return
  37.  37 end
Add Comment
Please, Sign In to add comment