Mercurial > hg > octave-lyh
comparison liboctave/Matrix-ext.cc @ 227:1a48a1b91489
[project @ 1993-11-15 10:10:35 by jwe]
author | jwe |
---|---|
date | Mon, 15 Nov 1993 10:11:59 +0000 |
parents | 2db13bf4f3e2 |
children | 0e77ff277fdc |
comparison
equal
deleted
inserted
replaced
226:c4027b057786 | 227:1a48a1b91489 |
---|---|
25 #pragma implementation | 25 #pragma implementation |
26 #endif | 26 #endif |
27 | 27 |
28 #include "Matrix.h" | 28 #include "Matrix.h" |
29 #include "mx-inlines.cc" | 29 #include "mx-inlines.cc" |
30 #include "lo-error.h" | |
30 | 31 |
31 /* | 32 /* |
32 * AEPBALANCE operations | 33 * AEPBALANCE operations |
33 */ | 34 */ |
34 | 35 |
35 int | 36 int |
36 AEPBALANCE::init (const Matrix& a, const char *balance_job) | 37 AEPBALANCE::init (const Matrix& a, const char *balance_job) |
37 { | 38 { |
38 if (a.nr != a.nc) | 39 if (a.nr != a.nc) |
39 FAIL; | 40 { |
41 (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); | |
42 return -1; | |
43 } | |
40 | 44 |
41 int n = a.nc; | 45 int n = a.nc; |
42 | 46 |
43 // Parameters for balance call. | 47 // Parameters for balance call. |
44 | 48 |
108 | 112 |
109 int | 113 int |
110 GEPBALANCE::init (const Matrix& a, const Matrix& b, const char *balance_job) | 114 GEPBALANCE::init (const Matrix& a, const Matrix& b, const char *balance_job) |
111 { | 115 { |
112 if (a.nr != a.nc || a.nr != b.nr || b.nr != b.nc) | 116 if (a.nr != a.nc || a.nr != b.nr || b.nr != b.nc) |
113 FAIL; | 117 { |
118 (*current_liboctave_error_handler) | |
119 ("GEPBALANCE requires square matrices of the same size"); | |
120 return -1; | |
121 } | |
114 | 122 |
115 int n = a.nc; | 123 int n = a.nc; |
116 | 124 |
117 // Parameters for balance call. | 125 // Parameters for balance call. |
118 | 126 |
234 | 242 |
235 int | 243 int |
236 CHOL::init (const Matrix& a) | 244 CHOL::init (const Matrix& a) |
237 { | 245 { |
238 if (a.nr != a.nc) | 246 if (a.nr != a.nc) |
239 FAIL; | 247 { |
248 (*current_liboctave_error_handler) ("CHOL requires square matrix"); | |
249 return -1; | |
250 } | |
240 | 251 |
241 char uplo = 'U'; | 252 char uplo = 'U'; |
242 | 253 |
243 int n = a.nc; | 254 int n = a.nc; |
244 int info; | 255 int info; |
264 | 275 |
265 int | 276 int |
266 ComplexCHOL::init (const ComplexMatrix& a) | 277 ComplexCHOL::init (const ComplexMatrix& a) |
267 { | 278 { |
268 if (a.nr != a.nc) | 279 if (a.nr != a.nc) |
269 FAIL; | 280 { |
281 (*current_liboctave_error_handler) | |
282 ("ComplexCHOL requires square matrix"); | |
283 return -1; | |
284 } | |
270 | 285 |
271 char uplo = 'U'; | 286 char uplo = 'U'; |
272 | 287 |
273 int n = a.nc; | 288 int n = a.nc; |
274 int info; | 289 int info; |
297 | 312 |
298 int | 313 int |
299 HESS::init (const Matrix& a) | 314 HESS::init (const Matrix& a) |
300 { | 315 { |
301 if (a.nr != a.nc) | 316 if (a.nr != a.nc) |
302 FAIL; | 317 { |
318 (*current_liboctave_error_handler) ("HESS requires square matrix"); | |
319 return -1; | |
320 } | |
303 | 321 |
304 char jobbal = 'N'; | 322 char jobbal = 'N'; |
305 char side = 'R'; | 323 char side = 'R'; |
306 | 324 |
307 int n = a.nc; | 325 int n = a.nc; |
355 | 373 |
356 int | 374 int |
357 ComplexHESS::init (const ComplexMatrix& a) | 375 ComplexHESS::init (const ComplexMatrix& a) |
358 { | 376 { |
359 if (a.nr != a.nc) | 377 if (a.nr != a.nc) |
360 FAIL; | 378 { |
379 (*current_liboctave_error_handler) | |
380 ("ComplexHESS requires square matrix"); | |
381 return -1; | |
382 } | |
361 | 383 |
362 char job = 'N'; | 384 char job = 'N'; |
363 char side = 'R'; | 385 char side = 'R'; |
364 | 386 |
365 int n = a.nc; | 387 int n = a.nc; |
427 | 449 |
428 int | 450 int |
429 SCHUR::init (const Matrix& a, const char *ord) | 451 SCHUR::init (const Matrix& a, const char *ord) |
430 { | 452 { |
431 if (a.nr != a.nc) | 453 if (a.nr != a.nc) |
432 FAIL; | 454 { |
455 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); | |
456 return -1; | |
457 } | |
433 | 458 |
434 char jobvs = 'V'; | 459 char jobvs = 'V'; |
435 char sort; | 460 char sort; |
436 | 461 |
437 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') | 462 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
514 | 539 |
515 int | 540 int |
516 ComplexSCHUR::init (const ComplexMatrix& a, const char *ord) | 541 ComplexSCHUR::init (const ComplexMatrix& a, const char *ord) |
517 { | 542 { |
518 if (a.nr != a.nc) | 543 if (a.nr != a.nc) |
519 FAIL; | 544 { |
545 (*current_liboctave_error_handler) | |
546 ("ComplexSCHUR requires square matrix"); | |
547 return -1; | |
548 } | |
520 | 549 |
521 char jobvs = 'V'; | 550 char jobvs = 'V'; |
522 char sort; | 551 char sort; |
523 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') | 552 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
524 sort = 'S'; | 553 sort = 'S'; |
686 | 715 |
687 int | 716 int |
688 EIG::init (const Matrix& a) | 717 EIG::init (const Matrix& a) |
689 { | 718 { |
690 if (a.nr != a.nc) | 719 if (a.nr != a.nc) |
691 FAIL; | 720 { |
721 (*current_liboctave_error_handler) ("EIG requires square matrix"); | |
722 return -1; | |
723 } | |
692 | 724 |
693 int n = a.nr; | 725 int n = a.nr; |
694 | 726 |
695 int info; | 727 int info; |
696 | 728 |
723 v.elem (i, j) = vr.elem (i, j); | 755 v.elem (i, j) = vr.elem (i, j); |
724 } | 756 } |
725 else | 757 else |
726 { | 758 { |
727 if (j+1 >= n) | 759 if (j+1 >= n) |
728 FAIL; | 760 { |
761 (*current_liboctave_error_handler) ("EIG: internal error"); | |
762 return -1; | |
763 } | |
729 | 764 |
730 for (int i = 0; i < n; i++) | 765 for (int i = 0; i < n; i++) |
731 { | 766 { |
732 lambda.elem (j) = Complex (wr[j], wi[j]); | 767 lambda.elem (j) = Complex (wr[j], wi[j]); |
733 lambda.elem (j+1) = Complex (wr[j+1], wi[j+1]); | 768 lambda.elem (j+1) = Complex (wr[j+1], wi[j+1]); |
751 int | 786 int |
752 EIG::init (const ComplexMatrix& a) | 787 EIG::init (const ComplexMatrix& a) |
753 { | 788 { |
754 | 789 |
755 if (a.nr != a.nc) | 790 if (a.nr != a.nc) |
756 FAIL; | 791 { |
792 (*current_liboctave_error_handler) ("EIG requires square matrix"); | |
793 return -1; | |
794 } | |
757 | 795 |
758 int n = a.nr; | 796 int n = a.nr; |
759 | 797 |
760 int info; | 798 int info; |
761 | 799 |
793 */ | 831 */ |
794 | 832 |
795 LU::LU (const Matrix& a) | 833 LU::LU (const Matrix& a) |
796 { | 834 { |
797 if (a.nr == 0 || a.nc == 0 || a.nr != a.nc) | 835 if (a.nr == 0 || a.nc == 0 || a.nr != a.nc) |
798 FAIL; | 836 { |
837 (*current_liboctave_error_handler) ("LU requires square matrix"); | |
838 return; | |
839 } | |
799 | 840 |
800 int n = a.nr; | 841 int n = a.nr; |
801 | 842 |
802 int *ipvt = new int [n]; | 843 int *ipvt = new int [n]; |
803 int *pvt = new int [n]; | 844 int *pvt = new int [n]; |
852 } | 893 } |
853 | 894 |
854 ComplexLU::ComplexLU (const ComplexMatrix& a) | 895 ComplexLU::ComplexLU (const ComplexMatrix& a) |
855 { | 896 { |
856 if (a.nr == 0 || a.nc == 0 || a.nr != a.nc) | 897 if (a.nr == 0 || a.nc == 0 || a.nr != a.nc) |
857 FAIL; | 898 { |
899 (*current_liboctave_error_handler) ("ComplexLU requires square matrix"); | |
900 return; | |
901 } | |
858 | 902 |
859 int n = a.nr; | 903 int n = a.nr; |
860 | 904 |
861 int *ipvt = new int [n]; | 905 int *ipvt = new int [n]; |
862 int *pvt = new int [n]; | 906 int *pvt = new int [n]; |
918 { | 962 { |
919 int m = a.nr; | 963 int m = a.nr; |
920 int n = a.nc; | 964 int n = a.nc; |
921 | 965 |
922 if (m == 0 || n == 0) | 966 if (m == 0 || n == 0) |
923 FAIL; | 967 { |
968 (*current_liboctave_error_handler) ("QR must have non-empty matrix"); | |
969 return; | |
970 } | |
924 | 971 |
925 double *tmp_data; | 972 double *tmp_data; |
926 int min_mn = m < n ? m : n; | 973 int min_mn = m < n ? m : n; |
927 double *tau = new double[min_mn]; | 974 double *tau = new double[min_mn]; |
928 int lwork = 32*n; | 975 int lwork = 32*n; |
964 { | 1011 { |
965 int m = a.nr; | 1012 int m = a.nr; |
966 int n = a.nc; | 1013 int n = a.nc; |
967 | 1014 |
968 if (m == 0 || n == 0) | 1015 if (m == 0 || n == 0) |
969 FAIL; | 1016 { |
1017 (*current_liboctave_error_handler) | |
1018 ("ComplexQR must have non-empty matrix"); | |
1019 return; | |
1020 } | |
970 | 1021 |
971 Complex *tmp_data; | 1022 Complex *tmp_data; |
972 int min_mn = m < n ? m : n; | 1023 int min_mn = m < n ? m : n; |
973 Complex *tau = new Complex[min_mn]; | 1024 Complex *tau = new Complex[min_mn]; |
974 int lwork = 32*n; | 1025 int lwork = 32*n; |