问题描述
我为在 Fortran 中求解一组方程(Thomas 算法)的子程序编写了主程序。这是一组简单方程的代码:
Program Thomas
implicit none
integer i
integer,parameter :: n=2
real,dimension(n) :: a,b,c,d,x
a(1)=0
a(2)=0
b(1)=1
b(2)=2
c(1)=0
c(2)=0
d(1)=5
d(2)=10
call solve_tridiag(a,x,n)
do i = n-1,1,-1
print*,x(i)
end do
end program
subroutine solve_tridiag(a,n)
implicit none
! a - sub-diagonal (means it is the diagonal below the main diagonal)
! b - the main diagonal
! c - sup-diagonal (means it is the diagonal above the main diagonal)
! d - right part
! x - the answer
! n - number of equations
integer,parameter :: r8 = kind(1.d0)
integer,intent(in) :: n
real(r8),dimension(n),intent(in) :: a,d
real(r8),intent(out) :: x
real(r8),dimension(n) :: cp,dp
real(r8) :: m
integer i
! initialize c-prime and d-prime
cp(1) = c(1)/b(1)
dp(1) = d(1)/b(1)
! solve for vectors c-prime and d-prime
do i = 2,n
m = b(i)-cp(i-1)*a(i)
cp(i) = c(i)/m
dp(i) = (d(i)-dp(i-1)*a(i))/m
end do
! initialize x
x(n) = dp(n)
! solve for x from the vectors c-prime and d-prime
do i = n-1,-1
x(i) = dp(i)-cp(i)*x(i+1)
end do
end subroutine solve_tridiag
当我编译程序时,我收到此警告:
warning FOR4227: argument A (number 1) in reference to procedure SOLVE_TRIDIAG from procedure THOMAS incorrect: has the wrong data type
warning FOR4227: argument B (number 2) in reference to procedure SOLVE_TRIDIAG from procedure THOMAS incorrect: has the wrong data type
warning FOR4227: argument C (number 3) in reference to procedure SOLVE_TRIDIAG from procedure THOMAS incorrect: has the wrong data type
warning FOR4227: argument D (number 4) in reference to procedure SOLVE_TRIDIAG from procedure THOMAS incorrect: has the wrong data type
warning FOR4227: argument X (number 5) in reference to procedure SOLVE_TRIDIAG from procedure THOMAS incorrect: has the wrong data type
当我运行它时,我遇到了一个运行时错误。数据类型有什么问题?以及运行时错误的原因是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)