1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} polyreduce (@var{c})
21 ## Reduce a polynomial coefficient vector to a minimum number of terms by
22 ## stripping off any leading zeros.
26 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
30 function p = polyreduce (c)
36 if (!isvector (c) || isempty (c))
37 error ("polyreduce: C must be a non-empty vector");
42 index = find (c != 0);
50 p = c(index (1):length (c));
58 %!assert(all (all (polyreduce ([0, 0, 1, 2, 3]) == [1, 2, 3])));
60 %!assert(all (all (polyreduce ([1, 2, 3, 0, 0]) == [1, 2, 3, 0, 0])));
62 %!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3])));
64 %!error polyreduce ([1, 2; 3, 4]);