我正在尝试从LAPACK zgeqrf
和zungqr
例程中获取Q-Matrix。
我有一个Nw-by-Nw复杂矩阵,其列上有非正交向量。这是我的C ++代码。 (矩阵名为vr_tr)
//QR Fact.
complex<double> TAU[Nw*Nw];
zgeqrf_(&Nw, &Nw, vr_tr, &Nw, TAU, &wkopt, &lwork, &info);
lwork = (int)wkopt.real();
work = new complex<double> [lwork];
zgeqrf_(&Nw, &Nw, vr_tr, &Nw, TAU, work, &lwork, &info);
zungqr_(&Nw, &Nw, &Nw, vr_tr, &Nw, TAU, &wkopt, &lwork, &info);
lwork = (int)wkopt.real();
work = new complex<double> [lwork];
zungqr_(&Nw, &Nw, &Nw, vr_tr, &Nw, TAU, work, &lwork, &info);
//Checking if vr_tr * vr_tr' = I
complex<double> one = 1,zer=0,res[Nw*Nw]; char Tchar = 'T', Nchar = 'N';
zgemm_( &Nchar, &Tchar, &Nw, &Nw, &Nw, &one, vr_tr, &Nw, vr_tr, &Nw, &zer, res, &Nw );
for(i=0;i<Nw;i++){
for(j=0;j<Nw;j++){
cout<<res[i*Nw+j]<<"\t";
}
cout<<"\n\n";
}
运行此代码后得到的不是单位矩阵,因为它应该从zgeqrf
计算QR分解并从zungqr
获得Q矩阵,而Q-matrix有是正交的Q*Q'=I
。
此代码有什么问题?