42 DEFUN (svd, args, nargout,
44 @deftypefn {Built-in Function} {@var{s} =} svd (@var{A})\n\
45 @deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A})\n\
46 @deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, @var{econ})\n\
47 @cindex singular value decomposition\n\
48 Compute the singular value decomposition of @var{A}\n\
51 A = U S V^{\\dagger}\n\
62 The function @code{svd} normally returns only the vector of singular values.\n\
63 When called with three return values, it computes\n\
68 @var{U}, @var{S}, and @var{V}.\n\
93 [u, s, v] = svd (hilb (3))\n\
103 -0.82704 0.54745 0.12766\n\
104 -0.45986 -0.52829 -0.71375\n\
105 -0.32330 -0.64901 0.68867\n\
109 1.40832 0.00000 0.00000\n\
110 0.00000 0.12233 0.00000\n\
111 0.00000 0.00000 0.00269\n\
115 -0.82704 0.54745 0.12766\n\
116 -0.45986 -0.52829 -0.71375\n\
117 -0.32330 -0.64901 0.68867\n\
121 If given a second argument, @code{svd} returns an economy-sized\n\
122 decomposition, eliminating the unnecessary rows or columns of @var{U} or\n\
124 @seealso{svd_driver, svds, eig, lu, chol, hess, qr, qz}\n\
129 int nargin = args.
length ();
131 if (nargin < 1 || nargin > 2 || nargout == 2 || nargout > 3)
142 if (arg.
ndims () != 2)
144 error (
"svd: A must be a 2-D matrix");
156 if (nr == 0 || nc == 0)
183 retval(1) =
Matrix (nr, nc);
188 retval(1) =
Matrix (0, 0);
192 retval(0) =
Matrix (0, 1);
209 error (
"svd: cannot take SVD of matrix containing Inf or NaN values");
213 FloatSVD result (tmp, type, driver);
217 if (nargout == 0 || nargout == 1)
237 error (
"svd: cannot take SVD of matrix containing Inf or NaN values");
245 if (nargout == 0 || nargout == 1)
268 error (
"svd: cannot take SVD of matrix containing Inf or NaN values");
272 SVD result (tmp, type, driver);
276 if (nargout == 0 || nargout == 1)
296 error (
"svd: cannot take SVD of matrix containing Inf or NaN values");
304 if (nargout == 0 || nargout == 1)
405 DEFUN (svd_driver, args, nargout,
407 @deftypefn {Built-in Function} {@var{val} =} svd_driver ()\n\
408 @deftypefnx {Built-in Function} {@var{old_val} =} svd_driver (@var{new_val})\n\
409 @deftypefnx {Built-in Function} {} svd_driver (@var{new_val}, \"local\")\n\
410 Query or set the underlying @sc{lapack} driver used by @code{svd}.\n\
411 Currently recognized values are @qcode{\"gesvd\"} and @qcode{\"gesdd\"}. \n\
412 The default is @qcode{\"gesvd\"}.\n\
414 When called from inside a function with the @qcode{\"local\"} option, the\n\
415 variable is changed locally for the function and any subroutines it calls. \n\
416 The original variable value is restored when exiting the function.\n\
420 static const char *driver_names[] = {
"gesvd",
"gesdd", 0 };