Mercurial > hg > octave-lyh
annotate scripts/polynomial/polyreduce.m @ 11188:4cb1522e4d0f
Use function handle as input to cellfun,
rather than quoted function name or anonymous function wrapper.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 03 Nov 2010 17:20:56 -0700 |
parents | f6e0404421f4 |
children | c776f063fefe |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2004, |
8920 | 2 ## 2005, 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
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. | |
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/>. | |
904 | 19 |
3368 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} polyreduce (@var{c}) | |
22 ## Reduces a polynomial coefficient vector to a minimum number of terms by | |
23 ## stripping off any leading zeros. | |
5642 | 24 ## @seealso{poly, roots, conv, deconv, residue, filter, polyval, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
25 ## polyvalm, polyderiv, polyint} |
3368 | 26 ## @end deftypefn |
1025 | 27 |
3202 | 28 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 29 ## Created: June 1994 |
30 ## Adapted-By: jwe | |
561 | 31 |
2312 | 32 function p = polyreduce (p) |
1025 | 33 |
2716 | 34 if (nargin != 1) |
6046 | 35 print_usage (); |
2716 | 36 endif |
561 | 37 |
4030 | 38 if (! (isvector (p) || isempty (p))) |
2716 | 39 error ("polyreduce: argument must be a vector"); |
40 endif | |
561 | 41 |
8507 | 42 if (! isempty (p)) |
1178 | 43 |
3617 | 44 index = find (p != 0); |
561 | 45 |
3617 | 46 if (isempty (index)) |
47 | |
48 p = 0; | |
49 | |
50 else | |
2716 | 51 |
3617 | 52 p = p (index (1):length (p)); |
1178 | 53 |
54 endif | |
55 | |
561 | 56 endif |
1025 | 57 |
561 | 58 endfunction |
7411 | 59 |
60 %!assert(all (all (polyreduce ([0, 0, 1, 2, 3]) == [1, 2, 3]))); | |
61 | |
62 %!assert(all (all (polyreduce ([1, 2, 3, 0, 0]) == [1, 2, 3, 0, 0]))); | |
63 | |
64 %!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3]))); | |
65 | |
66 %!assert(isempty (polyreduce ([]))); | |
67 | |
68 %!error polyreduce ([1, 2; 3, 4]); | |
69 |