Mercurial > octave
annotate scripts/linear-algebra/ordeig.m @ 28896:90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
* acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m,
asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m,
cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, cart2pol.m, cart2sph.m,
celldisp.m, common_size.m, deal.m, del2.m, fliplr.m, integral2.m, interp1.m,
isequal.m, isequaln.m, nextpow2.m, pol2cart.m, quad2d.m, quadl.m, quadv.m,
randi.m, rat.m, repelem.m, rescale.m, shiftdim.m, sortrows.m, sph2cart.m,
xor.m, convhull.m, delaunay.m, delaunayn.m, griddata.m, griddatan.m,
inpolygon.m, voronoi.m, voronoin.m, listdlg.m, msgbox.m, questdlg.m,
rmappdata.m, setappdata.m, __gripe_missing_component__.m,
get_first_help_sentence.m, type.m, which.m, cmpermute.m, cmunique.m,
gray2ind.m, imfinfo.m, imshow.m, imwrite.m, ind2rgb.m, movie.m, rgb2ind.m,
importdata.m, bandwidth.m, condeig.m, gls.m, housh.m, linsolve.m, logm.m,
lscov.m, normest.m, normest1.m, ols.m, ordeig.m, planerot.m, qzhess.m, rref.m,
copyfile.m, delete.m, dos.m, fileparts.m, getfield.m, menu.m, mkdir.m,
movefile.m, orderfields.m, publish.m, setfield.m, substruct.m, unix.m,
unpack.m, decic.m, ode23.m, ode23s.m, ode45.m, fminsearch.m, lsqnonneg.m,
pqpnonneg.m, sqp.m, annotation.m, lighting.m, shading.m, area.m, compass.m,
contourc.m, feather.m, fplot.m, hist.m, isocaps.m, isocolors.m, isonormals.m,
isosurface.m, ostreamtube.m, pie.m, pie3.m, reducepatch.m, reducevolume.m,
rose.m, smooth3.m, stairs.m, stem.m, stem3.m, stream2.m, stream3.m,
streamline.m, streamribbon.m, streamtube.m, surfnorm.m, trimesh.m, trisurf.m,
colstyle.m, hgload.m, linkprop.m, meshgrid.m, ndgrid.m, padecoef.m, polyfit.m,
polyval.m, unmkpp.m, profexport.m, ismember.m, unique.m, movfun.m, movslice.m,
periodogram.m, sinc.m, spdiags.m, sprandsym.m, betaincinv.m, ellipke.m,
factor.m, gammainc.m, gammaincinv.m, isprime.m, lcm.m, gallery.m, hadamard.m,
bounds.m, corrcoef.m, discrete_rnd.m, empirical_rnd.m, histc.m, mode.m,
movmad.m, movmax.m, movmean.m, movmedian.m, movmin.m, movprod.m, movstd.m,
movsum.m, movvar.m, ranks.m, runlength.m, zscore.m, str2num.m, strchr.m,
strsplit.m, strtok.m, untabify.m, assert.m, demo.m, example.m, speed.m, test.m,
datenum.m, datevec.m, webread.m, webwrite.m:
Add expected error message <Invalid call> to BIST tests for nargin.
Remove redundant tests for nargin greater than the number of declared inputs
which are now handled by interpreter.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 11 Oct 2020 21:59:35 -0700 |
parents | 28de41192f3c |
children | ae7ce8358953 |
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 ## |
138f91fb2883
ordeig.m: Use Octave coding conventions in function.
Rik <rik@octave.org>
parents:
25734
diff
changeset
|
38 ## @seealso{ordschur, 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)) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
48 error ("ordeig: A must be a square matrix") |
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)) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
56 if (! isquasitri (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)) |
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
71 if (! isquasitri (A) || ! isquasitri (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 |
25734
c7095a755185
New function "ordeig" (patch #9670)
Sébastien Villemot <sebastien@debian.org>
parents:
diff
changeset
|
109 function retval = isquasitri (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]) |