我在这里失去理智。给定正定矩阵S,我做了Cholesky因子分解S = L * L ^ T.现在,这应该导致L ^( - 1)* S *(L ^( - 1))^ T = 1,对吧?对。但它导致-1。我无法理解减号可能来自何处。
program testibum
implicit none
integer, parameter :: dp = selected_real_kind(15, 307)
integer :: ndim
complex(dp) :: cunit, czero, cone
complex(dp), allocatable :: S(:,:)
complex(dp), allocatable :: LMat(:,:)
complex(dp), allocatable :: InvLMat(:,:)
integer :: info
!########################################################################
cunit = (0.0_dp,1.0_dp)
czero = (0.0_dp,0.0_dp)
cone = (1.0_dp,0.0_dp)
ndim = 3
allocate(S(ndim,ndim))
allocate(LMat(ndim,ndim))
allocate(InvLMat(ndim,ndim))
S = reshape((/ 4.0_dp, 12.0_dp, -16.0_dp, 12.0_dp, 37.0_dp ,-43.0_dp,-16.0_dp,-43.0_dp,98.0_dp /), shape(S))
LMat(:,:) = cmplx(real(S(:,:),dp),0.0_dp,dp)
call zpotrf('L', ndim, LMat, ndim, info)
InvLMat(:,:) = LMat(:,:)
call ztrtri('L', 'N', ndim, InvLMat, ndim, info)
call ztrmm('L', 'L', 'N', 'N', ndim, ndim, cunit, InvLMat, ndim, S, ndim)
call ztrmm('R', 'L', 'T', 'N', ndim, ndim, cunit, InvLMat, ndim, S, ndim)
open(unit=25, file="testmatrix.dat", action='write', form='formatted')
write(25,*) S
deallocate(InvLMat)
deallocate(LMat)
deallocate(S)
结束程序testibum
在最后的变换之后,单位矩阵应该存储在S中。相反,它减去了单位矩阵。知道这里会发生什么吗?谢谢!
编辑:使用硬编码矩阵更新了可执行的代码。