# HG changeset patch # User Rik # Date 1326950234 28800 # Node ID f6007bb54f06a9fcab2830e1156c492f0759b475 # Parent ba7a26030214693a75354c984d179485bc0a1029 polyreduce.m: Recode function using modern syntax. * polyreduce.m: Recode function using modern syntax. diff --git a/scripts/polynomial/polyreduce.m b/scripts/polynomial/polyreduce.m --- 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 polyreduce ([1, 2; 3, 4]) +%!error polyreduce ([]) -%!error polyreduce ([1, 2; 3, 4]); -