Mercurial > hg > octave-lojdl
changeset 14224:f6007bb54f06
polyreduce.m: Recode function using modern syntax.
* polyreduce.m: Recode function using modern syntax.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 18 Jan 2012 21:17:14 -0800 |
parents | ba7a26030214 |
children | f0d903879eaa |
files | scripts/polynomial/polyreduce.m |
diffstat | 1 files changed, 14 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/polynomial/polyreduce.m +++ b/scripts/polynomial/polyreduce.m @@ -31,35 +31,28 @@ if (nargin != 1) print_usage (); - endif - - if (!isvector (c) || isempty (c)) + elseif (! isvector (c) || isempty (c)) error ("polyreduce: C must be a non-empty vector"); endif - if (! isempty (c)) - - index = find (c != 0); - - if (isempty (index)) + idx = find (c != 0, 1); - p = 0; - - else - - p = c(index (1):length (c)); - - endif - + if (isempty (idx)) + p = 0; + else + p = c(idx:end); endif endfunction -%!assert(all (all (polyreduce ([0, 0, 1, 2, 3]) == [1, 2, 3]))); -%!assert(all (all (polyreduce ([1, 2, 3, 0, 0]) == [1, 2, 3, 0, 0]))); +%!assert (polyreduce ([0, 0, 1, 2, 3]), [1, 2, 3]) +%!assert (polyreduce ([1, 2, 3, 0, 0]), [1, 2, 3, 0, 0]) +%!assert (polyreduce ([1, 0, 3]), [1, 0, 3]) +%!assert (polyreduce ([0, 0, 0]), 0) -%!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3]))); +%!error polyreduce () +%!error polyreduce (1, 2) +%!error <C must be a non-empty vector> polyreduce ([1, 2; 3, 4]) +%!error <C must be a non-empty vector> polyreduce ([]) -%!error polyreduce ([1, 2; 3, 4]); -