// // 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); namespace Ctain { class EigenSolver { public: EigenSolver(SMatrix s) { _matrix = s; Matrix tt(_matrix.rows(),2); Matrix_EigenValue(_matrix.addr(),_matrix.rows(),1000,1e-10,tt.addr()); t=tt; } Matrix eigenvalues() { return t; } private: SMatrix _matrix; Matrix t; }; } //namespace Ctain end static void Matrix_Hessenberg(double *A1,int n,double *ret) { int i,j,k,MaxNumber; double temp,*A; A=new double[n*n]; for (i=0;itemp) { temp=abs(A[j*n+i]); MaxNumber=j; } } ret[0]=A[MaxNumber*n+i]; i=MaxNumber; if (ret[0]!=0) { if (i!=k) { for(j=k-1;j0) { temp=abs(A[(t-1)*n+t-1]); temp+=abs(A[t*n+t]); temp=temp*Error1; if (abs(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(abs(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