# HG changeset patch # User Sebastien Loisel # Date 1204711134 18000 # Node ID b1368dc9e719f9e9748fc5ccc09dbb66b75f749f # Parent a6e08ecb405003da4e4fcf2ab1a205e029437f8e Apply a scaling factor to leading zero removal in roots.m diff -r a6e08ecb4050 -r b1368dc9e719 scripts/ChangeLog --- a/scripts/ChangeLog Mon Mar 03 20:00:17 2008 -0500 +++ b/scripts/ChangeLog Wed Mar 05 04:58:54 2008 -0500 @@ -1,3 +1,12 @@ +2008-03-05 Ben Abbott + + * polynomial/roots.m: Catch Infs and/or NaNs. + +2008-03-05 Sebastien Loisel + + * polynomial/roots.m: Apply a scaling factor to the removal of the + leading zeros. + 2008-02-29 John W. Eaton * plot/print.m: Handle gif and jpg devices. diff -r a6e08ecb4050 -r b1368dc9e719 scripts/polynomial/roots.m --- a/scripts/polynomial/roots.m Mon Mar 03 20:00:17 2008 -0500 +++ b/scripts/polynomial/roots.m Wed Mar 05 04:58:54 2008 -0500 @@ -83,16 +83,22 @@ if (nargin != 1 || min (size (v)) > 1) print_usage (); + elseif (any (isnan(v) | isinf(v))) + error ("roots: inputs must not contain Inf or NaN") endif - n = length (v); - v = reshape (v, 1, n); + n = numel (v); + v = v(:); ## If v = [ 0 ... 0 v(k+1) ... v(k+l) 0 ... 0 ], we can remove the ## leading k zeros and n - k - l roots of the polynomial are zero. - f = find (v); - m = max (size (f)); + if (isempty (v)) + f = v; + else + f = find (v ./ max (abs (v))); + endif + m = numel (f); if (m > 0 && n > 1) v = v(f(1):f(m));