7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2001, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3437
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3437
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3437
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3437
|
19 |
6945
|
20 ## Undocumented internal function. |
|
21 |
3437
|
22 ## -*- texinfo -*- |
3438
|
23 ## @deftypefn {Function File} {[@var{poly}, @var{rvals}] =} __zp2ssg2__ (@var{rvals}) |
3437
|
24 ## Used internally in @code{zp2ss} |
|
25 ## Extract 2 values from @var{rvals} (if possible) and construct |
|
26 ## a polynomial with those roots. |
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
30 ## Created: August 1996 |
|
31 |
3438
|
32 function [poly, rvals] = __zp2ssg2__ (rvals) |
3437
|
33 |
|
34 ## locate imaginary roots (if any) |
7136
|
35 cidx = find (imag (rvals)); |
3437
|
36 |
7136
|
37 if (! isempty (cidx)) |
3437
|
38 ## select first complex root, omit from cidx |
7136
|
39 r1i = cidx(1); |
|
40 r1 = rvals(r1i); |
|
41 cidx = complement (r1i, cidx); |
3437
|
42 |
|
43 ## locate conjugate root (must be in cidx list, just in case there's |
|
44 ## roundoff) |
7136
|
45 err = abs (rvals(cidx) - r1'); |
|
46 minerr = min (err); |
|
47 c2i = find (err == minerr, 1); |
3437
|
48 r2i = cidx(c2i); |
|
49 r2 = rvals(r2i); |
7136
|
50 cidx = complement (r2i, cidx); |
3437
|
51 |
|
52 ## don't check for divide by zero, since 0 is not complex. |
7136
|
53 if (abs (r2-r1') / abs (r1) > 1e-12) |
|
54 error ("r1=(%f,%f); r2=(%f,%f), not conjugates.", |
|
55 real (r1), imag (r1), real (r2), imag(r2)); |
3437
|
56 endif |
|
57 |
|
58 ## complex conjugate pair |
|
59 poly = [1, -2*real(r1), real(r1)^2+imag(r1)^2]; |
|
60 else |
|
61 ## select two roots (they're all real) |
|
62 r1 = rvals(1); |
|
63 r2 = rvals(2); |
|
64 poly = [1, -(r1+r2), (r1*r2)]; |
7136
|
65 r1i = 1; |
|
66 r2i = 2; |
3437
|
67 endif |
|
68 |
|
69 ## remove roots used |
7136
|
70 idx = complement ([r1i, r2i], 1:length(rvals)); |
3437
|
71 rvals = rvals(idx); |
|
72 |
|
73 endfunction |
|
74 |