diff --git a/mat.cc b/mat.cc index 233252c..e467085 100644 --- a/mat.cc +++ b/mat.cc @@ -492,6 +492,15 @@ return r; } +//randomize +template<> +void NRMat::randomize(const double &x) +{ +for(int i=0; i::clear((*this)[0],nn*mm);}; //zero out + void randomize(const T &x); //fill with random numbers NRMat & operator=(const T &a); //assign a to diagonal NRMat & operator|=(const NRMat &rhs); //assignment to a new copy NRMat & operator+=(const T &a); //add diagonal diff --git a/smat.cc b/smat.cc index 92d5d1e..1640144 100644 --- a/smat.cc +++ b/smat.cc @@ -132,6 +132,12 @@ const T NRSMat::trace() const return tmp; } +template<> +void NRSMat::randomize(const double &x) +{ +for(int i=0; i::clear(v,NN2);}; //zero out + void randomize(const T&x); NRSMat & operator=(const T &a); //assign a to diagonal const bool operator!=(const NRSMat &rhs) const {if(nn!=rhs.nn) return 1; return LA_traits::gencmp(v,rhs.v,NN2);} //memcmp for scalars else elementwise const bool operator==(const NRSMat &rhs) const {return !(*this != rhs);}; diff --git a/t.cc b/t.cc index c8a68f7..9804623 100644 --- a/t.cc +++ b/t.cc @@ -1163,7 +1163,7 @@ cin >>a>>b; cout < a,b; cin >>a >>b; @@ -1171,6 +1171,110 @@ cout < a; +cin >>a; +if(a.nrows()!=a.ncols()) laerror("must be square matrix"); +int n=a.nrows(); + +NRMatvl(n,n),vr(n,n); +NRVec wr(n),wi(n); +NRMat awork(a); +gdiagonalize(awork,wr,wi,&vl,&vr,1,0,1,biorthonormalize); +for(int i=0; i eival(0.,n,n); +eival.diagonalset(wr); + +cout <<"test biorthonormality "<< (vl.transpose() * vr - 1.).norm()< hlp; +hlp = a *vr - vr * eival; +cout <<"test right eivectors "< ader(n,n); +for(int i=0; i vlx(n,n),vrx(n,n); +NRVec wrx(n),wix(n); +gdiagonalize(awork,wrx,wix,&vlx,&vrx,1,0,1,biorthonormalize); +for(int i=0; i vly(n,n),vry(n,n); +NRVec wry(n),wiy(n); +gdiagonalize(awork,wry,wiy,&vly,&vry,1,0,1,biorthonormalize); +for(int i=0; i vld,vrd; +NRVec wrd; +vld = (vlx-vly) * (.5/h); +vrd = (vrx-vry) * (.5/h); +wrd = (wrx-wry) * (.5/h); + +NRMat vlg,vrg; +NRVec wrg(n); + +//compute analytic derivative +NRMat tmp(n,n); +tmp.gemm(0.,vl,'t', ader * vr,'n',1.); +hlp |= tmp; +cout <<" C~+ VH C = \n"< Y = tmp; +NRMat S = vr.transpose() * vr; +NRMat tmp2 = S * tmp; +for(int i=0; i numX = inverse(vr) * vrd; +cout <<" numerical X matrix \n"<< numX; +cout <<" numerical X matrix test = "<< (vr * numX - vrd).norm()<