我正在尝试使用Lapack的ZGGEV例程来解决一般特征值问题,即 A x = v B x 。其中 v 是特征值。我正在对一些随机矩阵做一个小测试。让我们说
A=[ -21.10-22.50i 53.50-50.50i -34.50+127.50i 7.50+0.50i;
-0.46-7.78i -3.50-37.50i -15.50+58.50i -10.50-1.50i;
4.30-5.50i 39.70-17.10i -68.50+12.50i -7.50-3.50i;
5.50+4.40i 14.40+43.30i -32.50-46.00i -19.00-32.50i]
B=[ 1.00-5.00i 1.60+1.20i -3.00+0.00i 0.00-1.00i ;
0.80-0.60i 3.00-5.00i -4.00+3.00i -2.40-3.20i ;
1.00+0.00i 2.40+1.80i -4.00-5.00i 0.00-3.00i ;
0.00+1.00i -1.80+2.40i 0.00-4.00i 4.00-5.00i]
我的Fortran代码如下: 程序testz
implicit none
integer, parameter :: N=4, nb=64, Nmax=10
integer :: lda,ldb,ldvr,lwork
parameter (lda=Nmax, ldb=Nmax, ldvr=Nmax,lwork=Nmax+Nmax*nb)
integer :: i,j,info
complex(kind=16) :: A(lda,Nmax), alpha(Nmax), B(ldb,Nmax),
& beta(Nmax), dummy(1,1), vr(ldvr,Nmax), work(lwork), eig(Nmax)
double precision :: rwork(8*Nmax)
A(1,1)=(-21.10,-22.50);A(1,2)=(53.50,-50.50)
A(1,3)=(-34.50,127.50);A(1,4)=(7.50,0.50)
A(2,1)=(-0.46,7.78);A(2,2)=(-3.5,-37.5)
A(2,3)=(-15.5,58.5);A(2,4)=(-10.5,-1.5)
A(3,1)=(4.3,-5.5);A(3,2)=(39.7,-17.1)
A(3,3)=(-68.5,12.5);A(3,4)=(-7.5,-3.5)
A(4,1)=(5.5,4.4);A(4,2)=(14.4,43.3)
A(4,3)=(-32.5,-46);A(4,4)=(-19,32.5)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
B(1,1)=(1,-5);B(1,2)=(1.6,1.2)
B(1,3)=(-3,0);B(1,4)=(0,-1)
B(2,1)=(0.8,-0.6);B(2,2)=(3,-5)
B(2,3)=(-4,3);B(2,4)=(-2.4,-3.2)
B(3,1)=(1,0);B(3,2)=(2.4,1.8)
B(3,3)=(-4,-5);B(3,4)=(0,-3)
B(4,1)=(0,1);B(4,2)=(-1.8,2.4)
B(4,3)=(0,-4);B(4,4)=(4,-5)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call zggev('n','v',N,A,lda,B,ldb,alpha,beta,dummy,1,vr,ldvr,
& work,lwork,rwork,info)
eig=alpha/beta
!here skip the heading to the file
do j=1,N
write(7,12) eig(j)
12 format('(',2F8.4,')')!,'(',2F8.4,')','(',2F8.4,')','(',2F8.4,')')
end do
end program
我的结果是: (NaN NaN) (****************) (0.0000 0.0000) (0.0000 0.0000) 而正确的答案应该是 特征值(1)=(3.0000E + 00,-9.0000E + 00)
特征值(2)=(2.0000E + 00,-5.0000E + 00)
特征值(3)=(3.0000E + 00,-1.0000E + 00)
特征值(4)=(4.0000E + 00,-5.0000E + 00)