comparison src/svd.cc @ 539:5ec10a984241

[project @ 1994-07-21 22:40:04 by jwe]
author jwe
date Thu, 21 Jul 1994 22:42:09 +0000
parents b9284136189a
children 20fbad23ae51
comparison
equal deleted inserted replaced
538:8e134d3b21c9 539:5ec10a984241
33 #include "gripes.h" 33 #include "gripes.h"
34 #include "error.h" 34 #include "error.h"
35 #include "defun-dld.h" 35 #include "defun-dld.h"
36 36
37 DEFUN_DLD ("svd", Fsvd, Ssvd, 2, 3, 37 DEFUN_DLD ("svd", Fsvd, Ssvd, 2, 3,
38 "S = svd (X) or [U, S, V] = svd (X)\n\ 38 "S = svd (X) or [U, S, V] = svd (X [, 0])\n\
39 \n\ 39 \n\
40 compute the singular value decomposition of X") 40 Compute the singular value decomposition of X. Given a second input\n\
41 argument, an `economy' sized factorization is computed that omits\n\
42 unnecessary rows and columns of U and V")
41 { 43 {
42 Octave_object retval; 44 Octave_object retval;
43 45
44 int nargin = args.length (); 46 int nargin = args.length ();
45 47
46 if (nargin != 2 || nargout == 2 || nargout > 3) 48 if (nargin < 2 || nargin > 3 || nargout == 2 || nargout > 3)
47 { 49 {
48 print_usage ("svd"); 50 print_usage ("svd");
49 return retval; 51 return retval;
50 } 52 }
51 53
92 default: 94 default:
93 panic_impossible (); 95 panic_impossible ();
94 break; 96 break;
95 } 97 }
96 98
99 SVD::type type = (nargin == 3) ? SVD::economy : SVD::std;
100
97 switch (arg.const_type ()) 101 switch (arg.const_type ())
98 { 102 {
99 case tree_constant_rep::scalar_constant: 103 case tree_constant_rep::scalar_constant:
100 case tree_constant_rep::matrix_constant: 104 case tree_constant_rep::matrix_constant:
101 { 105 {
102 SVD result (tmp); 106 SVD result (tmp, type);
103 107
104 DiagMatrix sigma = result.singular_values (); 108 DiagMatrix sigma = result.singular_values ();
105 109
106 if (nargout == 0 || nargout == 1) 110 if (nargout == 0 || nargout == 1)
107 { 111 {
118 } 122 }
119 break; 123 break;
120 case tree_constant_rep::complex_scalar_constant: 124 case tree_constant_rep::complex_scalar_constant:
121 case tree_constant_rep::complex_matrix_constant: 125 case tree_constant_rep::complex_matrix_constant:
122 { 126 {
123 ComplexSVD result (ctmp); 127 ComplexSVD result (ctmp, type);
124 128
125 DiagMatrix sigma = result.singular_values (); 129 DiagMatrix sigma = result.singular_values ();
126 130
127 if (nargout == 0 || nargout == 1) 131 if (nargout == 0 || nargout == 1)
128 { 132 {