# HG changeset patch # User Juan Pablo Carbajal # Date 1396214700 -7200 # Node ID 5fe907167520ba2eef3299834fe5bd4555e10915 # Parent 6fdd3ab55b7823b4291e5f21f5f3dad21229cf43 interp1.m: fix function for inputs w/multiple discontinuities (bug #41980). * interp1.m: Remove discontinuities from dy in the same order as they are removed from xx and yy. Adjust %!tests to account for new behavior. diff -r 6fdd3ab55b78 -r 5fe907167520 scripts/general/interp1.m --- a/scripts/general/interp1.m Sat Apr 05 17:03:15 2014 -0400 +++ b/scripts/general/interp1.m Sun Mar 30 23:25:00 2014 +0200 @@ -247,20 +247,21 @@ case "linear" xx = x; + nxx = nx; yy = y; - nxx = nx; + dy = diff (yy); if (have_jumps) ## Omit zero-size intervals. - yy(jumps, :) = []; xx(jumps) = []; nxx = rows (xx); + yy(jumps, :) = []; + dy(jumps, :) = []; endif - dy = diff (yy); dx = diff (xx); dx = repmat (dx, [1 size(dy)(2:end)]); - coefs = [(dy./dx).'(:), yy(1:nxx-1, :).'(:)]; + coefs = [(dy./dx).', yy(1:nxx-1, :).']; pp = mkpp (xx, coefs, szy(2:end)); pp.orient = "first"; @@ -631,8 +632,8 @@ %!assert (interp1 (0:4, 2.5), 1.5) ## Left and Right discontinuities -%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-8,2,4,3,1.5]) -%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,1.5,1.5]) +%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-2,0.5,4,3,1.5]) +%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,3,1.5]) %% Test input validation %!error interp1 ()