Mercurial > hg > octave-nkf
changeset 10672:1cd7c39a96ee
legendre.m: Orient row vector correctly (bug #29997).
Add input validation for negative values and %tests to check
validation routines.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 31 May 2010 14:34:30 -0700 |
parents | f5f9bc8e83fc |
children | b17a966099ed |
files | scripts/ChangeLog scripts/specfun/legendre.m |
diffstat | 2 files changed, 30 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,4 +1,9 @@ -2010-05-26 Rik <octave@nomad.inbox5.com> +2010-05-31 Rik <octave@nomad.inbox5.com> + * specfun/legendre.m: Orient row vector correctly (bug #29997). + Add input validation for negative values and %tests to check + validation routines. + +2010-05-30 Rik <octave@nomad.inbox5.com> * sparse/svds.m: Overhaul code. Return smallest singular values if sigma == 0 (Bug #29721).
--- a/scripts/specfun/legendre.m +++ b/scripts/specfun/legendre.m @@ -117,20 +117,20 @@ print_usage (); endif + if (!isscalar (n) || n < 0 || n != fix (n)) + error ("legendre: N must be a non-negative scalar integer"); + endif + + if (!isvector (x) || !isreal (x) || any (x < -1 | x > 1)) + error ("legendre: X must be real-valued vector in the range -1 <= X <= 1"); + endif + if (nargin == 3) normalization = lower (normalization); else normalization = "unnorm"; endif - if (! isscalar (n) || n < 0 || n != fix (n)) - error ("legendre: n must be a non-negative scalar integer"); - endif - - if (! isvector (x) || any (x < -1 || x > 1)) - error ("legendre: x must be vector in range -1 <= x <= 1"); - endif - switch (normalization) case "norm" scale = sqrt (n+0.5); @@ -139,9 +139,12 @@ case "unnorm" scale = 1; otherwise - error ("legendre: expecting normalization option to be \"norm\", \"sch\", or \"unnorm\""); + error ('legendre: expecting normalization option to be "norm", "sch", or "unnorm"'); endswitch + if (rows (x) != 1) + x = x'; + endif scale = scale * ones (1, numel (x)); ## Based on the recurrence relation below @@ -235,3 +238,15 @@ %!test %! result = legendre (0, 0:0.1:1); %! assert (result, full(ones(1,11))) + +%% Check correct invocation +%!error legendre (); +%!error legendre (1); +%!error legendre (1,2,3,4); +%!error legendre ([1, 2], [-1, 0, 1]); +%!error legendre (-1, [-1, 0, 1]); +%!error legendre (1.1, [-1, 0, 1]); +%!error legendre (1, [-1+i, 0, 1]); +%!error legendre (1, [-2, 0, 1]); +%!error legendre (1, [-1, 0, 2]); +%!error legendre (1, [-1, 0, 1], "badnorm");