next up previous contents
Next: Test Problem. Up: Numerical Integration Previous: Example.   Contents

Homework

Write two subroutines that compute the integral


by Trapezoidal and Simpson methods respectively.

The user will provide the function f, the interval endpoints a and b, and the tolerance tol.

The routines will return , and respectively. The number of node points n should be a power of 2 (). n is automatically selected by the routine such that the numerical result approximates the true integral within tol ( , and respectively). The routines will also return ierr, a state variable. ierr=0 means that the integration did not succeed; if the integration was successfull, then ierr returns the number of node points n.

The trapezoidal routine header and the declarations part should look like

subroutine trap(f,a,b,tol,T,ierr)
implicit none
interface
real function f(x)
real, intent(in) :: x
end function f
end interface
real, intent(in) :: a,b,tol
real, intent(out) :: T
integer, intent(out) :: ierr

The Simpson routine header and the declarations part should look like

subroutine simpson(f,a,b,tol,S,ierr)
implicit none
interface
real function f(x)
real, intent(in) :: x
end function f
end interface
real, intent(in) :: a,b,tol
real, intent(out) :: S
integer, intent(out) :: ierr

You need to insert detailed comments about the meaning of input, output and local variables, and about the computational algorithm.

Both routines will reside in the same file, named integration.f90.


next up previous contents
Next: Test Problem. Up: Numerical Integration Previous: Example.   Contents
Adrian Sandu 2001-08-26