Fortran cgeev sovle非Hermitain矩阵不正确
最近我想重现的图1(a),我用cgeev来解非厄米哈密顿矩阵的本征值,我发现解变成了连线。 这是我的Fortran代码,结果如图1所示。(a)对应于abs.dat 如果我使用了Lapack的错误函数,或者我的代码不正确 我用的是英特尔fortran,complie命令是 *ifort-mkl file.f90-o a.outFortran cgeev sovle非Hermitain矩阵不正确,fortran,intel-fortran,Fortran,Intel Fortran,最近我想重现的图1(a),我用cgeev来解非厄米哈密顿矩阵的本征值,我发现解变成了连线。 这是我的Fortran代码,结果如图1所示。(a)对应于abs.dat 如果我使用了Lapack的错误函数,或者我的代码不正确 我用的是英特尔fortran,complie命令是 *ifort-mkl file.f90-o a.out 运行程序./a.out&*欢迎光临,请参加。所有Fortran问题都使用tag。您必须向我们展示代码的结果。好的,我已经编译并运行了您的程序。它生成一些输出文件。如何检查这
运行程序./a.out&*欢迎光临,请参加。所有Fortran问题都使用tag。您必须向我们展示代码的结果。好的,我已经编译并运行了您的程序。它生成一些输出文件。如何检查这些设备是否“有线”?我看到很多星星,这可能意味着你在某个地方搞砸了一个格式,没有提供足够的空间来输出你想要的内容,但是还有什么我应该寻找的吗?请始终使用隐式无-模块中的例程也更好。我的输出数据文件没有星形,我认为数据的格式应该正确。在代码中*(999格式(201f11.6))*设置正确的数据格式-2.970000*******************************和更多的星星(带有一些其他数字)是我在abs.dat中看到的。我不知道,我的结果中没有很多星星欢迎,请接受这个。所有Fortran问题都使用tag。您必须向我们展示代码的结果。好的,我已经编译并运行了您的程序。它生成一些输出文件。如何检查这些设备是否“有线”?我看到很多星星,这可能意味着你在某个地方搞砸了一个格式,没有提供足够的空间来输出你想要的内容,但是还有什么我应该寻找的吗?请始终使用隐式无-模块中的例程也更好。我的输出数据文件没有星形,我认为数据的格式应该正确。在代码中*(999格式(201f11.6))*设置正确的数据格式-2.970000****************************和更多的星星(带有一些其他数字)是我在abs.dat中看到的。我不知道,我的结果中没有很多星星
module pub
implicit none
complex,parameter::im = (0.0,1.0)
real,parameter::pi = 3.1415926535
integer xn,N,en,kn
parameter(xn = 100,N = xn*2,en = 100)
complex Ham(N,N)
real t1,t2,t3,gam
!-----------------
integer::lda = N
integer,parameter::lwmax=2*N + N**2
complex,allocatable::w(:) ! store eigenvalues
complex,allocatable::work(:)
real,allocatable::rwork(:)
integer lwork
integer info
integer LDVL, LDVR
parameter(LDVL = N, LDVR = N )
complex VL( LDVL, N ), VR( LDVR, N )
end module pub
!=====================================================
program sol
use pub
! Physics memory allocate
allocate(w(N))
allocate(work(lwmax))
allocate(rwork(2*N))
!-----------------
t2 = 1.0
t3 = 0.0
gam = 3.0/4.0
call band()
end program sol
!======================================================
subroutine band()
use pub
integer m1,i
open(11,file="real.dat")
open(12,file="imag.dat")
open(13,file="abs.dat")
do m1 = -en,en
t1 = 3.0*m1/en
call matset()
call eigsol()
write(11,999)t1,(real(w(i)),i = 1,N)
write(12,999)t1,(aimag(w(i)),i = 1,N)
write(13,999)t1,(abs(w(i)),i = 1,N)
end do
close(11)
close(12)
close(13)
999 format(201f11.6)
end subroutine band
!======================================================
subroutine matset()
use pub
real kx
complex sx(2,2),sy(2,2),sz(2,2)
integer k,m1,m2
sx(1,2) = 1.0
sx(2,1) = 1.0
sy(1,2) = -im
sy(2,1) = im
sz(1,1) = 1.0
sz(2,2) = -1.0
!--------
Ham = 0.0
do k = 0,xn-1
if(k == 0)then
do m1 = 1,2
do m2 = 1,2
ham(m1,m2) = t1*sx(m1,m2) + im*gam/2.0*sy(m1,m2)
ham(m1,m2 + 2) = (t2 + t3)/2.0*sx(m1,m2) - im*(t2 - t3)/2.0*sy(m1,m2)
end do
end do
elseif(k == xn-1)then
do m1 = 1,2
do m2 = 1,2
ham(k*2 + m1,k*2 + m2) = t1*sx(m1,m2) + im*gam/2.0*sy(m1,m2)
ham(k*2 + m1,k*2 + m2 - 2) = (t2 + t3)/2.0*sx(m1,m2) + im*(t2 - t3)/2.0*sy(m1,m2)
end do
end do
else
do m1 = 1,2
do m2 = 1,2
ham(k*2 + m1,k*2 + m2) = t1*sx(m1,m2) + im*gam/2.0*sy(m1,m2)
! right hopping
ham(k*2 + m1,k*2 + m2 + 2) = (t2 + t3)/2.0*sx(m1,m2) - im*(t2 - t3)/2.0*sy(m1,m2)
! left hopping
ham(k*2 + m1,k*2 + m2 - 2) = (t2 + t3)/2.0*sx(m1,m2) + im*(t2 - t3)/2.0*sy(m1,m2)
end do
end do
end if
end do
return
end subroutine matset
!==============================================================================
subroutine eigsol()
use pub
! Query the optimal workspace.
LWORK = -1
CALL cgeev( 'Vectors', 'Vectors', N, Ham, LDA, W, VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO)
LWORK = MIN( LWMAX, INT( WORK( 1 ) ) )
! Solve eigenproblem.
CALL cgeev( 'Vectors', 'Vectors', N, Ham, LDA, W, VL, LDVL,VR, LDVR, WORK, LWORK, RWORK, INFO)
! Check for convergence.
IF( INFO.GT.0 ) THEN
WRITE(*,*)'The algorithm failed to compute eigenvalues.'
STOP
END IF
! open(120,file="eigval.dat")
! do m = 1,N
! write(120,*)m,w(m)
! end do
! close(120)
return
end subroutine eigsol