执行此功能时:
FUNCTION gaussian_elimination(A, C) result(X)
implicit none
real, intent(inout) :: C(:), A(size(C), size(C))
real :: X(size(C))
real :: D(size(C))
integer :: i, j, neq
neq = size(C)
! Forward reduction, only two loops since reduction is now row by row
do i = 1, neq
D = A(:,i)/A(i,i)
do j = i+1, neq
A(j,:) = A(j,:) - D(j)*A(i,:)
C(j) = C(j) - D(j)*C(i)
enddo
enddo
! Back substitution, only one loop
do i = neq, 1, -1
x(i) = (C(i) - sum(A(i, i+1:) * x(i+1:))) / A(i,i)
enddo
end FUNCTION gaussian_elimination
具有以下内容:
real , DIMENSION(6,6) :: K
real , DIMENSION(6,1) :: R
real , DIMENSION(6,1) :: n
n = gaussian_elimination(K,R)
结果:
n = gaussian_elimination(K,R)
1
错误:在 (1) 的分配中不相容的等级 2 和 1