在fortran中排名不匹配

时间:2013-10-22 16:30:05

标签: fortran rank mismatch

执行此功能时:

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不兼容

1 个答案:

答案 0 :(得分:0)

如果X应为n,则需要为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))
...

或者,您可以将Rn定义为

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

并保持代码不变。


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

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

代码没有变化......