Wrong inverse matrix using ZGETRI in Fortran

前端 未结 1 1058
情深已故
情深已故 2020-12-20 04:14

I am trying to compute the inverse of a complex matrix with ZGETRI, but even if it executes without error (info = 0), it does not give me the correct inverse matrix and I ha

相关标签:
1条回答
  • 2020-12-20 04:41

    I suggest you to NOT use the kind notation with literal numbers like REAL(4) or COMPLEX(16).

    First, it is ugly and not portable.

    Second, it can be confusing for complex variables.

    Here you define your variables as COMPLEX(16), but ZGETRI, and all other LAPACK Z routines, expects COMPLEX*16. These are NOT the same.

    COMPLEX*16 is a non-standard notation for complex numbers with REAL*8 components. REAL*8 is a nonstandard notation for 8 byte real numbers that are normally equivalent to DOUBLE PRECISION.

    COMPLEX(16) is a complex number with two REAL(16) components, provided such a kind exists. In compilers which provide REAL(16) this real is a quadruple precision, not double precision.

    So you are effectively passing 32-byte complex variables instead of 16-byte complex variables.

    There are enough resources where to learn how to use Fortran kinds properly. You can start with

    integer, parameter :: dp = kind(1.d0)
    

    and

    real(dp) :: x
    complex(dp) :: c
    
    0 讨论(0)
提交回复
热议问题