viernes, 25 de marzo de 2011

Método de Simpson

Este es un método empleado para la aproximación de integrales de funciones.

Programa principal:
program main

use numerico
use funciones

implicit none
real::Xi,Xd,I
integer::n
write(*,*)'elige un intervalo de integracion'
read(*,*)Xi,Xd
write(*,*)'elige el numero de repeticiones de la integral'
read(*,*)n
call SIMPSON(Xi,Xd,n,I,f)
write(*,*)'por el metodo de simpson la integral es:'
write(*,*)I
end program
Module numerico:
MODULE numerico

CONTAINS

SUBROUTINE SIMPSON(a,b,n,I,F)

INTERFACE
FUNCTION F(X)

REAL,intent(in):: X
REAL:: F

END FUNCTION
END INTERFACE

INTEGER :: j,k
INTEGER, INTENT(IN):: n
REAL :: h,I1,I2
REAL, INTENT(IN) :: a,b
REAL, INTENT(OUT) :: I

h=(b-a)/n*1.0
I1=0 
I2=0

DO j=1,n-1,2

I1=I1+F(a+j*h)


END DO

DO k=2,n-2,2

I2=I2+F(a+k*h)

END DO

I=(h/3)*(F(a)+4*I1+2*I2+F(b))

END SUBROUTINE



end module
Module funciones:
module funciones 
contains 
function f(x)
real,intent(in)::x
real::f
f=x**2
end function 
end module 



2 comentarios: