CPPLapack
 All Classes Files Functions Variables Friends
zhematrix-lapack.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! solve A*X=Y using zhesv\n
00003   The argument is dmatrix Y. Y is overwritten and become the solution X.
00004   A is also overwritten. 
00005 */
00006 inline long zhematrix::zhesv(zgematrix& mat)
00007 {VERBOSE_REPORT;
00008 #ifdef  CPPL_DEBUG
00009   if(n!=mat.n){
00010     ERROR_REPORT;
00011     std::cerr << "These two matrices cannot be solved." << std::endl
00012               << "Your input was (" << n << "x" << n << ") and (" << mat.n << "x" << mat.n << ")." << std::endl;
00013     exit(1);
00014   }
00015 #endif//CPPL_DEBUG
00016   
00017   char UPLO('l');
00018   long NRHS(mat.n), LDA(n), *IPIV(new long[n]), LDB(mat.n), LWORK(-1), INFO(1);
00019   comple *WORK(new comple[1]);
00020   zhesv_(UPLO, n, NRHS, array, LDA, IPIV, mat.array, LDB, WORK, LWORK, INFO);
00021   
00022   INFO=1;
00023   LWORK = long(std::real(WORK[0]));
00024   delete [] WORK;  WORK =new comple[LWORK];
00025   zhesv_(UPLO, n, NRHS, array, LDA, IPIV, mat.array, LDB, WORK, LWORK, INFO);
00026   delete [] WORK; delete [] IPIV;
00027   
00028   if(INFO!=0){
00029     WARNING_REPORT;
00030     std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
00031   }
00032   return INFO;
00033 }
00034 
00035 //=============================================================================
00036 /*! solve A*x=y using zhesv\n
00037   The argument is zcovector y. y is overwritten and become the solution x.
00038   A is also overwritten.
00039 */
00040 inline long zhematrix::zhesv(zcovector& vec)
00041 {VERBOSE_REPORT;
00042 #ifdef  CPPL_DEBUG
00043   if(n!=vec.l){
00044     ERROR_REPORT;
00045     std::cerr << "These matrix and vector cannot be solved." << std::endl
00046               << "Your input was (" << n << "x" << n << ") and (" << vec.l << ")." << std::endl;
00047     exit(1);
00048   }
00049 #endif//CPPL_DEBUG 
00050   
00051   char UPLO('l');
00052   long NRHS(1), LDA(n), *IPIV(new long[n]), LDB(vec.l), LWORK(-1), INFO(1);
00053   comple *WORK( new comple[1] );
00054   zhesv_(UPLO, n, NRHS, array, LDA, IPIV, vec.array, LDB, WORK, LWORK, INFO);
00055   
00056   INFO=1;
00057   LWORK = long(std::real(WORK[0]));
00058   delete [] WORK;  WORK = new comple[LWORK];
00059   zhesv_(UPLO, n, NRHS, array, LDA, IPIV, vec.array, LDB, WORK, LWORK, INFO);
00060   delete [] WORK;  delete [] IPIV;
00061   
00062   if(INFO!=0){
00063     WARNING_REPORT;
00064     std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
00065   }
00066   return INFO;
00067 }
00068 
00069 ///////////////////////////////////////////////////////////////////////////////
00070 ///////////////////////////////////////////////////////////////////////////////
00071 ///////////////////////////////////////////////////////////////////////////////
00072 
00073 //=============================================================================
00074 /*! calculate eigenvalues and eigenvectors.\n
00075   All of the arguments need not to be initialized.
00076   w is overwitten and become eigenvalues.
00077   This matrix is also overwritten. 
00078   if jobz=1, this matrix becomes eigenvectors.
00079 */
00080 inline long zhematrix::zheev(std::vector<double>& w,
00081                              const bool& jobz=0)
00082 {VERBOSE_REPORT;
00083   w.resize(n);
00084   char JOBZ, UPLO('l');
00085   if(jobz==0){ JOBZ='n'; } else{ JOBZ='V'; }
00086   long LDA(n), INFO(1), LWORK(-1);
00087   double *RWORK(new double[std::max(long(1), 3*n-2)]);
00088   comple *WORK(new comple[1]);
00089   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00090   
00091   INFO=1;
00092   LWORK = long(std::real(WORK[0]));
00093   delete [] WORK;  WORK = new comple[LWORK];
00094   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00095   delete [] RWORK;  delete [] WORK;
00096   
00097   if(INFO!=0){
00098     WARNING_REPORT;
00099     std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
00100   }
00101   return INFO;
00102 }
00103 
00104 //=============================================================================
00105 /*! calculate eigenvalues and eigenvectors.\n
00106   All of the arguments need not to be initialized.
00107   w and v are overwitten and become 
00108   eigenvalues and eigenvectors, respectively.
00109   This matrix is also overwritten. 
00110 */
00111 inline long zhematrix::zheev(std::vector<double>& w,
00112                              std::vector<zcovector>& v)
00113 {VERBOSE_REPORT;
00114   w.resize(n);  v.resize(n);
00115   for(long i=0; i<n; i++){ v[i].resize(n); }
00116   char JOBZ('V'), UPLO('l');
00117   long LDA(n), INFO(1), LWORK(-1);
00118   double *RWORK(new double[std::max(long(1), 3*n-2)]);
00119   comple *WORK(new comple[1]);
00120   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00121   
00122   INFO=1;
00123   LWORK = long(std::real(WORK[0]));
00124   delete [] WORK;  WORK = new comple[LWORK];
00125   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00126   delete [] RWORK;  delete [] WORK;
00127   
00128   //// forming ////
00129   for(long i=0; i<n; i++){ for(long j=0; j<n; j++){
00130     v[j](i) = array[i+n*j];
00131   }}
00132   
00133   if(INFO!=0){
00134     WARNING_REPORT;
00135     std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
00136   }
00137   return INFO;
00138 }
00139 
00140 //=============================================================================
00141 /*! calculate eigenvalues and eigenvectors.\n
00142   All of the arguments need not to be initialized.
00143   w and v are overwitten and become 
00144   eigenvalues and eigenvectors, respectively.
00145   This matrix is also overwritten. 
00146 */
00147 inline long zhematrix::zheev(std::vector<double>& w,
00148                              std::vector<zrovector>& v)
00149 {VERBOSE_REPORT;
00150   w.resize(n);  v.resize(n);
00151   for(long i=0; i<n; i++){ v[i].resize(n); }
00152   char JOBZ('V'), UPLO('l');
00153   long LDA(n), INFO(1), LWORK(-1);
00154   double *RWORK(new double[std::max(long(1), 3*n-2)]);
00155   comple *WORK(new comple[1]);
00156   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00157   
00158   INFO=1;
00159   LWORK = long(std::real(WORK[0]));
00160   delete [] WORK;  WORK = new comple[LWORK];
00161   zheev_(JOBZ, UPLO, n, array, LDA, &w[0], WORK, LWORK, RWORK, INFO);
00162   delete [] RWORK;  delete [] WORK;
00163   
00164   //// forming ////
00165   for(long i=0; i<n; i++){ for(long j=0; j<n; j++){
00166     v[j](i) = array[i+n*j];
00167   }}
00168   
00169   if(INFO!=0){
00170     WARNING_REPORT;
00171     std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
00172   }
00173   return INFO;
00174 }
 All Classes Files Functions Variables Friends