comparison scripts/general/cplxpair.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children 72c96de7a403
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} cplxpair (@var{z}) 20 ## @deftypefn {Function File} {} cplxpair (@var{z})
21 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol}) 21 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol})
22 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol}, @var{dim}) 22 ## @deftypefnx {Function File} {} cplxpair (@var{z}, @var{tol}, @var{dim})
23 ## Sort the numbers @var{z} into complex conjugate pairs ordered by 23 ## Sort the numbers @var{z} into complex conjugate pairs ordered by
24 ## increasing real part. Place the negative imaginary complex number 24 ## increasing real part. Place the negative imaginary complex number
25 ## first within each pair. Place all the real numbers (those with 25 ## first within each pair. Place all the real numbers (those with
26 ## @code{abs (imag (@var{z}) / @var{z}) < @var{tol})}) after the 26 ## @code{abs (imag (@var{z}) / @var{z}) < @var{tol})}) after the
27 ## complex pairs. 27 ## complex pairs.
28 ## 28 ##
56 print_usage (); 56 print_usage ();
57 endif 57 endif
58 58
59 if (length (z) == 0) 59 if (length (z) == 0)
60 y = zeros (size (z)); 60 y = zeros (size (z));
61 return; 61 return;
62 endif 62 endif
63 63
64 if (nargin < 2 || isempty (tol)) 64 if (nargin < 2 || isempty (tol))
65 if (isa (z, "single")) 65 if (isa (z, "single"))
66 tol = 100 * eps("single"); 66 tol = 100 * eps("single");
67 else 67 else
68 tol = 100*eps; 68 tol = 100*eps;
69 endif 69 endif
70 endif 70 endif
71 71
72 nd = ndims (z); 72 nd = ndims (z);
73 orig_dims = size (z); 73 orig_dims = size (z);
146 %!assert (cplxpair(1), 1) 146 %!assert (cplxpair(1), 1)
147 %!assert (cplxpair([1+1i, 1-1i]), [1-1i, 1+1i]) 147 %!assert (cplxpair([1+1i, 1-1i]), [1-1i, 1+1i])
148 %!assert (cplxpair([1+1i, 1+1i, 1, 1-1i, 1-1i, 2]), \ 148 %!assert (cplxpair([1+1i, 1+1i, 1, 1-1i, 1-1i, 2]), \
149 %! [1-1i, 1+1i, 1-1i, 1+1i, 1, 2]) 149 %! [1-1i, 1+1i, 1-1i, 1+1i, 1, 2])
150 %!assert (cplxpair([1+1i; 1+1i; 1; 1-1i; 1-1i; 2]), \ 150 %!assert (cplxpair([1+1i; 1+1i; 1; 1-1i; 1-1i; 2]), \
151 %! [1-1i; 1+1i; 1-1i; 1+1i; 1; 2]) 151 %! [1-1i; 1+1i; 1-1i; 1+1i; 1; 2])
152 %!assert (cplxpair([0, 1, 2]), [0, 1, 2]); 152 %!assert (cplxpair([0, 1, 2]), [0, 1, 2]);
153 153
154 %!shared z 154 %!shared z
155 %! z=exp(2i*pi*[4; 3; 5; 2; 6; 1; 0]/7); 155 %! z=exp(2i*pi*[4; 3; 5; 2; 6; 1; 0]/7);
156 %!assert (cplxpair(z(randperm(7))), z); 156 %!assert (cplxpair(z(randperm(7))), z);