304 | function gauss_jordan(A, n) result(x) | 1 Error: Symbol ‘n’ at (1) has no IMPLICIT type
时间: 2024-01-23 08:02:33 浏览: 113
这个错误的原因是Fortran90中`n`变量没有声明类型,可以通过在函数声明中添加`integer, intent(in) :: n`语句来解决。修改后的代码如下:
```
function gauss_jordan(A, n) result(x)
implicit none
real, dimension(n,n+1), intent(inout) :: A
real, dimension(n) :: x
integer, intent(in) :: n
integer :: i, j, k, l
real :: temp
do i = 1, n
l = i
do j = i+1, n
if (abs(A(j,i)) > abs(A(l,i))) then
l = j
end if
end do
if (l /= i) then
do k = 1, n+1
temp = A(i,k)
A(i,k) = A(l,k)
A(l,k) = temp
end do
end if
do j = i+1, n
A(j,i) = A(j,i)/A(i,i)
do k = i+1, n+1
A(j,k) = A(j,k) - A(j,i)*A(i,k)
end do
end do
end do
do i = n, 1, -1
do j = i+1, n
A(i,n+1) = A(i,n+1) - A(i,j)*x(j)
end do
x(i) = A(i,n+1)/A(i,i)
end do
end function
```
在函数声明中,我们添加了`integer, intent(in) :: n`,以声明变量`n`的类型并指定它是一个输入参数。这将消除该错误并使函数能够正常运行。
阅读全文