Mercurial > hg > octave-avbm
changeset 11670:b1368dc9e719 release-3-0-x
Apply a scaling factor to leading zero removal in roots.m
author | Sebastien Loisel |
---|---|
date | Wed, 05 Mar 2008 04:58:54 -0500 |
parents | a6e08ecb4050 |
children | 1507a9d6df40 |
files | scripts/ChangeLog scripts/polynomial/roots.m |
diffstat | 2 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,12 @@ +2008-03-05 Ben Abbott <bpabbott@mac.com> + + * polynomial/roots.m: Catch Infs and/or NaNs. + +2008-03-05 Sebastien Loisel <loisel@temple.edu> + + * polynomial/roots.m: Apply a scaling factor to the removal of the + leading zeros. + 2008-02-29 John W. Eaton <jwe@octave.org> * plot/print.m: Handle gif and jpg devices.
--- a/scripts/polynomial/roots.m +++ b/scripts/polynomial/roots.m @@ -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));