40 template <
class Matrix>
60 DEFUN (schur, args, nargout,
62 @deftypefn {Built-in Function} {@var{S} =} schur (@var{A})\n\
63 @deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, \"real\")\n\
64 @deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, \"complex\")\n\
65 @deftypefnx {Built-in Function} {@var{S} =} schur (@var{A}, @var{opt})\n\
66 @deftypefnx {Built-in Function} {[@var{U}, @var{S}] =} schur (@var{A}, @dots{})\n\
67 @cindex Schur decomposition\n\
68 Compute the Schur@tie{}decomposition of @var{A}\n\
77 @code{@var{S} = @var{U}' * @var{A} * @var{U}}\n\
81 where @var{U} is a unitary matrix\n\
83 ($U^T U$ is identity)\n\
86 (@code{@var{U}'* @var{U}} is identity)\n\
88 and @var{S} is upper triangular. The eigenvalues of @var{A} (and @var{S})\n\
89 are the diagonal elements of @var{S}. If the matrix @var{A}\n\
90 is real, then the real Schur@tie{}decomposition is computed, in which the\n\
91 matrix @var{U} is orthogonal and @var{S} is block upper triangular\n\
92 with blocks of size at most\n\
99 along the diagonal. The diagonal elements of @var{S}\n\
100 (or the eigenvalues of the\n\
107 blocks, when appropriate) are the eigenvalues of @var{A} and @var{S}.\n\
109 The default for real matrices is a real Schur@tie{}decomposition.\n\
110 A complex decomposition may be forced by passing the flag\n\
111 @qcode{\"complex\"}.\n\
113 The eigenvalues are optionally ordered along the diagonal according to\n\
114 the value of @var{opt}. @code{@var{opt} = \"a\"} indicates that all\n\
115 eigenvalues with negative real parts should be moved to the leading\n\
117 (used in @code{are}), @code{@var{opt} = \"d\"} indicates that all eigenvalues\n\
118 with magnitude less than one should be moved to the leading block of @var{S}\n\
119 (used in @code{dare}), and @code{@var{opt} = \"u\"}, the default, indicates\n\
120 that no ordering of eigenvalues should occur. The leading @var{k}\n\
121 columns of @var{U} always span the @var{A}-invariant\n\
122 subspace corresponding to the @var{k} leading eigenvalues of @var{S}.\n\
124 The Schur@tie{}decomposition is used to compute eigenvalues of a\n\
125 square matrix, and has applications in the solution of algebraic\n\
126 Riccati equations in control (see @code{are} and @code{dare}).\n\
127 @seealso{rsf2csf, lu, chol, hess, qr, qz, svd}\n\
132 int nargin = args.
length ();
134 if (nargin < 1 || nargin > 2 || nargout > 2)
146 ord = args(1).string_value ();
150 error (
"schur: second argument must be a string");
155 bool force_complex =
false;
159 ord = std::string ();
161 else if (ord ==
"complex")
163 force_complex =
true;
164 ord = std::string ();
168 char ord_char = ord.empty () ?
'U' : ord[0];
170 if (ord_char !=
'U' && ord_char !=
'A' && ord_char !=
'D'
171 && ord_char !=
'u' && ord_char !=
'a' && ord_char !=
'd')
173 warning (
"schur: incorrect ordered schur argument '%c'",
198 if (nargout == 0 || nargout == 1)
218 if (nargout == 0 || nargout == 1)
240 if (nargout == 0 || nargout == 1)
242 SCHUR result (tmp, ord,
false);
247 SCHUR result (tmp, ord,
true);
260 if (nargout == 0 || nargout == 1)
296 DEFUN (rsf2csf, args, nargout,
298 @deftypefn {Function File} {[@var{U}, @var{T}] =} rsf2csf (@var{UR}, @var{TR})\n\
299 Convert a real, upper quasi-triangular Schur@tie{}form @var{TR} to a complex,\n\
300 upper triangular Schur@tie{}form @var{T}.\n\
302 Note that the following relations hold:\n\
305 $UR \\cdot TR \\cdot {UR}^T = U T U^{\\dagger}$ and\n\
306 $U^{\\dagger} U$ is the identity matrix I.\n\
309 @tcode{@var{UR} * @var{TR} * @var{UR}' = @var{U} * @var{T} * @var{U}'} and\n\
310 @code{@var{U}' * @var{U}} is the identity matrix I.\n\
313 Note also that @var{U} and @var{T} are not unique.\n\
319 if (args.length () == 2 && nargout <= 2)
321 if (! args(0).is_numeric_type ())
323 else if (! args(1).is_numeric_type ())
325 else if (args(0).is_complex_type () || args(1).is_complex_type ())
326 error (
"rsf2csf: UR and TR must be real matrices");
330 if (args(0).is_single_type () || args(1).is_single_type ())
344 Matrix u = args(0).matrix_value ();
345 Matrix t = args(1).matrix_value ();