Este es un método empleado para resolver sistemas de ecuaciones, en nuestro caso marices.
program principal
use Gauss1
implicit none
real,allocatable:: A(:,:),b(:),x(:)
integer::Ierr,n,i,j
write(*,*)'introduce la dimension de la matriz'
read(*,*) n
allocate(A(n,n),stat=Ierr)
allocate(b(n),stat=Ierr)
allocate(x(n),stat=Ierr)
if (Ierr>0) stop
write(*,*)'introduce los elementos de la matriz'
A(1,1)=2
A(1,2)=0
A(1,3)=1
A(2,1)=1.5
A(2,2)=5
A(2,3)=3
A(3,1)=0
A(3,2)=1
A(3,3)=1.5
write(*,*)'introduce las componentes del vector de soluciones'
b(1)=1
b(2)=2
b(3)=3
call Gauss1(A,b,x)
write(*,*)x
end program
Module Numerico:
subroutine GAUSS1(A,b,x)
real,intent(INOUT)::A(:,:)
real,intent(INOUT)::b(:)
real,intent(OUT)::x(:)
real::suma
integer::i,j,k,n
n=size(b)
!PASO DE ELIMINACION:
do k=1,n-1
do i=k+1,n
do j=k+1,n
A(i,j)=A(i,j)-(A(i,k)/A(k,k))*A(k,j)
end do
B(I)=B(I)-(A(I,K)/A(K,K))*(B(K))
END DO
END DO
!PASO DE SUSTITUCION
X(N)=B(N)/A(N,N)
DO I=N-1,1,-1
SUMA=0
DO J=I+1,N
SUMA=SUMA+A(I,J)*X(J)
END DO
X(I)=(B(I)-SUMA)/A(I,I)
END DO
END SUBROUTINE Gauss1
Module Funciones:
module funciones
contains
function f1(y)
real,intent(in)::y
real::f1
f1=(((-0.809524)*(y**2))-((-0.928571))*(sin(y)))
end function
end module funciones
Programa Principal:
program principal
use Gauss1
implicit none
real,allocatable:: A(:,:),b(:),x(:)
integer::Ierr,n,i,j
write(*,*)'introduce la dimension de la matriz'
read(*,*) n
allocate(A(n,n),stat=Ierr)
allocate(b(n),stat=Ierr)
allocate(x(n),stat=Ierr)
if (Ierr>0) stop
write(*,*)'introduce los elementos de la matriz'
A(1,1)=2
A(1,2)=0
A(1,3)=1
A(2,1)=1.5
A(2,2)=5
A(2,3)=3
A(3,1)=0
A(3,2)=1
A(3,3)=1.5
write(*,*)'introduce las componentes del vector de soluciones'
b(1)=1
b(2)=2
b(3)=3
call Gauss1(A,b,x)
write(*,*)x
end program
Module Numerico:
subroutine GAUSS1(A,b,x)
real,intent(INOUT)::A(:,:)
real,intent(INOUT)::b(:)
real,intent(OUT)::x(:)
real::suma
integer::i,j,k,n
n=size(b)
!PASO DE ELIMINACION:
do k=1,n-1
do i=k+1,n
do j=k+1,n
A(i,j)=A(i,j)-(A(i,k)/A(k,k))*A(k,j)
end do
B(I)=B(I)-(A(I,K)/A(K,K))*(B(K))
END DO
END DO
!PASO DE SUSTITUCION
X(N)=B(N)/A(N,N)
DO I=N-1,1,-1
SUMA=0
DO J=I+1,N
SUMA=SUMA+A(I,J)*X(J)
END DO
X(I)=(B(I)-SUMA)/A(I,I)
END DO
END SUBROUTINE Gauss1
Module Funciones:
module funciones
contains
function f1(y)
real,intent(in)::y
real::f1
f1=(((-0.809524)*(y**2))-((-0.928571))*(sin(y)))
end function
end module funciones
use Gauss1
ResponderEliminar1
Fatal Error: Can't open module file 'gauss1.mod' for reading at (1): No such file or directory
compilation terminated.
tengo un problema con la subrutina, me aparcece esto: "Required interface for passing assumed shape array is missing from original source. [A] ". AYUDAAA Que puedo hacer?
ResponderEliminar