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\
412 Currently recognized values are @qcode{\"gesvd\"} and @qcode{\"gesdd\"}.\n\
413 The default is @qcode{\"gesvd\"}.\n\
415 When called from inside a function with the @qcode{\"local\"} option, the\n\
416 variable is changed locally for the function and any subroutines it calls.\n\
417 The original variable value is restored when exiting the function.\n\
421 static const char *driver_names[] = {
"gesvd",
"gesdd", 0 };
DiagMatrix singular_values(void) const
bool is_real_type(void) const
void gripe_wrong_type_arg(const char *name, const char *s, bool is_error)
octave_idx_type rows(void) const
Matrix right_singular_matrix(void) const
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
OCTINTERP_API void print_usage(void)
octave_idx_type length(void) const
FloatComplexMatrix left_singular_matrix(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
FloatComplexMatrix right_singular_matrix(void) const
bool any_element_is_inf_or_nan(void) const
ColumnVector extract_diag(octave_idx_type k=0) const
FloatDiagMatrix singular_values(void) const
octave_idx_type columns(void) const
F77_RET_T const double const double * f
FloatMatrix left_singular_matrix(void) const
FloatMatrix right_singular_matrix(void) const
FloatDiagMatrix singular_values(void) const
bool is_complex_type(void) const
#define SET_INTERNAL_VARIABLE_CHOICES(NM, CHOICES)
FloatColumnVector extract_diag(octave_idx_type k=0) const
bool any_element_is_inf_or_nan(void) const
Matrix matrix_value(bool frc_str_conv=false) const
ComplexMatrix left_singular_matrix(void) const
Matrix left_singular_matrix(void) const
bool any_element_is_inf_or_nan(void) const
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
DiagMatrix singular_values(void) const
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
bool any_element_is_inf_or_nan(void) const
bool is_single_type(void) const
ComplexMatrix right_singular_matrix(void) const