// // Created by 顾涵彬 on 2019-08-30. // #ifndef MATRIX_MATRIXSOLVER_H #define MATRIX_MATRIXSOLVER_H #include #include static bool Matrix_EigenValue(double *K1,int n,int LoopNumber,double Error1,double *Ret); static void Matrix_Hessenberg(double *A1,int n,double *ret); namespace Ctain { class EigenSolver { public: EigenSolver(SMatrix s) { double *A = new double[s.rows()*2]; double *B = new double[s.size()]; for(int i = 0; i < s.size(); i++) B[i] = s(i); memset(A, 0, sizeof(s.rows()*2)); Matrix_EigenValue(B, s.rows(),1000,1e-10,A); Matrix tt(A, s.rows(), 2); t=tt; std::cout<<"s:"< s2(A, s.rows()); std::cout<<"tt:"< eigenvalues() { return t; } private: Matrix t; }; } //namespace Ctain end static void Matrix_Hessenberg(double *A1,int n,double *ret) { int MaxNumber; double temp,*A; A=new double[n*n]; memset(A, 0, sizeof(double)*n*n); for (int i=0;itemp) { temp=fabs(A[j*n+i]); MaxNumber=j; } } ret[0]=A[MaxNumber*n+i]; if (ret[0]!=0) { if (MaxNumber!=k) { for(int j=k-1;j0) { temp=fabs(A[(t-1)*n+t-1]); temp+=fabs(A[t*n+t]); temp=temp*Error1; if (fabs(A[t*n+t-1])>temp) { t--; } else { break; } } if (t==m-1) { Ret[(m-1)*2]=A[(m-1)*n+m-1]; Ret[(m-1)*2+1]=0; m-=1; Loop1=LoopNumber; } else if(t==m-2) { b=-A[(m-1)*n+m-1]-A[(m-2)*n+m-2]; c=A[(m-1)*n+m-1]*A[(m-2)*n+m-2]-A[(m-1)*n+m-2]*A[(m-2)*n+m-1]; d=b*b-4*c; y=sqrt(fabs(d)); if (d>0) { xy=1; if (b<0) { xy=-1; } Ret[(m-1)*2]=-(b+xy*y)/2; Ret[(m-1)*2+1]=0; Ret[(m-2)*2]=c/Ret[(m-1)*2]; Ret[(m-2)*2+1]=0; } else { Ret[(m-1)*2]=-b/2; Ret[(m-2)*2]=-b/2; Ret[(m-1)*2+1]=y/2; Ret[(m-2)*2+1]=-y/2; } m-=2; Loop1=LoopNumber; } else { if (Loop1<1) { return false; } Loop1--; j=t+2; while (jm-2) { j=m-1; } for (i=t;i