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