2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
2313
|
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/>. |
904
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} polyreduce (@var{c}) |
|
21 ## Reduces a polynomial coefficient vector to a minimum number of terms by |
|
22 ## stripping off any leading zeros. |
5642
|
23 ## @seealso{poly, roots, conv, deconv, residue, filter, polyval, |
|
24 ## polyvalm, polyderiv, polyinteg} |
3368
|
25 ## @end deftypefn |
1025
|
26 |
3202
|
27 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
28 ## Created: June 1994 |
|
29 ## Adapted-By: jwe |
561
|
30 |
2312
|
31 function p = polyreduce (p) |
1025
|
32 |
2716
|
33 if (nargin != 1) |
6046
|
34 print_usage (); |
2716
|
35 endif |
561
|
36 |
4030
|
37 if (! (isvector (p) || isempty (p))) |
2716
|
38 error ("polyreduce: argument must be a vector"); |
|
39 endif |
561
|
40 |
3617
|
41 if (! isempty (p) ) |
1178
|
42 |
3617
|
43 index = find (p != 0); |
561
|
44 |
3617
|
45 if (isempty (index)) |
|
46 |
|
47 p = 0; |
|
48 |
|
49 else |
2716
|
50 |
3617
|
51 p = p (index (1):length (p)); |
1178
|
52 |
|
53 endif |
|
54 |
561
|
55 endif |
1025
|
56 |
561
|
57 endfunction |