32 #if defined (HAVE_CONFIG_H)
58 DEFUN (ordqz, args, nargout,
156 enum { LHP, RHP, UDI, UDO, VEC,
NONE } select_mode =
NONE;
158 if (args.length () != 5)
162 if (args(4).is_string())
164 std::string opts = args(4).string_value ();
165 std::for_each (opts.begin (), opts.end (),
166 [] (
char& c) { c = std::tolower (c); });
167 if (opts ==
"lhp" || opts ==
"-")
169 else if (opts ==
"rhp" || opts ==
"+")
171 else if (opts ==
"udi" || opts ==
"s")
173 else if (opts ==
"udo" || opts ==
"b")
177 "ordqz: unknown KEYWORD, possible values: "
178 "lhp, rhp, udi, udo");
180 else if (args(4).isreal () || args(4).
isinteger () || args(4).islogical ())
182 if (args(4).rows () > 1 && args(4).columns () > 1)
184 "ordqz: SELECT argument must be a vector");
189 "ordqz: OPT must be string or a logical vector");
193 "ordqz: at most four output arguments possible");
196 F77_INT nn = to_f77_int (args(0).rows ());
197 F77_INT nc = to_f77_int (args(0).columns ());
199 if (args(0).isempty ())
211 if (args(0).iscomplex ())
212 caa = args(0).complex_matrix_value ();
214 aa = args(0).matrix_value ();
217 F77_INT b_nr = to_f77_int (args(1).rows ());
218 F77_INT b_nc = to_f77_int (args(1).columns ());
220 if (nn != b_nc || nn != b_nr)
226 if (args(1).iscomplex ())
227 cbb = args(1).complex_matrix_value ();
229 bb = args(1).matrix_value ();
232 F77_INT q_nr = to_f77_int (args(2).rows ());
233 F77_INT q_nc = to_f77_int (args(2).columns ());
235 if (nn != q_nc || nn != q_nr)
241 if (args(2).iscomplex ())
242 cqq = args(2).complex_matrix_value ().
hermitian ();
244 qq = args(2).matrix_value ().
transpose ();
247 F77_INT z_nr = to_f77_int (args(3).rows ());
248 F77_INT z_nc = to_f77_int (args(3).columns ());
250 if (nn != z_nc || nn != z_nr)
256 if (args(3).iscomplex ())
257 czz = args(3).complex_matrix_value ();
259 zz = args(3).matrix_value ();
261 bool complex_case = (args(0).iscomplex () || args(1).iscomplex ()
262 || args(2).iscomplex () || args(3).iscomplex ());
264 if (select_mode == VEC && args(4).rows () != nn && args(4).columns () != nn)
266 "ordqz: SELECT vector has the wrong number of elements");
269 if (select_mode == VEC)
270 select_array = args(4).vector_value ();
277 if (args(0).isreal ())
279 if (args(1).isreal ())
281 if (args(2).isreal ())
283 if (args(3).isreal ())
290 for (k = 0; k < nn-1; k++)
292 if (caa(k+1, k) != 0.0)
294 "ordqz: quasi upper triangular matrices are not "
295 "allowed with complex data");
298 for (k = 0; k < nn; k++)
300 alpha(k) = caa(k, k);
304 for (k = 0; k < nn; k++)
309 select(k) =
real (alpha(k) * beta(k)) < 0;
312 select(k) =
real (alpha(k) * beta(k)) > 0;
316 select(k) =
abs (alpha(k)/beta(k)) < 1.0;
322 select(k) =
abs (alpha(k)/beta(k)) > 1.0;
327 if (select_array(k) != 0.0)
339 wantq = 1, wantz = 1;
340 F77_INT ijob, mm, lrwork3, liwork, info;
341 ijob = 0, lrwork3 = 1, liwork = 1;
363 "ordqz: failed to reorder eigenvalues");
378 octave_stdout <<
"ordqz: k = " << k <<
" nn = " << nn <<
" \n";
380 if ((k < nn-1 && aa(k+1, k) == 0.0) || k == nn-1)
382 alphar(k) = aa(k, k);
389 double ar[2], ai[2], b[2], work[4];
402 (F77_CONST_CHAR_ARG2 (&qz_job, 1),
403 F77_CONST_CHAR_ARG2 (&comp_q, 1),
404 F77_CONST_CHAR_ARG2 (&comp_z, 1),
410 nullptr, nn, work, lwork, info
413 F77_CHAR_ARG_LEN (1)));
415 error(
"ordqz: failed to extract eigenvalues");
429 for (k = 0; k < nn; k++)
434 select(k) = alphar(k) * beta(k) < 0;
437 select(k) = alphar(k) * beta(k) > 0;
440 select(k) = alphar(k)*alphar(k)
441 + alphai(k)*alphai(k) < beta(k)*beta(k);
444 select(k) = alphar(k)*alphar(k)
445 + alphai(k)*alphai(k) > beta(k)*beta(k);
448 if (select_array(k) != 0.0)
460 wantq = 1, wantz = 1;
461 F77_INT ijob, mm, lrwork3, liwork, info;
462 ijob = 0, lrwork3 = 4*nn+16, liwork = nn;
484 error(
"ordqz: failed to reorder eigenvalues");
682 OCTAVE_END_NAMESPACE(
octave)
T * fortran_vec()
Size of the specified dimension.
ComplexMatrix hermitian() const
Vector representing the dimensions (size) of an Array.
ColumnVector real(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error_with_id(const char *id, const char *fmt,...)
void() error(const char *fmt,...)
#define panic_impossible()
void err_square_matrix_required(const char *fcn, const char *name)
void warn_empty_arg(const char *name)
#define F77_DBLE_CMPLX_ARG(x)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_LOGICAL
octave_f77_int_type F77_INT
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
template int8_t abs(int8_t)