这是试图解决一个 3*3 的线性方程并打印出结果,但它在注释行中遇到了问题:
我在程序之外定义了模块 LinearSolution,我应该在里面定义它吗?有什么不同?
为什么它说该语句是递归的,你知道,当我将这些语句用作普通子程序而不是模块子程序时,它们被验证为没问题。
module LinearSolution
type LAE
integer::N
double precision,dimension(:,:),allocatable::A
double precision,dimension( :),allocatable::B
contains
procedure,nopass::RowReduction
end type LAE
contains
subroutine RowReduction
double precision::C
do k=1,N
do i=k+1,N
if(A(k,k)/=0) then
C=A(i,k)/A(k,k)
B(i)=B(i)-B(k)*C !error: Statement Function is recursive
do j=k+1,N
A(i,j)=A(i,j)-A(k,j)*C !error: Statement Function is recursive
end do
end if
end do
end do
do k=N,1,-1
do i=k-1,1,-1
if(A(k,k)/=0) then
C=A(i,k)/A(k,k)
B(i)=B(i)-B(k)*C !error: Statement Function is recursive
end if
end do
end do
do k=1,N
if(A(k,k)/=0) then
B(k)=B(k)/A(k,k) !error: Statement Function is recursive
end if
end do
end subroutine RowReduction
end module LinearSolution
program TestLAE
use LinearSolution !fatal error: cant open module file LinearSolution.mod for reading
type(LAE)::LAE1
LAE1%N=3
allocate(LAE1%B(1:N))
allocate(LAE1%A(1:N,1:N))
LAE1%B=(/1,1,1/)
LAE1%A=(/2,0,0,0,2,0,0,0,2/)
call LAE1%RowReduction
print*, LAE1%B(1),LAE1%B(2),LAE1%B(3)
end program