0

执行此功能时:

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

4

1 回答 1

0

您需要指定第二个维度Xifn应该是DIMENSION(6,1)

real :: X(size(C,1),size(C,2))

请注意,您还指定了错误的虚拟参数......它可能应该是:

FUNCTION gaussian_elimination(A, C) result(X)
implicit none
real, intent(inout) :: C(:,:), A(size(C,1), size(C,1))
real :: X(size(C,1),size(C,2))
...

或者,您可以将Rand定义n

real , DIMENSION(6) :: R
real , DIMENSION(6) :: n

并保持您的代码不变。


选项三:您使用数组切片:

n(:,1) = gaussian_elimination(K,R(:,1))

代码没有变化...

于 2013-10-22T16:32:08.640 回答