3437
|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
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. |
3437
|
9 ## |
7016
|
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. |
3437
|
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/>. |
3437
|
18 |
6945
|
19 ## Undocumented internal function. |
|
20 |
3437
|
21 ## -*- texinfo -*- |
3438
|
22 ## @deftypefn {Function File} {[@var{poly}, @var{rvals}] =} __zp2ssg2__ (@var{rvals}) |
3437
|
23 ## Used internally in @code{zp2ss} |
|
24 ## Extract 2 values from @var{rvals} (if possible) and construct |
|
25 ## a polynomial with those roots. |
|
26 ## @end deftypefn |
|
27 |
|
28 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
29 ## Created: August 1996 |
|
30 |
3438
|
31 function [poly, rvals] = __zp2ssg2__ (rvals) |
3437
|
32 |
|
33 ## locate imaginary roots (if any) |
|
34 cidx = find(imag(rvals)); |
|
35 |
|
36 if(!isempty(cidx)) |
|
37 ## select first complex root, omit from cidx |
|
38 r1i = cidx(1); r1 = rvals(r1i); cidx = complement(r1i,cidx); |
|
39 |
|
40 ## locate conjugate root (must be in cidx list, just in case there's |
|
41 ## roundoff) |
|
42 err = abs(rvals(cidx) - r1'); |
|
43 minerr = min(err); |
6024
|
44 c2i = find(err == minerr, 1); |
3437
|
45 r2i = cidx(c2i); |
|
46 r2 = rvals(r2i); |
|
47 cidx = complement(r2i,cidx); |
|
48 |
|
49 ## don't check for divide by zero, since 0 is not complex. |
|
50 if(abs(r2 - r1')/abs(r1) > 1e-12) |
|
51 error(sprintf("r1=(%f,%f); r2=(%f,%f), not conjugates.", ... |
|
52 real(r1),imag(r1),real(r2),imag(r2))); |
|
53 endif |
|
54 |
|
55 ## complex conjugate pair |
|
56 poly = [1, -2*real(r1), real(r1)^2+imag(r1)^2]; |
|
57 else |
|
58 ## select two roots (they're all real) |
|
59 r1 = rvals(1); |
|
60 r2 = rvals(2); |
|
61 poly = [1, -(r1+r2), (r1*r2)]; |
|
62 r1i = 1; r2i = 2; |
|
63 endif |
|
64 |
|
65 ## remove roots used |
|
66 idx = complement([r1i, r2i],1:length(rvals)); |
|
67 rvals = rvals(idx); |
|
68 |
|
69 endfunction |
|
70 |