View difference between Paste ID: UQfWzGN3 and ycSUHbDL
SHOW: | | - or go back to the newest paste.
1-
program riemann
1+
module functions
2-
implicit none
2+
contains
3
  function f(x)
4-
integer :: i,N
4+
    implicit none
5-
real :: integ,a,b,dx,x
5+
    real :: f
6
    integer,intent(in) :: x
7-
! zerando as variaveis
7+
8-
integ = 0.
8+
    f = EXP(real(x))
9-
x=0.
9+
10-
dx=0.
10+
  end function
11-
 
11+
end module
12-
print *,"Digite os limites a,b e o numero N de intervalos:"
12+
13-
print *,"Use N grande, ex: 1000"
13+
program trapezio
14-
read *,a,b,N
14+
  use functions
15
  implicit none
16-
dx = (b-a)/real(N)
16+
17
  integer :: i, n, b, a
18-
!integ = 0.5*(f(a)+f(b))
18+
  real :: sumation, mean, deltax, integral
19
20-
do i = 1,N
20+
21-
    x = a + i*dx
21+
  ! The value of the integral using the trapezium rule can be found using
22-
    integ = integ + f(x)*dx
22+
  ! integral = (b - a)*((f(a) +f(b))/2 + sumation_1_n-1 )/n 
23-
enddo
23+
24
  write(*,*) "type the limits b, a and the number of intervals"
25-
print *,'Integral = ', integ
25+
  read *, b, a, n
26-
 
26+
27-
stop '>>> Fim do Programa'
27+
  deltax = real(b - a)/real(n)
28
  mean = (f(a) + f(b))/2
29-
 contains
29+
  sumation = 0
30-
real function f(x)
30+
31-
real :: x
31+
  do i = 1, n-1  
32-
! f(x) = x^2
32+
    sumation = sumation + f(i)
33-
 f = x**2.
33+
  end do
34-
return 
34+
35-
end function f
35+
36
  integral = deltax*(mean + sumation) 
37-
end program riemann
37+
  write (*,*) "the value of the integral using the trapezoidal method is", integral
38
39
end program trapezio