首页 > 解决方案 > 在fortran中使用dreal函数

问题描述

我在 Fortran 中有一个 complex(8) 矩阵 A(-n:n,-m:m),它的许多元素实际上为零,例如 10e-8 等。我想让这些小值等于零。我输入:

do i=-n,n
    do j=-m,m
        if (dreal(A(i,j))<=cutoff) dreal(A(i,j))=0.0d0
        if (dimag(A(i,j))<=cutoff) dimag(A(i,j))=0.0d0
    end do
end do

其中 cutoff 已被声明为值为 0.00000010d0 的 real(8) 类型,但出现错误:

 error #6512: A scalar-valued expression is required in this context.
 error #6408: This name has already been used as an intrinsic function name.   [DREAL]
 error #6515: This function, which is specified as the left side of an assignment statement, is invalid.   [DREAL]

任何想法如何解决这一问题?

更新:@francescalus 注意到这个问题之前已经被问过。根据答案,我将代码更改为:

 do i=-n,n
    do j=-m,m
    ar= A(i,j)%re; ai=A(i,j)%im; 
       if (ar <cutoff) A(i,j)%re=0.0d0
       if (ai<cutoff)  A(i,j)%im=0.0d0
    end do
end do

但我仍然收到第一个错误:

error #6512: A scalar-valued expression is required in this context.

标签: fortrancomplex-numbers

解决方案


推荐阅读