首先,对于西班牙语注释感到抱歉。
program gauss
implicit none
integer, parameter :: d=30
real*8, dimension(d, d+1) :: a
real*8, dimension(d) :: b, x
integer :: k, i, n
integer, dimension(d) :: pvt
real*8 :: eps = 0.0000001
!Lectura matriz
character (len=32) :: nombre
print*, 'Dame el nombre del fichero de datos'
read*, nombre
open (unit=1, file=nombre, status='OLD')
read(1,*) n
do i=1, n
read(1,*) a(i,1:n)
end do
read(1,*) b(1:n)
close(unit=1)
a(1:n,n+1) = b(1:n)
!Eliminación gaussiana
do k=1,n-1
!Búsqueda del pivote
pvt(k:k) = maxloc(abs(a(k:n,k))) + k-1
if (abs(a(pvt(k),k)) <= eps) stop 'matriz singular'
!Intercambio de filas
if(pvt(k) /= k) then
a(n+1,1:n+1) = a(pvt(k),1:n+1)
a(pvt(k),1:n+1) = a(k,1:n+1)
a(k,1:n+1) = a(n+1,1:n+1)
end if
do i=k+1,n
a(i,k) = a(i,k)/a(k,k)
a(i,k+1:n+1) = a(i,k+1:n+1) - a(i,k)*a(k,k+1:n+1)
end do
end do
!a(n,n) == 0?
if (abs(a(n,n)) <= eps) stop 'matriz singular'
!Sustitución regresiva
do i=n,1,-1
x(i) = (a(i,n+1) - dot_product(a(i,i+1:n),x(i+1:n)))/a(i,i)
end do
print*, 'Solucion:'
print*, x(1:n)
end program gauss
我已经在我的学位上编写了这个程序用于简单的实验室练习,当我在那里运行它时,它运行得很好。但是,我刚刚将mingw编译器安装回家,当我运行程序并输入文件名时,我收到以下错误:
Porgram received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 ffffffffffffffff
#1 ffffffffffffffff
#2 ffffffffffffffff
#3 ffffffffffffffff
#4 ffffffffffffffff
#5 ffffffffffffffff
#6 ffffffffffffffff
#7 ffffffffffffffff
#8 ffffffffffffffff
#9 ffffffffffffffff
#10 ffffffffffffffff
#11 ffffffffffffffff
#12 ffffffffffffffff
#13 ffffffffffffffff
#14 ffffffffffffffff
#15 ffffffffffffffff
#16 ffffffffffffffff
#17 ffffffffffffffff
#18 ffffffffffffffff
#19 ffffffffffffffff
我用作输入的文件只是
5
0 1 0 0 0
0 0 0 0 1
1 0 0 0 0
0 0 1 0 0
0 0 0 1 0
1 2 3 4 5
我不知道可能会发生什么,因为正如我所说的那样,当我在另一台计算机上执行此操作时,相同的代码和矩阵工作正常。