MIDPOINT

 !Program name: MIDPOINT

!Integration of function: 2+cos(2*sqrt(x))

!Interval: 0 to 10

! I=20.13035

 

integer :: k, a, m

real :: h, i, x, n, b

 

 

a=0

b=10.

m=20

i=0.

 

h=(b-a)/m

print *, h

 

do k=1,m

   n=a+(k-0.5)*h

   x=n

   i=i+h*func(x)

   print *, k, n, func(x), i

end do

print *, i

stop

end

 

function func(x) result(f)

real :: f

f=2+cos(2*sqrt(x))

end function func

Comentários

Postagens mais visitadas deste blog

HYDROGEN-RADIAL

HYDROGEN-POTENTIAL

ONE_PART_QHO