zrhans

Integração - Método do Trapézio

Jun 15th, 2014
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module functions
  2. contains
  3.   function f(x)
  4.     implicit none
  5.     real :: f
  6.     integer,intent(in) :: x
  7.  
  8.     f = EXP(real(x))
  9.  
  10.   end function
  11. end module
  12.  
  13. program trapezio
  14.   use functions
  15.   implicit none
  16.  
  17.   integer :: i, n, b, a
  18.   real :: sumation, mean, deltax, integral
  19.  
  20.  
  21.   ! The value of the integral using the trapezium rule can be found using
  22.   ! integral = (b - a)*((f(a) +f(b))/2 + sumation_1_n-1 )/n
  23.  
  24.   write(*,*) "type the limits b, a and the number of intervals"
  25.   read *, b, a, n
  26.  
  27.   deltax = real(b - a)/real(n)
  28.   mean = (f(a) + f(b))/2
  29.   sumation = 0
  30.  
  31.   do i = 1, n-1  
  32.     sumation = sumation + f(i)
  33.   end do
  34.  
  35.  
  36.   integral = deltax*(mean + sumation)
  37.   write (*,*) "the value of the integral using the trapezoidal method is", integral
  38.  
  39. end program trapezio
Advertisement
Add Comment
Please, Sign In to add comment