1 ## Copyright (C) 2007-2012 Ben Abbott
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p})
21 ## @deftypefnx {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p}, @var{tol})
22 ## @deftypefnx {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p}, @var{tol}, @var{reorder})
23 ## Identify unique poles in @var{p} and their associated multiplicity. The
24 ## output is ordered from largest pole to smallest pole.
26 ## If the relative difference of two poles is less than @var{tol} then
27 ## they are considered to be multiples. The default value for @var{tol}
30 ## If the optional parameter @var{reorder} is zero, poles are not sorted.
32 ## The output @var{multp} is a vector specifying the multiplicity of the
33 ## poles. @code{@var{multp}(n)} refers to the multiplicity of the Nth pole
34 ## @code{@var{p}(@var{idxp}(n))}.
41 ## [m, n] = mpoles (p)
42 ## @result{} m = [1; 1; 2; 1; 2]
43 ## @result{} n = [2; 5; 1; 4; 3]
44 ## @result{} p(n) = [3, 2, 2, 1, 1]
48 ## @seealso{residue, poly, roots, conv, deconv}
51 ## Author: Ben Abbott <bpabbott@mac.com>
52 ## Created: Sept 30, 2007
54 function [multp, indx] = mpoles (p, tol, reorder)
56 if (nargin < 1 || nargin > 3)
60 if (nargin < 2 || isempty (tol))
64 if (nargin < 3 || isempty (reorder))
70 ## Force the poles to be a column vector.
74 ## Sort the poles according to their magnitidues, largest first.
77 ## Sort with smallest magnitude first.
79 ## Reverse order, largest maginitude first.
87 ## Find pole multiplicty by comparing the relative differnce in the
90 multp = zeros (Np, 1);
92 n = find (multp == 0, 1);
96 if (any (abs (p) > 0 & isfinite (p)))
97 p0 = mean (abs (p(abs (p) > 0 & isfinite (p))));
104 k = find (dp < tol * p0);
105 ## Poles can only be members of one multiplicity group.
107 k = k(! ismember (k, indx));
112 n = find (multp == 0, 1);
120 %! [mp, n] = mpoles ([0 0], 0.01);
121 %! assert (mp, [1; 2])