Mercurial > hg > octave-nkf
changeset 17966:3232956a6081
spline.m: Fix problem with transposed "complete" inputs (bug #40584).
* scripts/polynomial/spline.m: Orient input vector correctly for not-a-knot (n)
and "complete (n+2) inputs. Add %!tests to check behavior.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Nov 2013 10:05:08 -0800 |
parents | 1d58abc740c0 |
children | 303157af491f |
files | scripts/polynomial/spline.m |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/polynomial/spline.m +++ b/scripts/polynomial/spline.m @@ -83,12 +83,12 @@ ## Check the size and shape of y ndy = ndims (y); szy = size (y); - if (ndy == 2 && (szy(1) == n || szy(2) == n)) - if (szy(2) == n) + if (ndy == 2 && (any (szy == n) || any (szy == n+2))) + if (szy(2) == n || szy(2) == n+2) a = y.'; else a = y; - szy = fliplr (szy); + szy = szy([2 1]); endif else a = shiftdim (reshape (y, [prod(szy(1:end-1)), szy(end)]), 1); @@ -283,18 +283,24 @@ %! x = [2,1]; %! y = [1,2,3,4]; %! pp = spline (x,y); +%! pp2 = spline (x', y'); %! [x,P] = unmkpp (pp); %! assert (P, [7,-9,1,3], abserr); +%! assert (pp2, pp); %!test %! x = [0,1,2]; %! y = [0,0,1,0,0]; %! pp = spline (x,y); +%! pp2 = spline (x', y'); %! [x,P] = unmkpp (pp); %! assert (P, [-2,3,0,0;2,-3,0,1], abserr); +%! assert (pp2, pp); %!test %! x = [0,1,2,3]; %! y = [0,0,1,1,0,0]; %! pp = spline (x,y); +%! pp2 = spline (x', y'); %! [x,P] = unmkpp (pp); %! assert (P, [-1,2,0,0;0,-1,1,1;1,-1,-1,1], abserr); +%! assert (pp2, pp);