annotate scripts/general/cplxpair.m @ 20610:a61f0d6beb71

inputParser: do not perform validation of default values (bug #45837)
author Carnë Draug <carandraug@octave.org>
date Thu, 08 Oct 2015 20:15:19 +0100
parents 4c2e76cbdc7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18713
diff changeset
1 ## Copyright (C) 2000-2015 Paul Kienzle
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
2 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
4 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
9 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
14 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
18
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
20 ## @deftypefn {Function File} {} cplxpair (@var{z})
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
21 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol})
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
22 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol}, @var{dim})
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
23 ## Sort the numbers @var{z} into complex conjugate pairs ordered by increasing
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
24 ## real part.
20193
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
25 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
26 ## The negative imaginary complex numbers are placed first within each pair.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
27 ## All real numbers (those with
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
28 ## @code{abs (imag (@var{z}) / @var{z}) < @var{tol}}) are placed after the
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
29 ## complex pairs.
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
30 ##
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
31 ## @var{tol} is a weighting factor which determines the tolerance of matching.
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
32 ## The default value is 100 and the resulting tolerance for a given complex
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
33 ## pair is @code{100 * eps (abs (@var{z}(i))}.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
34 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
35 ## By default the complex pairs are sorted along the first non-singleton
20193
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
36 ## dimension of @var{z}. If @var{dim} is specified, then the complex pairs are
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
37 ## sorted along this dimension.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
38 ##
9154
761fc0d3d980 Update section 17.2 (Complex Arithmetic) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9153
diff changeset
39 ## Signal an error if some complex numbers could not be paired. Signal an
20193
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
40 ## error if all complex numbers are not exact conjugates (to within @var{tol}).
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
41 ## Note that there is no defined order for pairs with identical real parts but
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
42 ## differing imaginary parts.
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
43 ## @c Set example in small font to prevent overfull line
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
44 ##
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7017
diff changeset
45 ## @smallexample
5831
b0d4ff99a0c5 [project @ 2006-05-26 21:06:00 by jwe]
jwe
parents: 5820
diff changeset
46 ## cplxpair (exp(2i*pi*[0:4]'/5)) == exp(2i*pi*[3; 2; 4; 1; 0]/5)
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7017
diff changeset
47 ## @end smallexample
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
48 ## @end deftypefn
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
49
8202
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7795
diff changeset
50 ## FIXME: subsort returned pairs by imaginary magnitude
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
51 ## FIXME: Why doesn't exp (2i*pi*[0:4]'/5) produce exact conjugates? Does
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
52 ## FIXME: it in Matlab? The reason is that complex pairs are supposed
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
53 ## FIXME: to be exact conjugates, and not rely on a tolerance test.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
54
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
55 ## 2006-05-12 David Bateman - Modified for NDArrays
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
56
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
57 function y = cplxpair (z, tol, dim)
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
58
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
59 if (nargin < 1 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5831
diff changeset
60 print_usage ();
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
61 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
62
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
63 if (isempty (z))
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
64 y = zeros (size (z));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
65 return;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
66 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
67
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
68 if (nargin < 2 || isempty (tol))
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
69 tol = 100;
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
70 elseif (! isscalar (tol) || tol < 0)
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
71 error ("cplxpair: TOL must be a positive scalar number")
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
72 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
73
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
74 nd = ndims (z);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
75 if (nargin < 3)
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
76 ## Find the first singleton dimension.
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
77 sz = size (z);
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
78 (dim = find (sz > 1, 1)) || (dim = 1);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
79 else
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
80 dim = floor (dim);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
81 if (dim < 1 || dim > nd)
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
82 error ("cplxpair: invalid dimension DIM");
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
83 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
84 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
85
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
86 ## Move dimension to treat to first position, and convert to a 2-D matrix.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
87 perm = [dim:nd, 1:dim-1];
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
88 z = permute (z, perm);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
89 sz = size (z);
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
90 n = sz(1);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
91 m = prod (sz) / n;
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
92 z = reshape (z, n, m);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
93
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
94 ## Sort the sequence in terms of increasing real values.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
95 [q, idx] = sort (real (z), 1);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
96 z = z(idx + n * ones (n, 1) * [0:m-1]);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
97
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
98 ## Put the purely real values at the end of the returned list.
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
99 cls = ifelse (isa (z, "single"), "single", "double");
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
100 [idxi, idxj] = find (abs (imag (z)) ./ (abs (z) + realmin (cls)) ...
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
101 < tol*eps (abs (z)));
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
102 q = sparse (idxi, idxj, 1, n, m);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
103 nr = sum (q, 1);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
104 [q, idx] = sort (q, 1);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
105 z = z(idx);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
106 y = z;
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
107
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
108 ## For each remaining z, place the value and its conjugate at the start of
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
109 ## the returned list, and remove them from further consideration.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
110 for j = 1:m
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
111 p = n - nr(j);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
112 for i = 1:2:p
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
113 if (i+1 > p)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
114 error ("cplxpair: could not pair all complex numbers");
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
115 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
116 [v, idx] = min (abs (z(i+1:p) - conj (z(i))));
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
117 if (v > tol*eps (abs (z(i))))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
118 error ("cplxpair: could not pair all complex numbers");
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
119 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
120 if (imag (z(i)) < 0)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9154
diff changeset
121 y([i, i+1]) = z([i, idx+i]);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
122 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9154
diff changeset
123 y([i, i+1]) = z([idx+i, i]);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
124 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
125 z(idx+i) = z(i+1);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
126 endfor
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
127 endfor
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
128
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
129 ## Reshape the output matrix.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
130 y = ipermute (reshape (y, sz), perm);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
131
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
132 endfunction
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
133
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
134
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
135 %!demo
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
136 %! [ cplxpair(exp(2i*pi*[0:4]'/5)), exp(2i*pi*[3; 2; 4; 1; 0]/5) ]
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
137
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
138 %!assert (isempty (cplxpair ([])))
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
139 %!assert (cplxpair (1), 1)
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
140 %!assert (cplxpair ([1+1i, 1-1i]), [1-1i, 1+1i])
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
141 %!assert (cplxpair ([1+1i, 1+1i, 1, 1-1i, 1-1i, 2]), ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
142 %! [1-1i, 1+1i, 1-1i, 1+1i, 1, 2])
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
143 %!assert (cplxpair ([1+1i; 1+1i; 1; 1-1i; 1-1i; 2]), ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
144 %! [1-1i; 1+1i; 1-1i; 1+1i; 1; 2])
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
145 %!assert (cplxpair ([0, 1, 2]), [0, 1, 2])
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
146
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
147 %!shared z
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
148 %! z = exp (2i*pi*[4; 3; 5; 2; 6; 1; 0]/7);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
149 %!assert (cplxpair (z(randperm (7))), z)
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
150 %!assert (cplxpair (z(randperm (7))), z)
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
151 %!assert (cplxpair (z(randperm (7))), z)
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
152 %!assert (cplxpair ([z(randperm (7)), z(randperm (7))]), [z,z])
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
153 %!assert (cplxpair ([z(randperm (7)), z(randperm (7))],[],1), [z,z])
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
154 %!assert (cplxpair ([z(randperm (7)).'; z(randperm (7)).'],[],2), [z.';z.'])
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
155
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
156 ## Test tolerance
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
157 %!assert (cplxpair ([2000 * (1+eps) + 4j; 2000 * (1-eps) - 4j]), ...
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
158 %! [(2000 - 4j); (2000 + 4j)], 100*eps(200))
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
159 %!error <could not pair> cplxpair ([2000 * (1+eps) + 4j; 2000 * (1-eps) - 4j], 0);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
160
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
161 %!error <could not pair> cplxpair ([2e6 + j; 2e6 - j; 1e-9 * (1 + j); 1e-9 * (1 - 2j)]);
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17336
diff changeset
162
20508
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
163 ## Test input validation
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
164 %!error cplxpair ()
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
165 %!error cplxpair (1,2,3,4)
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
166 %!error <TOL must be .* positive> cplxpair (1, -1)
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
167 %!error <TOL must be .* scalar number> cplxpair (1, ones (2,2))
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
168 %!error <invalid dimension DIM> cplxpair (1, [], 3)
4c2e76cbdc7d cplxpair.m: Use tolerance that depends on Z to evaluate pairing (bug #45810).
Rik <rik@octave.org>
parents: 20193
diff changeset
169