[
The goal of the lab is to develop for Fortran code to perform numerical integration. This code will be developed further next week as part of an assignment.
Some things you'll need to know:
The following program implements the Trapezoid Rule to approximate
program numint
implicit none
integer n
real a, b, j
print*, 'a, b, n, = ?'
read*, a, b, n
call trap(a, b, n, j)
print*, 'Int f(x) dx =', j
end program numint
! **************
real function f(x)
real x
f = x/(1.0 + x*x)
end function f
! ***************
subroutine trap(a, b, n, j)
implicit none
real, intent(in) :: a,b
integer, intent(in) :: n
real, intent(out) :: j
real h, x, f
integer i
h = (b - a)/n
j = f(a)
x = a
loopi: do i = 1,n-1
x = x + h
j = j + 2.0*f(x)
end do loopi
j = j + f(b)
j = j * h/2.0
end
Complete the following table:
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
Next Week: you will have to