Mercurial > hg > octave-lojdl
changeset 12475:009068efc66d
Properly evaluate zeroth order polynomials.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 24 Feb 2011 20:05:51 -0500 |
parents | 26d3164fd58d |
children | 070214996fba |
files | scripts/ChangeLog scripts/polynomial/polyval.m |
diffstat | 2 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2011-02-24 Robert T. Short <rtshort@ieee.org> + + * polynomial/polyval.m: Properly evaluate constant polynomials. + 2011-02-24 John W. Eaton <jwe@octave.org> * strings/strchr.m: Avoid implicit string to number conversion.
--- a/scripts/polynomial/polyval.m +++ b/scripts/polynomial/polyval.m @@ -69,7 +69,7 @@ n = length (p) - 1; x = (x - mu(1)) / mu(2); - y = p(1); + y = p(1) * ones (size (x(:))); for i = 2:n+1 y = y .* x(:) + p(i); endfor @@ -128,3 +128,19 @@ %! x = reshape(x, [1, 1, 5, 2]); %! assert (x, polyval(p,x), eps) +%!test +%! p = [1]; +%! x = 1:10; +%! y = ones(size(x)); +%! assert (y, polyval(p,x), eps) +%! x = x(:); +%! y = ones(size(x)); +%! assert (y, polyval(p,x), eps) +%! x = reshape(x, [2, 5]); +%! y = ones(size(x)); +%! assert (y, polyval(p,x), eps) +%! x = reshape(x, [5, 2]); +%! y = ones(size(x)); +%! assert (y, polyval(p,x), eps) +%! x = reshape(x, [1, 1, 5, 2]); +