annotate scripts/linear-algebra/ordeig.m @ 30379:363fb10055df stable

maint: Style check m-files ahead of 7.1 release. * Map.m, integral3.m, logspace.m, quad2d.m, quadgk.m, quadl.m, tsearchn.m, get_first_help_sentence.m, print_usage.m, getframe.m, imformats.m, javaclasspath.m, condest.m, null.m, ordeig.m, inputParser.m, license.m, memory.m, methods.m, __publish_html_output__.m, __publish_latex_output__.m, publish.m, ode15s.m, fminbnd.m, fzero.m, configure_make.m, get_description.m, get_forge_pkg.m, annotation.m, camlookat.m, legend.m, __gnuplot_legend__.m, bar.m, colorbar.m, fill3.m, isosurface.m, plotyy.m, polar.m, __bar__.m, __ezplot__.m, __patch__.m, __pie__.m, __plt__.m, __scatter__.m, smooth3.m, stemleaf.m, __gnuplot_drawnow__.m, print.m, printd.m, __add_default_menu__.m, __gnuplot_draw_axes__.m, __gnuplot_print__.m, __print_parse_opts__.m, struct2hdl.m, profexport.m, profile.m, movfun.m, sprandsym.m, betaincinv.m, factor.m, nchoosek.m, gallery.m, hadamard.m, iqr.m, ranks.m, __run_test_suite__.m, test.m, datevec.m, weboptions.m: Style check m-files ahead of 7.1 release.
author Rik <rik@octave.org>
date Fri, 26 Nov 2021 20:53:22 -0800
parents 7854d5752dd2
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 ## Copyright (C) 2018-2021 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)
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
110
26802
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
111 if (length (A) <= 2)
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
112 retval = true;
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
113 else
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
114 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
115 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
116 endif
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
117
25734
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
118 endfunction
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
119
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
120
25734
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
121 %!test
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
122 %! 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
123 %! T = schur (A);
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
124 %! lambda = ordeig (T);
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
125 %! 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
126
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
127 %!test
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
128 %! 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
129 %! 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
130 %! [AA, BB] = qz (A, B);
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
131 %! assert (isreal (AA) && isreal (BB));
25734
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
132 %! lambda = ordeig (AA, BB);
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
133 %! 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
134 %! [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
135 %! assert (iscomplex (AA) && iscomplex (BB));
25734
c7095a755185 New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
136 %! lambda = ordeig (AA, BB);
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
137 %! assert (lambda, diag (AA) ./ diag (BB));
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
138
26802
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
139 ## Check trivial 1x1 case
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
140 %!test <*55779>
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
141 %! lambda = ordeig ([6], [2]);
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
142 %! assert (lambda, 3);
74e63d2fd0d0 ordeig.m: Do not fail on 1x1 matrices (bug #55779);
Sebastien Villemot <sebastien@debian.org>
parents: 26376
diff changeset
143
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
144 ## 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
145 %!error <Invalid call> ordeig ()
25736
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
146 %!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
147 %!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
148 %!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
149 %!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
150 %!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
151 %!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
152 %!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
153 %!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
154 %! ordeig (triu (magic (3)), magic (3))
138f91fb2883 ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents: 25734
diff changeset
155 %!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
156 %! ordeig ([1, 1; 0, 1], [1, 0; i, 1])