Mercurial > hg > octave-nkf
annotate scripts/polynomial/mpoles.m @ 17530:0f45d9dd8107
test: Fix 4 failing plot demos.
* scripts/plot/legend.m: Demo #11, use 'h' for returned handle.
* scripts/plot/plot.m: Fix typo "lenths" -> "lengths".
* scripts/plot/ribbon.m: Remove unnecessary call to meshgrid now
that sombrero returns meshgridded data.
* scripts/plot/trimesh.m: Set colormap so plot is always reproducible.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 01 Oct 2013 15:39:20 -0700 |
parents | f3d52523cde1 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 2007-2012 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 -*- | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p}) |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p}, @var{tol}) |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{multp}, @var{idxp}] =} mpoles (@var{p}, @var{tol}, @var{reorder}) |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
23 ## Identify unique poles in @var{p} and their associated multiplicity. The |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
24 ## output is ordered from largest pole to smallest pole. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
25 ## |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
26 ## If the relative difference of two poles is less than @var{tol} then |
6964 | 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 ## | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
32 ## The output @var{multp} is a vector specifying the multiplicity of the |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
33 ## poles. @code{@var{multp}(n)} refers to the multiplicity of the Nth pole |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
34 ## @code{@var{p}(@var{idxp}(n))}. |
6964 | 35 ## |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 ## For example: |
6964 | 37 ## |
38 ## @example | |
39 ## @group | |
40 ## p = [2 3 1 1 2]; | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
41 ## [m, n] = mpoles (p) |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
42 ## @result{} m = [1; 1; 2; 1; 2] |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
43 ## @result{} n = [2; 5; 1; 4; 3] |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 ## @result{} p(n) = [3, 2, 2, 1, 1] |
6964 | 45 ## @end group |
46 ## @end example | |
47 ## | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
48 ## @seealso{residue, poly, roots, conv, deconv} |
6964 | 49 ## @end deftypefn |
50 | |
51 ## Author: Ben Abbott <bpabbott@mac.com> | |
52 ## Created: Sept 30, 2007 | |
53 | |
54 function [multp, indx] = mpoles (p, tol, reorder) | |
55 | |
56 if (nargin < 1 || nargin > 3) | |
57 print_usage (); | |
58 endif | |
59 | |
60 if (nargin < 2 || isempty (tol)) | |
61 tol = 0.001; | |
62 endif | |
63 | |
64 if (nargin < 3 || isempty (reorder)) | |
65 reorder = true; | |
66 endif | |
67 | |
68 Np = numel (p); | |
69 | |
70 ## Force the poles to be a column vector. | |
71 | |
72 p = p(:); | |
73 | |
74 ## Sort the poles according to their magnitidues, largest first. | |
75 | |
76 if (reorder) | |
77 ## Sort with smallest magnitude first. | |
78 [p, ordr] = sort (p); | |
79 ## Reverse order, largest maginitude first. | |
80 n = Np:-1:1; | |
81 p = p(n); | |
82 ordr = ordr(n); | |
83 else | |
84 ordr = 1:Np; | |
85 endif | |
86 | |
87 ## Find pole multiplicty by comparing the relative differnce in the | |
88 ## poles. | |
89 | |
90 multp = zeros (Np, 1); | |
91 indx = []; | |
92 n = find (multp == 0, 1); | |
93 while (n) | |
94 dp = abs (p-p(n)); | |
95 if (p(n) == 0.0) | |
9360
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
96 if (any (abs (p) > 0 & isfinite (p))) |
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
97 p0 = mean (abs (p(abs (p) > 0 & isfinite (p)))); |
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
98 else |
6964 | 99 p0 = 1; |
7151 | 100 endif |
6964 | 101 else |
102 p0 = abs (p(n)); | |
103 endif | |
104 k = find (dp < tol * p0); | |
7360 | 105 ## Poles can only be members of one multiplicity group. |
106 if (numel (indx)) | |
107 k = k(! ismember (k, indx)); | |
108 endif | |
6964 | 109 m = 1:numel (k); |
110 multp(k) = m; | |
111 indx = [indx; k]; | |
112 n = find (multp == 0, 1); | |
113 endwhile | |
114 multp = multp(indx); | |
6998 | 115 indx = ordr(indx); |
6964 | 116 |
117 endfunction | |
9360
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
118 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
119 |
9360
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
120 %!test |
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
121 %! [mp, n] = mpoles ([0 0], 0.01); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
122 %! assert (mp, [1; 2]); |
9360
df42106beec8
mpoles.m: Fix infinite loop for a multiplicity of poles at zero. Test added.
Ben Abbott <bpabbott@mac.com>
parents:
9245
diff
changeset
|
123 |