11 std::cerr <<
"These two matrices cannot be solved." << std::endl
12 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << mat.
m <<
"x" << mat.
n <<
")." << std::endl;
17 CPPL_INT NRHS(mat.
n), LDA(
n), *IPIV(
new CPPL_INT[
n]), LDB(mat.
m), INFO(1);
18 dgesv_(&n, &NRHS,
array, &LDA, IPIV, mat.
array, &LDB, &INFO);
23 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
38 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
39 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << vec.
l <<
")." << std::endl;
44 CPPL_INT NRHS(1), LDA(
n), *IPIV(
new CPPL_INT[
n]), LDB(vec.
l), INFO(1);
45 dgesv_(&n, &NRHS,
array, &LDA, IPIV, vec.
array, &LDB, &INFO);
50 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
67 std::cerr <<
"These two matrices cannot be solved." << std::endl
68 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << mat.
m <<
"x" << mat.
n <<
")." << std::endl;
75 for(CPPL_INT
i=0;
i<mat.
m;
i++){
76 for(CPPL_INT j=0; j<mat.
n; j++){
85 CPPL_INT NRHS(mat.
n), LDA(
m), LDB(mat.
m), LWORK(std::min(
m,
n)+std::max(std::min(
m,
n),NRHS)), INFO(1);
86 double *WORK(
new double[LWORK]);
87 dgels_(&TRANS, &
m, &
n, &NRHS,
array, &LDA, mat.
array, &LDB, WORK, &LWORK, &INFO);
92 for(CPPL_INT
i=0;
i<tmp.
m;
i++){
93 for(CPPL_INT j=0; j<tmp.
n; j++){
103 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
112 {CPPL_VERBOSE_REPORT;
116 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
117 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << vec.
l <<
")." << std::endl;
124 for(CPPL_INT
i=0;
i<vec.
l;
i++){
132 CPPL_INT NRHS(1), LDA(
m), LDB(vec.
l), LWORK(std::min(
m,
n)+std::max(std::min(
m,
n),NRHS)), INFO(1);
133 double *WORK(
new double[LWORK]);
134 dgels_(&TRANS, &
m, &
n, &NRHS,
array, &LDA, vec.
array, &LDB, WORK, &LWORK, &INFO);
139 for(CPPL_INT
i=0;
i<tmp.
l;
i++){
148 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
161 {CPPL_VERBOSE_REPORT;
165 std::cerr <<
"These two matrices cannot be solved." << std::endl
166 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << mat.
m <<
"x" << mat.
n <<
")." << std::endl;
176 for(CPPL_INT
i=0;
i<mat.
m;
i++){
177 for(CPPL_INT j=0; j<mat.
n; j++){
186 CPPL_INT NRHS(mat.
n), LDA(
m), LDB(mat.
m), LWORK(std::min(
m,
n)+std::max(std::min(
m,
n),NRHS)), INFO(1);
187 double *WORK(
new double[LWORK]);
188 dgels_(&TRANS, &
m, &
n, &NRHS,
array, &LDA, mat.
array, &LDB, WORK, &LWORK, &INFO);
192 for(CPPL_INT
i=0;
i<residual.
l;
i++){
193 for(CPPL_INT j=0; j<
m-
n; j++){
194 residual(
i) += std::pow(mat(n+j,
i), 2.0);
199 for(CPPL_INT
i=0;
i<tmp.
m;
i++){
200 for(CPPL_INT j=0; j<tmp.
n; j++){
210 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
223 {CPPL_VERBOSE_REPORT;
227 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
228 <<
"Your input was (" <<
m <<
"x" <<
n <<
") and (" << vec.
l <<
")." << std::endl;
237 for(CPPL_INT
i=0;
i<vec.
l;
i++){
245 CPPL_INT NRHS(1), LDA(
m), LDB(vec.
l), LWORK(std::min(
m,
n)+std::max(std::min(
m,
n),NRHS)), INFO(1);
246 double *WORK(
new double[LWORK]);
247 dgels_(&TRANS, &
m, &
n, &NRHS,
array, &LDA, vec.
array, &LDB, WORK, &LWORK, &INFO);
251 for(CPPL_INT
i=0;
i<
m-
n;
i++){
252 residual+=std::pow(vec(n+
i),2.0);
256 for(CPPL_INT
i=0;
i<tmp.
l;
i++){
265 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
283 const double RCOND =-1.
285 {CPPL_VERBOSE_REPORT;
289 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
290 <<
"Your input was (" << m <<
"x" << n <<
") and (" << B.
l <<
")." << std::endl;
297 for(CPPL_INT
i=0;
i<B.
l;
i++){
306 CPPL_INT NRHS(1), LDA(m), LDB(B.
l), LWORK(3*std::min(m,n)+std::max(std::max(2*std::min(m,n),std::max(m,n)), NRHS)), INFO(1);
307 double *WORK(
new double[LWORK]);
308 dgelss_(&m, &n, &NRHS, array, &LDA, B.
array, &LDB, S.
array, &RCOND, &RANK, WORK, &LWORK, &INFO);
313 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
327 const double RCOND =-1.
329 {CPPL_VERBOSE_REPORT;
333 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
334 <<
"Your input was (" << m <<
"x" << n <<
") and (" << B.
m <<
"x" << B.
n <<
")." << std::endl;
341 for(CPPL_INT
i=0;
i<B.
m;
i++){
342 for(CPPL_INT j=0; j<B.
n; j++){
352 CPPL_INT NRHS(B.
n), LDA(m), LDB(B.
m), LWORK(3*std::min(m,n)+std::max(std::max(2*std::min(m,n),std::max(m,n)), NRHS)), INFO(1);
353 double *WORK(
new double[LWORK]);
354 dgelss_(&m, &n, &NRHS, array, &LDA, B.
array, &LDB, S.
array, &RCOND, &RANK, WORK, &LWORK, &INFO);
359 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
376 const double RCOND =-1.
378 {CPPL_VERBOSE_REPORT;
382 std::cerr <<
"These matrix and vector cannot be solved." << std::endl
383 <<
"Your input was (" << m <<
"x" << n <<
") and (" << B.
l <<
")." << std::endl;
391 for(CPPL_INT
i=0;
i<B.
l;
i++){
406 std::vector<double> WORK(1);
408 CPPL_INT MINMN =std::min(M,N);
410 CPPL_INT NLVL =CPPL_INT( std::log(
double(MINMN)/
double(SMLSIZ+1))/std::log(2.) );
411 CPPL_INT LIWORK =3*MINMN*NLVL+11*MINMN;
412 std::vector<CPPL_INT> IWORK(LIWORK);
414 dgelsd_(&M, &N, &NRHS, array, &LDA, B.
array, &LDB, S.
array, &RCOND, &RANK, &WORK[0], &LWORK, &IWORK[0], &INFO);
415 LWORK =CPPL_INT(WORK[0]);
421 dgelsd_(&M, &N, &NRHS, array, &LDA, B.
array, &LDB, S.
array, &RCOND, &RANK, &WORK[0], &LWORK, &IWORK[0], &INFO);
426 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
443 {CPPL_VERBOSE_REPORT;
447 std::cerr <<
"This matrix is not a square matrix." << std::endl
448 <<
"This matrix is (" <<
m <<
"x" <<
n <<
")." << std::endl;
455 char JOBVL(
'n'), JOBVR(
'n');
456 CPPL_INT LDA(
n), LDVL(1), LDVR(1), LWORK(3*
n), INFO(1);
457 double *VL(NULL), *VR(NULL), *WORK(
new double[LWORK]);
458 dgeev_(&JOBVL, &JOBVR, &
n,
array, &LDA, &wr[0], &wi[0], VL, &LDVL, VR, &LDVR, WORK, &LWORK, &INFO);
465 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
477 {CPPL_VERBOSE_REPORT;
479 std::vector<double> wr, wi;
480 CPPL_INT INFO =
dgeev(wr,wi);
484 for(CPPL_INT
i=0;
i<
n;
i++){
485 w(
i) =comple(wr[
i],wi[i]);
501 std::vector<double>& wr,
502 std::vector<double>& wi,
503 std::vector<dcovector>& vrr,
504 std::vector<dcovector>& vri
506 {CPPL_VERBOSE_REPORT;
510 std::cerr <<
"This matrix is not a square matrix." << std::endl
511 <<
"This matrix is (" << m <<
"x" << n <<
")." << std::endl;
520 for(CPPL_INT
i=0;
i<n;
i++){
526 char JOBVL(
'n'), JOBVR(
'V');
527 CPPL_INT LDA(n), LDVL(1), LDVR(n), LWORK(4*n), INFO(1);
528 double *VL(NULL), *WORK(
new double[LWORK]);
529 dgeev_(&JOBVL, &JOBVR, &n, array, &LDA, &wr[0], &wi[0], VL, &LDVL, VR.
array, &LDVR, WORK, &LWORK, &INFO);
534 for(CPPL_INT j=0; j<n; j++){
535 if(fabs(wi[j])<DBL_MIN){
536 for(CPPL_INT
i=0;
i<n;
i++){
542 for(CPPL_INT
i=0;
i<n;
i++){
544 vri[j](
i) = VR(
i,j+1);
545 vrr[j+1](
i) = VR(
i,j);
546 vri[j+1](
i) =-VR(
i,j+1);
554 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
568 std::vector<drovector>& vlr,
569 std::vector<drovector>& vli)
570 {CPPL_VERBOSE_REPORT;
574 std::cerr <<
"This matrix is not a square matrix." << std::endl
575 <<
"This matrix is (" <<
m <<
"x" <<
n <<
")." << std::endl;
584 for(CPPL_INT
i=0;
i<
n;
i++){
590 char JOBVL(
'V'), JOBVR(
'n');
591 CPPL_INT LDA(n), LDVL(n), LDVR(1), LWORK(4*n), INFO(1);
592 double *VR(NULL), *WORK(
new double[LWORK]);
593 dgeev_(&JOBVL, &JOBVR, &n,
array, &LDA, &wr[0], &wi[0], VL.
array, &LDVL, VR, &LDVR, WORK, &LWORK, &INFO);
598 for(CPPL_INT j=0; j<
n; j++){
599 if(fabs(wi[j])<DBL_MIN){
600 for(CPPL_INT
i=0;
i<
n;
i++){
606 for(CPPL_INT
i=0;
i<
n;
i++){
608 vli[j](
i) =-VL(
i,j+1);
609 vlr[j+1](
i) = VL(
i,j);
610 vli[j+1](
i) = VL(
i,j+1);
619 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
638 std::vector<double>& wr, std::vector<double>& wi)
639 {CPPL_VERBOSE_REPORT;
643 std::cerr <<
"This matrix is not a square matrix." << std::endl
644 <<
"This matrix is (" <<
m <<
"x" <<
n <<
")." << std::endl;
647 if(matB.
m!=
n || matB.
n!=
n){
649 std::cerr <<
"The matrix B is not a square matrix having the same size as \"this\" matrix." << std::endl
650 <<
"The B matrix is (" << matB.
m <<
"x" << matB.
n <<
")." << std::endl;
657 char JOBVL(
'n'), JOBVR(
'n');
658 CPPL_INT LDA(
n), LDB(
n), LDVL(1), LDVR(1), LWORK(8*
n), INFO(1);
659 double *BETA(
new double[
n]), *VL(NULL), *VR(NULL), *WORK(
new double[LWORK]);
660 dggev_(&JOBVL, &JOBVR, &n,
array, &LDA, matB.
array, &LDB, &wr[0], &wi[0], BETA, VL, &LDVL, VR, &LDVR, WORK, &LWORK, &INFO);
666 for(CPPL_INT
i=0;
i<
n;
i++){
674 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
688 std::vector<double>& wr, std::vector<double>& wi,
689 std::vector<dcovector>& vrr,
690 std::vector<dcovector>& vri)
691 {CPPL_VERBOSE_REPORT;
695 std::cerr <<
"This matrix is not a square matrix." << std::endl
696 <<
"This matrix is (" <<
m <<
"x" <<
n <<
")." << std::endl;
699 if(matB.
m!=
n || matB.
n!=
n){
701 std::cerr <<
"The matrix B is not a square matrix having the same size as \"this\" matrix." << std::endl
702 <<
"The B matrix is (" << matB.
m <<
"x" << matB.
n <<
")." << std::endl;
711 for(CPPL_INT
i=0;
i<
n;
i++){
717 char JOBVL(
'n'), JOBVR(
'V');
718 CPPL_INT LDA(n), LDB(n), LDVL(1), LDVR(n), LWORK(8*n), INFO(1);
719 double *BETA(
new double[n]), *VL(NULL), *WORK(
new double[LWORK]);
720 dggev_(&JOBVL, &JOBVR, &n,
array, &LDA, matB.
array, &LDB, &wr[0], &wi[0], BETA, VL, &LDVL, VR.
array, &LDVR, WORK, &LWORK, &INFO);
725 for(CPPL_INT
i=0;
i<
n;
i++){
732 for(CPPL_INT j=0; j<
n; j++){
733 if(fabs(wi[j])<DBL_MIN){
734 for(CPPL_INT
i=0;
i<
n;
i++){
740 for(CPPL_INT
i=0;
i<
n;
i++){
742 vri[j](
i) = VR(
i,j+1);
743 vrr[j+1](
i) = VR(
i,j);
744 vri[j+1](
i) =-VR(
i,j+1);
752 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
766 std::vector<double>& wr, std::vector<double>& wi,
767 std::vector<drovector>& vlr,
768 std::vector<drovector>& vli)
769 {CPPL_VERBOSE_REPORT;
773 std::cerr <<
"This matrix is not a square matrix." << std::endl
774 <<
"This matrix is (" <<
m <<
"x" <<
n <<
")." << std::endl;
777 if(matB.
m!=
n || matB.
n!=
n){
779 std::cerr <<
"The matrix B is not a square matrix having the same size as \"this\" matrix." << std::endl
780 <<
"The B matrix is (" << matB.
m <<
"x" << matB.
n <<
")." << std::endl;
789 for(CPPL_INT
i=0;
i<
n;
i++){
795 char JOBVL(
'V'), JOBVR(
'n');
796 CPPL_INT LDA(n), LDB(n), LDVL(n), LDVR(1), LWORK(8*n), INFO(1);
797 double *BETA(
new double[n]), *VR(NULL), *WORK(
new double[LWORK]);
798 dggev_(&JOBVL, &JOBVR, &n,
array, &LDA, matB.
array, &LDB, &wr[0], &wi[0], BETA, VL.
array, &LDVL, VR, &LDVR, WORK, &LWORK, &INFO);
803 for(CPPL_INT
i=0;
i<
n;
i++){
810 for(CPPL_INT j=0; j<
n; j++){
811 if(fabs(wi[j])<DBL_MIN){
812 for(CPPL_INT
i=0;
i<
n;
i++){
818 for(CPPL_INT
i=0;
i<
n;
i++){
820 vli[j](
i) =-VL(
i,j+1);
821 vlr[j+1](
i) = VL(
i,j);
822 vli[j+1](
i) = VL(
i,j+1);
830 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
850 {CPPL_VERBOSE_REPORT;
862 CPPL_INT LWORK =std::max(3*std::min(m,n)+std::max(m,n),5*std::min(m,n));
863 double *WORK =
new double[LWORK];
866 dgesvd_(&JOBU, &JOBVT, &m, &n, array, &LDA, S.
array, U, &LDU, VT, &LDVT, WORK, &LWORK, &INFO);
871 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
886 {CPPL_VERBOSE_REPORT;
887 char JOBU(
'A'), JOBVT(
'A');
888 CPPL_INT LDA(
m), LDU(
m), LDVT(
n), LWORK(std::max(3*std::min(
m,
n)+std::max(
m,
n),5*std::min(
m,
n))), INFO(1);
889 double *WORK(
new double[LWORK]);
894 dgesvd_(&JOBU, &JOBVT, &
m, &
n,
array, &LDA, S.
array, U.
array, &LDU, VT.
array, &LDVT, WORK, &LWORK, &INFO);
899 std::cerr <<
"Serious trouble happend. INFO = " << INFO <<
"." << std::endl;
921 {CPPL_VERBOSE_REPORT;
925 std::cerr <<
"A.m and c.l should be the same." << std::endl
926 <<
"Your input was A.m=" << m <<
" and c.l=" << c.
l << std::endl;
931 std::cerr <<
"B.m and d.l should be the same." << std::endl
932 <<
"Your input was B.m=" << B.
m <<
" and d.l=" << d.
l << std::endl;
935 if( !(B.
m<=n) || !(n<=m+B.
m) ){
937 std::cerr <<
"B.m<=A.n<=A.m+B.m should be satisfied." << std::endl
938 <<
"Your input was B.m=" << B.
m <<
", A.n=" << n <<
", and A.m+B.m=" << m+B.
m << std::endl;
943 CPPL_INT lwork(-1), info(1);
948 CPPL_INT lda =std::max(CPPL_INT(1),m);
949 CPPL_INT ldb =std::max(CPPL_INT(1),B.
m);
950 dgglse_(&m, &n, &B.
m, array, &lda, B.
array, &ldb, c.
array, d.
array, x.
array, work.
array, &lwork, &info);
951 lwork =CPPL_INT(work(0));
956 dgglse_(&m, &n, &B.
m, array, &lda, B.
array, &ldb, c.
array, d.
array, x.
array, work.
array, &lwork, &info);
961 std::cerr <<
"Serious trouble happend. info = " << info <<
"." << std::endl;
dgematrix & resize(const CPPL_INT &, const CPPL_INT &)
CPPL_INT m
matrix row size
double * array
1D array to store matrix data
CPPL_INT dgeev(std::vector< double > &, std::vector< double > &)
_dgematrix i(const _dgbmatrix &mat)
dcovector & resize(const CPPL_INT &, const CPPL_INT=0)
friend void swap(dgematrix &, dgematrix &)
CPPL_INT dggev(dgematrix &, std::vector< double > &, std::vector< double > &)
CPPL_INT n
matrix column size
Real Double-precision General Dence Matrix Class.
double * array
1D array to store vector data
CPPL_INT dgesvd(dgbmatrix &)
double * array
1D array to store matrix data
CPPL_INT dgesv(dgematrix &)
Real Double-precision Row Vector Class.
CPPL_INT dgelss(dcovector &, dcovector &, CPPL_INT &, const double)
void swap(dcovector &u, dcovector &v)
CPPL_INT dgglse(dgematrix &, dcovector &, dcovector &, dcovector &)
dgbmatrix & resize(const CPPL_INT &, const CPPL_INT &, const CPPL_INT &, const CPPL_INT &)
drovector & resize(const CPPL_INT &, const CPPL_INT=0)
Real Double-precision General Band Matrix Class.
CPPL_INT dgels(dgematrix &)
CPPL_INT dgelsd(dcovector &, dcovector &, CPPL_INT &, const double)
Real Double-precision Column Vector Class.
friend _dgematrix i(const dgematrix &)
void resize(const CPPL_INT &)
Complex Double-precision Column Vector Class.