Este es otro método para resolver sistemas de ecuaciones similar al de GAUSS.
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 numerico
use funciones
implicit none
real::det
real, allocatable:: A(:,:),L(:,:),U(:,:),b(:),x(:),y(:)
integer::n,Ierr
write(*,*)'introduce la dimension de la matriz A'
read(*,*) n
allocate(A(n,n),L(n,n),U(n,n),b(n),x(n),y(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 LU1(A,b,x,y,det)
write(*,*)x
write(*,*)'el determinante es:',det
end program
Module Numerico:
subroutine LU1(A,b,x,y,det)
real,intent(INOUT)::A(:,:)
real,intent(INOUT)::b(:)
real,intent(inout)::x(:)
real,intent(inout)::y(:)
real::L(3,3),U(3,3),sum1,sum2,sum3,sum4,sum5,det
INTEGER::k,i,n,j,suma1,s
n=size(B)
s=0
do i=1,n
suma1=0
do j=1,n
suma1=suma1+(abs(A(i,j)))
end do
if(abs(A(i,i))>suma1)then
s=(s+1)
end if
end do
if(s==n)then
write(*,*)'la matriz es diagonal dominante'
end if
l=0
u=0
l(1,1)=A(1,1)
u(1,1)=1
!PASO DE DESCOMPOSICION
do K=1,N-1
U(1,K+1)=A(1,K+1)/L(1,1)
DO I=2,K
SUM1=0
DO J=1,I-1
SUM1=SUM1+L(I,J)*U(J,K+1)
END DO
U(I,K+1)=(A(I,K+1)-SUM1)/L(I,I)
END DO
L(K+1,1)=A(K+1,1)
DO I=2,K
SUM2=0
DO J=1,I-1
SUM2=SUM2+ U(J,I)*L(K+1,J)
END DO
L(K+1,I)=A(K+1,I)-SUM2
END DO
U(K+1,K+1)=1
SUM3=0
DO I=1,K
SUM3=SUM3+ L(K+1,I)*U(I,K+1)
END DO
L(K+1,K+1)=A(K+1,K+1)-SUM3
END DO
!PASO DE SUSTITUCION 1
y(1)=B(1)/L(1,1)
DO I=2,N
SUM4=0
DO J=1,I-1
SUM4=SUM4+L(I,J)*y(J)
END DO
y(I)=(b(I)-SUM4)/L(I,I)
END DO
!PASO DE SUSTITUCION 2
X(N)=y(N)/U(N,N)
DO I=N-1,1,-1
SUM5=0
DO J=I+1,N
SUM5=SUM5+U(I,J)*X(J)
END DO
X(I)=(y(I)-SUM5)/U(I,I)
END DO
det=1
do i=1,3
det=det*(L(i,i))
end do
END SUBROUTINE LU1
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