diff --git a/t.cc b/t.cc index 7eaf0fe..718272a 100644 --- a/t.cc +++ b/t.cc @@ -9,6 +9,7 @@ #include "davidson.h" #include "gmres.h" #include "conjgrad.h" +#include "diis.h" extern void test(const NRVec &x); @@ -541,26 +542,50 @@ cout <>n; NRMat a(n,n); for(int i=0;i b; b|=a; NRVec er(n),ei(n); NRMat vr(n,n),vl(n,n); -gdiagonalize(b,er,ei,&vl,&vr); +gdiagonalize(b,er,ei,&vl,&vr,1,0,1,1); cout < u=exp(a*.125); -cout <<"norms "< u=exp(a*.1); +gdiagonalize(u,er,ei,&vl,&vr,1,0,1,1); cout <>k; +int n=2*k; +NRMat a(n,n); +//matrix with known spectrum +for(int i=0;i er(n),ei(n); +NRMat vr(n,n),vl(n,n); +cout <<"input matrix\n"< amat,bmat; cin >>amat; cin >>bmat; NRVec v(amat.nrows()); -gendiagonalize(amat,v,bmat,2); +diagonalize(amat,v,1,1,0,&bmat,1); cout <>n >>m; -NRMat a(n,n); +NRSMat a(n,n); NRVec rr(n); for(int i=0;i aa; -aa=a; diagonalize(aa,rr); +NRSMat aa; +NRMat vv(n,n); +aa=a; diagonalize(aa,rr,&vv); NRVec r(m); NRVec *eivecs = new NRVec[m]; davidson(a,r,eivecs,NULL,m,1,1e-6,1,200); @@ -820,7 +845,46 @@ cout <<"Eigenvectors compare:\n"; for(int i=0; i>n >>m; +NRMat a(n,n); +NRVec rr(n),ii(n); + +double tmp=0.; +for(int i=0;i aa=a; +NRMat vv=aa; +gdiagonalize(aa, rr, ii, NULL, &vv, 1, 0, 2, 0, NULL,NULL); +NRVec r(m); +NRVec *eivecs = new NRVec[m]; +davidson(a,r,eivecs,NULL,m,1,1e-6,1,200); + +cout <<"Davidson energies " < *)NULL,"eivecs",m,1,1e-5,0,300,300); cout <>n>>m; + SparseMat aa(n,n); + aa.setsymmetric(); + for(int i=0; i r(m); +NRVec r2(m); +davidson(aa,r,(NRVec *)NULL,"eivecs",m,1,1e-5,1,300,300); + SparseMat bb(n,n); +for(int i=0; i e1,e2,cc; +e1=exp(bb); +e2=exp(bb*-1.); +aa.setunsymmetric(); +cc=e1*aa*e2; +davidson(cc,r2,(NRVec *)NULL,"eivecs2",m,1,1e-5,1,300,300); +cout <<"original matrix" <>n>>m; + SparseMat aa(n,n); + for(int i=0; i r(m); +davidson(aa,r,(NRVec *)NULL,"eivecs",m,1,1e-5,0,300,300); +cout <>n >>m; @@ -899,4 +1014,36 @@ gmres(aa,b,x,1,1e-20,20,1,1,1,1000,1); //conjgrad(aa,b,x,1,1e-10,1000,1,0,1); } +if(0) +{ +NRMat A(3,3); +A=1.; +double *p = (double *)A; +*p=2.; +cout < > diis(5,1); +int dim=8; +NRVec solution(dim), deviation(dim); +for(i=0; i1e-8 ; ++iter) + { + NRVec trial=solution; + trial.copyonwrite(); + for(i=0; i