Mercurial > octave
annotate scripts/linear-algebra/ordeig.m @ 28986:69ec8d9e769b
Add function ordqz (patch #9897).
* libinterp/corefcn/ordqz.cc: New file.
* libinterp/corefcn/module.mk: Add new file to build system.
* scripts/help/__unimplemented__.m: Remove file from list.
* liboctave/numeric/lo-lapack-proto.h (ztgsen): Add new function prototype.
* libinterp/corefcn/ordschur.cc (Fordschur), scripts/linear-algebra/ordeig.m:
Add seealso link to new function.
* NEWS: Announce new function.
* doc/interpreter/linalg.txi: Add docstring to manual.
* doc/interpreter/contributors.in: Add new contributor to list.
author | Martin Köhler <koehlerm@mpi-magdeburg.mpg.de> |
---|---|
date | Fri, 24 Apr 2020 12:25:38 +0200 |
parents | 6e460773bdda |
children | 7854d5752dd2 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2018-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26802
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
7 ## |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
9 ## |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
13 ## (at your option) any later version. |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
14 ## |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
18 ## GNU General Public License for more details. |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
19 ## |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
25 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
27 ## @deftypefn {} {@var{lambda} =} ordeig (@var{A}) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
28 ## @deftypefnx {} {@var{lambda} =} ordeig (@var{A}, @var{B}) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
29 ## Return the eigenvalues of quasi-triangular matrices in their order of |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
30 ## appearance in the matrix @var{A}. |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
31 ## |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
32 ## The quasi-triangular matrix @var{A} is usually the result of a Schur |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
33 ## factorization. If called with a second input @var{B} then the generalized |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
34 ## eigenvalues of the pair @var{A}, @var{B} are returned in the order of |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
35 ## appearance of the matrix @code{@var{A}-@var{lambda}*@var{B}}. The pair |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
36 ## @var{A}, @var{B} is usually the result of a QZ decomposition. |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
37 ## |
28986
69ec8d9e769b
Add function ordqz (patch #9897).
Martin Köhler <koehlerm@mpi-magdeburg.mpg.de>
parents:
28945
diff
changeset
|
38 ## @seealso{ordschur, ordqz, eig, schur, qz} |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
39 ## @end deftypefn |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
40 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
41 function lambda = ordeig (A, B) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
42 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
43 if (nargin < 1) |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
44 print_usage (); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
45 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
46 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
47 if (! isnumeric (A) || ! issquare (A)) |
28928
ae7ce8358953
maint: Add semicolon to end of all warning() and error() invocations.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
48 error ("ordeig: A must be a square matrix"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
49 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
50 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
51 n = length (A); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
52 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
53 if (nargin == 1) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
54 B = eye (n); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
55 if (isreal (A)) |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28928
diff
changeset
|
56 if (! is_quasitri (A)) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
57 error ("ordeig: A must be quasi-triangular (i.e., upper block triangular with 1x1 or 2x2 blocks on the diagonal)"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
58 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
59 else |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
60 if (! istriu (A)) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
61 error ("ordeig: A must be upper-triangular when it is complex"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
62 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
63 endif |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
64 else |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
65 if (! isnumeric (B) || ! issquare (B)) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
66 error ("ordeig: B must be a square matrix"); |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
67 elseif (length (B) != n) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
68 error ("ordeig: A and B must be the same size"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
69 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
70 if (isreal (A) && isreal (B)) |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28928
diff
changeset
|
71 if (! is_quasitri (A) || ! is_quasitri (B)) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
72 error ("ordeig: A and B must be quasi-triangular (i.e., upper block triangular with 1x1 or 2x2 blocks on the diagonal)"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
73 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
74 else |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
75 if (! istriu (A) || ! istriu (B)) |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
76 error ("ordeig: A and B must both be upper-triangular if either is complex"); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
77 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
78 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
79 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
80 |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
81 ## Start of algorithm |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
82 lambda = zeros (n, 1); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
83 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
84 i = 1; |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
85 while (i <= n) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
86 if (i == n || (A(i+1,i) == 0 && B(i+1,i) == 0)) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
87 lambda(i) = A(i,i) / B(i,i); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
88 else |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
89 a = B(i,i) * B(i+1,i+1); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
90 b = - (A(i,i) * B(i+1,i+1) + A(i+1,i+1) * B(i,i)); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
91 c = A(i,i) * A(i+1,i+1) - ... |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
92 (A(i,i+1) - B(i,i+1)) * (A(i+1,i) - B(i+1,i)); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
93 if (b > 0) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
94 lambda(i) = 2*c / (-b - sqrt (b^2 - 4*a*c)); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
95 i += 1; |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
96 lambda(i) = (-b - sqrt (b^2 - 4*a*c)) / 2 / a; |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
97 else |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
98 lambda(i) = (-b + sqrt (b^2 - 4*a*c)) / 2 / a; |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
99 i += 1; |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
100 lambda(i) = 2*c / (-b + sqrt (b^2 - 4*a*c)); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
101 endif |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
102 endif |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
103 i += 1; |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
104 endwhile |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
105 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
106 endfunction |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
107 |
26802
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
108 ## Check whether a matrix is quasi-triangular |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28928
diff
changeset
|
109 function retval = is_quasitri (A) |
26802
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
110 if (length (A) <= 2) |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
111 retval = true; |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
112 else |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
113 v = diag (A, -1) != 0; |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
114 retval = (all (tril (A, -2)(:) == 0) && all (v(1:end-1) + v(2:end) < 2)); |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
115 endif |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
116 endfunction |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
117 |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
118 |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
119 %!test |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
120 %! A = toeplitz ([0, 1, 0, 0], [0, -1, 0, 0]); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
121 %! T = schur (A); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
122 %! lambda = ordeig (T); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
123 %! assert (lambda, [1.61803i; -1.61803i; 0.61803i; -0.61803i], 1e-4); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
124 |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
125 %!test |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
126 %! A = toeplitz ([0, 1, 0, 0], [0, -1, 0, 0]); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
127 %! B = toeplitz ([0, 0, 0, 1], [0, -1, 0, 2]); |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
128 %! [AA, BB] = qz (A, B); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
129 %! assert (isreal (AA) && isreal (BB)); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
130 %! lambda = ordeig (AA, BB); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
131 %! assert (lambda, [0.5+0.86603i; 0.5-0.86603i; i; -i], 1e-4); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
132 %! [AA, BB] = qz (complex (A), complex (B)); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
133 %! assert (iscomplex (AA) && iscomplex (BB)); |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
134 %! lambda = ordeig (AA, BB); |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
135 %! assert (lambda, diag (AA) ./ diag (BB)); |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
136 |
26802
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
137 ## Check trivial 1x1 case |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
138 %!test <*55779> |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
139 %! lambda = ordeig ([6], [2]); |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
140 %! assert (lambda, 3); |
74e63d2fd0d0
ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents:
26376
diff
changeset
|
141 |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
142 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
143 %!error <Invalid call> ordeig () |
25736
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
144 %!error <A must be a square matrix> ordeig ('a') |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
145 %!error <A must be a square matrix> ordeig ([1, 2, 3]) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
146 %!error <A must be quasi-triangular> ordeig (magic (3)) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
147 %!error <A must be upper-triangular> ordeig ([1, 0; i, 1]) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
148 %!error <B must be a square matrix> ordeig (1, 'a') |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
149 %!error <B must be a square matrix> ordeig (1, [1, 2]) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
150 %!error <A and B must be the same size> ordeig (1, ones (2,2)) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
151 %!error <A and B must be quasi-triangular> |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
152 %! ordeig (triu (magic (3)), magic (3)) |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
153 %!error <A and B must both be upper-triangular> |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
154 %! ordeig ([1, 1; 0, 1], [1, 0; i, 1]) |