Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program lab2
- use integrate
- implicit none
- real(8)::a,b,eps,h,s=0,z=0
- integer::i,method,n,k
- byte::ok=0
- interface !If a procedure has another procedure as dummy argument then one has to specify its type, just as the type of other parameters.
- !An interface block is used for this case. It consists of the procedure statement with the definitions of its arguments.
- real(8) function f(x)
- real(8) :: x
- end function f
- end interface
- print*, 'Input a,b,n,and eps'
- read(*,*) a,b,n,eps
- print*,'Choose method (1-left rect.,2-right,3-midpoint,4-trapezoidal,5-simpsons)'
- read(*,*) method
- do while (ok .EQ. 0)
- select case (method) !Выбор метода
- case (1)
- k=1
- call left(a,b,n,s,f)
- n=n*2
- call left(a,b,n,z,f)
- case (2)
- k=1
- call right(a,b,n,s,f)
- n=n*2
- call right(a,b,n,z,f)
- case (3)
- k=2
- call mid(a,b,n,s,f)
- n=n*2
- call mid(a,b,n,z,f)
- case (4)
- k=2
- call tr(a,b,n,s,f)
- n=n*2
- call tr(a,b,n,z,f)
- case (5)
- k=4
- call sim(a,b,n,s,f)
- n=n*2
- call sim(a,b,n,z,f)
- case default
- print*, 'Error'
- end select
- if (abs(z-s)/(2**k-1).LT.eps) then
- s=z
- ok=1
- end if
- end do
- print*, 'Results::'
- print*, 'n=',n
- print*, 'sum=',s
- end program lab2
- function f(x)
- implicit none
- real(8)::f,x
- f=3*sin(x-4)-x**5+5
- end function f
Add Comment
Please, Sign In to add comment