[Fortran] 纯文本查看 复制代码
! Gaussian elimination
DO k = 1, n
! Pivot row operations
m1=k+p
if(k+p>n)then
m1=n
end if
DO i = k + 1, m1
factor = matrix(i, k) / matrix(k, k)
m2=k+q
if(k+q>n)then
m2=n
end if
if(i==5 .and. k==3)then
print*, '第三次消元:',Matrix(i,k), Matrix(k,k),factor !???????????
end if
matrix(i, k:m2) = matrix(i, k:m2) - (factor * matrix(k, k:m2))
matrix(i, n+1) = matrix(i, n+1) - factor * matrix(k,n+1)
END DO
END DO
! Back substitution
DO i = n, 1, -1
x(i) = matrix(i, n + 1) / matrix(i, i)
DO j = i + 1, n
x(i) = x(i) - matrix(i, j) * x(j) / matrix(i, i)
END DO
END DO