Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyreduce.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | d0b799dafede |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 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, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
24 ## polyvalm, polyderiv, polyint} |
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 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
31 function p = polyreduce (c) |
1025 | 32 |
2716 | 33 if (nargin != 1) |
6046 | 34 print_usage (); |
2716 | 35 endif |
561 | 36 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
37 if (!isvector (c) || isempty (c)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
38 error ("polyreduce: C must be a non-empty vector"); |
2716 | 39 endif |
561 | 40 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
41 if (! isempty (c)) |
1178 | 42 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
43 index = find (c != 0); |
561 | 44 |
3617 | 45 if (isempty (index)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
46 |
3617 | 47 p = 0; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
48 |
3617 | 49 else |
2716 | 50 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
51 p = c(index (1):length (c)); |
1178 | 52 |
53 endif | |
54 | |
561 | 55 endif |
1025 | 56 |
561 | 57 endfunction |
7411 | 58 |
59 %!assert(all (all (polyreduce ([0, 0, 1, 2, 3]) == [1, 2, 3]))); | |
60 | |
61 %!assert(all (all (polyreduce ([1, 2, 3, 0, 0]) == [1, 2, 3, 0, 0]))); | |
62 | |
63 %!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3]))); | |
64 | |
65 %!error polyreduce ([1, 2; 3, 4]); | |
66 |