Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyreduce.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 614505385171 |
children | f6007bb54f06 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 1994-2012 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}) | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
21 ## Reduce a polynomial coefficient vector to a minimum number of terms by |
3368 | 22 ## stripping off any leading zeros. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
23 ## @seealso{polyout} |
3368 | 24 ## @end deftypefn |
1025 | 25 |
3202 | 26 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 27 ## Created: June 1994 |
28 ## Adapted-By: jwe | |
561 | 29 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
30 function p = polyreduce (c) |
1025 | 31 |
2716 | 32 if (nargin != 1) |
6046 | 33 print_usage (); |
2716 | 34 endif |
561 | 35 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
36 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
|
37 error ("polyreduce: C must be a non-empty vector"); |
2716 | 38 endif |
561 | 39 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
40 if (! isempty (c)) |
1178 | 41 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
42 index = find (c != 0); |
561 | 43 |
3617 | 44 if (isempty (index)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 |
3617 | 46 p = 0; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
47 |
3617 | 48 else |
2716 | 49 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
50 p = c(index (1):length (c)); |
1178 | 51 |
52 endif | |
53 | |
561 | 54 endif |
1025 | 55 |
561 | 56 endfunction |
7411 | 57 |
58 %!assert(all (all (polyreduce ([0, 0, 1, 2, 3]) == [1, 2, 3]))); | |
59 | |
60 %!assert(all (all (polyreduce ([1, 2, 3, 0, 0]) == [1, 2, 3, 0, 0]))); | |
61 | |
62 %!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3]))); | |
63 | |
64 %!error polyreduce ([1, 2; 3, 4]); | |
65 |