Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Algoritmo Gauss Fortran
Algoritmo Gauss Fortran
PROGRAM Gauss
Integer n
Real a(380,381),x(380)
Call Datos(n,a)
Call Eligauss(n,a,x)
Call Resul(n,x)
END PROGRAM
Subroutine Datos(n,a)
Integer i,j
Real a(380,381)
Character Titulo*20
open(3,File = 'Datos1.txt')
read (3,*) Titulo
read (3,*) n
Do i = 1,n
read (3,*) (a(i,j),j=1,n+1)
End Do
close(3)
write(*,*) Titulo
Do i=1,n
write(*,*)(a(i,j),j=1,n+1)
End Do
Return
End Subroutine Datos
Subroutine Eligauss(n,a,x)
Integer p,i,j,k
Real a(380,381),x(380),Aux,Suma,m,Max
Do i = 1,n‐1
Max = abs(a(i,i))
p = i
Do j = i+1,n
if (Max.LT.abs(a(j,i))) Then
Max = abs(a(j,i))
p = j
End if
End Do
if (p.NE.i) Then
Do j = 1,n+1
Aux = a(i,j)
a(i,j) = a(p,j)
a(p,j) = Aux
end Do
End if
if (a(i,i).EQ.(0.0))Then
write (*,*) "El sistema no tiene solucion unica"
stop
End if
Do j = i+1,n
Página 1
ALGORITMO GAUSS FORTRAN
m = a(j,i)/a(i,i)
if (m.NE.(0)) Then
Do k = i+1,n+1
a(j,k) = a(j,k) ‐ m*a(i,k)
End Do
End if
End Do
End Do
if ((a(n,n).EQ.(0.0)).AND.(a(n,n+1).EQ.(0.0))) Then
write(*,*)"El sistema tiene infinitas soluciones"
stop
End if
if ((a(n,n).EQ.(0.0)).AND.(a(n,n+1).NE.(0.0))) Then
write(*,*)"El sistema no tiene solucion"
stop
End if
Do i=n,1,‐1
suma=0.0
Do j=i+1,n
suma=suma+a(i,j)*x(j)
End Do
x(i)=(a(i,n+1)‐suma)/a(i,i)
End Do
Return
End Subroutine Eligauss
Subroutine Resul(n,x)
Real x(380)
write(*,*) "Los valores de X son: "
Open(3,File='ValoresDeSolucionesX.txt')
write(3,*) "Los valores de X son: "
Do i = 1,n
write(*,*) x(i)
write(3,*) x(i)
End Do
close(3)
write(*,*) " "
return
End Subroutine Resul
Página 2