Mercurial > hg > octave-nkf
annotate scripts/polynomial/mpoles.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | e9dc2ed2ec0f |
children | df42106beec8 |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2008, 2009 Ben Abbott |
6964 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6964 | 9 ## |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6964 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {[@var{multp}, @var{indx}] =} mpoles (@var{p}) | |
21 ## @deftypefnx {Function File} {[@var{multp}, @var{indx}] =} mpoles (@var{p}, @var{tol}) | |
22 ## @deftypefnx {Function File} {[@var{multp}, @var{indx}] =} mpoles (@var{p}, @var{tol}, @var{reorder}) | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## Identify unique poles in @var{p} and associates their multiplicity, |
6964 | 24 ## ordering them from largest to smallest. |
25 ## | |
26 ## If the relative difference of the poles is less than @var{tol}, then | |
27 ## they are considered to be multiples. The default value for @var{tol} | |
28 ## is 0.001. | |
29 ## | |
30 ## If the optional parameter @var{reorder} is zero, poles are not sorted. | |
31 ## | |
32 ## The value @var{multp} is a vector specifying the multiplicity of the | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
33 ## poles. @var{multp}(:) refers to multiplicity of @var{p}(@var{indx}(:)). |
6964 | 34 ## |
35 ## For example, | |
36 ## | |
37 ## @example | |
38 ## @group | |
39 ## p = [2 3 1 1 2]; | |
40 ## [m, n] = mpoles(p); | |
41 ## @result{} m = [1; 1; 2; 1; 2] | |
42 ## @result{} n = [2; 5; 1; 4; 3] | |
43 ## @result{} p(n) = [3, 2, 2, 1, 1] | |
44 ## @end group | |
45 ## @end example | |
46 ## | |
47 ## @seealso{poly, roots, conv, deconv, polyval, polyderiv, polyinteg, residue} | |
48 ## @end deftypefn | |
49 | |
50 ## Author: Ben Abbott <bpabbott@mac.com> | |
51 ## Created: Sept 30, 2007 | |
52 | |
53 function [multp, indx] = mpoles (p, tol, reorder) | |
54 | |
55 if (nargin < 1 || nargin > 3) | |
56 print_usage (); | |
57 endif | |
58 | |
59 if (nargin < 2 || isempty (tol)) | |
60 tol = 0.001; | |
61 endif | |
62 | |
63 if (nargin < 3 || isempty (reorder)) | |
64 reorder = true; | |
65 endif | |
66 | |
67 Np = numel (p); | |
68 | |
69 ## Force the poles to be a column vector. | |
70 | |
71 p = p(:); | |
72 | |
73 ## Sort the poles according to their magnitidues, largest first. | |
74 | |
75 if (reorder) | |
76 ## Sort with smallest magnitude first. | |
77 [p, ordr] = sort (p); | |
78 ## Reverse order, largest maginitude first. | |
79 n = Np:-1:1; | |
80 p = p(n); | |
81 ordr = ordr(n); | |
82 else | |
83 ordr = 1:Np; | |
84 endif | |
85 | |
86 ## Find pole multiplicty by comparing the relative differnce in the | |
87 ## poles. | |
88 | |
89 multp = zeros (Np, 1); | |
90 indx = []; | |
91 n = find (multp == 0, 1); | |
92 while (n) | |
93 dp = abs (p-p(n)); | |
94 if (p(n) == 0.0) | |
95 p0 = mean (abs (p(find (abs (p) > 0)))); | |
96 if (isempty (p0)) | |
97 p0 = 1; | |
7151 | 98 endif |
6964 | 99 else |
100 p0 = abs (p(n)); | |
101 endif | |
102 k = find (dp < tol * p0); | |
7360 | 103 ## Poles can only be members of one multiplicity group. |
104 if (numel (indx)) | |
105 k = k(! ismember (k, indx)); | |
106 endif | |
6964 | 107 m = 1:numel (k); |
108 multp(k) = m; | |
109 indx = [indx; k]; | |
110 n = find (multp == 0, 1); | |
111 endwhile | |
112 multp = multp(indx); | |
6998 | 113 indx = ordr(indx); |
6964 | 114 |
115 endfunction |