0
我正在嘗試使用lapack的zheevd來對角化一個複雜的Hermitian矩陣。我已經寫不產生任何編譯或運行時錯誤,但給出了特徵值錯誤結果的小例子下面的代碼:lapack zheevd給出了錯誤的結果
program test
implicit none
INTEGER, PARAMETER :: N=4
INTEGER, PARAMETER :: LDA = N
INTEGER, PARAMETER :: LWMAX = 1000
INTEGER :: INFO, LWORK, LIWORK, LRWORK,i,j
INTEGER :: IWORK(LWMAX)
REAL(8) :: W(N), RWORK(LWMAX)
COMPLEX(16) :: A(LDA, N), WORK(LWMAX), zero
character(len=1) :: job,uplo
! the matrix I want to diagonalize is:
! ( 3.40, 0.00) (-2.36, -1.93) (-4.68, 9.55) ( 5.37, -1.23)
! A= (-2.36, 1.93) ( 6.94, 0.00) ( 8.13, -1.47) ( 2.07, -5.78)
! (-4.68, -9.55) ( 8.13, 1.47) (-2.14, 0.00) ( 4.68, 7.44)
! ( 5.37, 1.23) ( 2.07, 5.78) ( 4.68, -7.44) (-7.42, 0.00)
zero=dcmplx(0.0d0,0.0d0)
A=zero
A(1,1)= dcmplx(3.40d0, 0.0d0); A(1,2)=dcmplx(-2.36d0, -1.93d0); A(1,3)= dcmplx(-4.68d0,9.55d0)
A(1,4)= dcmplx(5.37d0, -1.23d0)
A(2,2)= dcmplx(6.94d0, 0.0d0); A(2,3)=dcmplx(8.13d0, -1.47d0); A(2,4)= dcmplx(2.07d0, -5.78d0)
A(3,3)= dcmplx(-2.14d0, 0.0d0); A(3,4)=dcmplx(4.68d0, 7.44d0); A(4,4)= dcmplx(-7.42d0, 0.0d0)
job='V'; uplo='U'
LWORK= N**2 + 2*N; LRWORK= 2*N**2 + 5*N + 1; LIWORK= 5*N+3
CALL ZHEEVD(job, uplo, N, A, LDA, W, WORK, LWORK, RWORK,LRWORK,IWORK,LIWORK, INFO)
IF(INFO > 0) THEN
WRITE(*,*)'The algorithm failed to compute eigenvalues.'
STOP
END IF
print*, 'eigenvalues found'
do i=1,N
print*, W(i)
end do
open(1, file='eigenvectors.dat')
write(1,10) ((A(i,j),j=1,N),i=1,N)
10 format(4(F10.5,2X,F10.5))
end program test
當我運行的代碼,結果我得到了特徵值是: -2.8413,0,0,2.8413
而實際特徵值是:-21.968,16.3387,6.45946,-0.0501069
我一直看到了常規的參考指南,似乎我的一切正確因此它應該正常工作,期望它不...有沒有人知道我的代碼有什麼問題?
感謝
「COMPLEX(16)」與「COMPLEX * 16」不同。 – talonmies
你是否設法解決這個問題?我提供了幫助嗎? – talonmies