这是我在 Fortran 90 中的代码
program final
implicit none
real, dimension(421,422) :: a
real :: temp,factor
real, dimension (421) :: soln
integer :: i, rmax, pivot, row,n, O,P,COL,k,a_j,n2,a_i,t
open(unit=177241,file="input_21.txt",status="old")
open(unit=20,file="output.txt",status="unknown")
do i =1,421
read (177241,*) (a(i,:))
end do
do i = 1,421
print *,a(i,13)
end do
do T=1,421
n=421
a_i=n
n2=422
a_j=n2
!pivoting
do pivot = T,n-1
print *, 'pivot=',pivot
rmax = pivot
do row = pivot,a_i
if (ABS(a(rmax,pivot)) < ABS(a(row,pivot)) ) then
rmax=row
end if
end do
if (rmax /= pivot) then
do k=1, a_j
temp = a(rmax,k)
a(rmax,k) = a(pivot,k)
a(pivot,k) = temp
end do
end if
!elimination
do row = pivot+1, n
if ( a(pivot,pivot) /= 0 ) then
factor = (a(row,pivot)) / (a(pivot,pivot))
print *,'factor=',factor
do col = 1, n2
a(row, col) = a(row,col) - a(pivot,col) * factor
print *,'a=',a(row,col)
end do
end if
end do
end do
end do
!back-substitution
soln(n2) = 0
do o=n,1,-1
do p=n2,o+1,-1
a(o,n2) = a(o,n2) - soln(p)*a(o,p)
end do
soln(o) = a(o,n2) / a(o,o)
end do
do i=1,n
print *,soln(i)
write (121,*) soln(i)
end do
end program final
输入文件是 441x442 矩阵 txt 文件。我认为这可以读取该输入文件,但这将是一个无限循环
if ( a(pivot,pivot) /= 0 ) then
factor = (a(row,pivot)) / (a(pivot,pivot))
print *,'factor=',factor
do col = 1, n2
a(row, col) = a(row,col) - a(pivot,col) * factor
我怎么解决这个问题?