Mercurial > octave-nkf
diff scripts/general/interp1.m @ 7671:4fbaba9abec1
implement compiled binary lookup
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 28 Mar 2008 15:53:09 -0400 |
parents | a1dbe9d80eee |
children | cadc73247d65 |
line wrap: on
line diff
--- a/scripts/general/interp1.m Fri Mar 28 14:52:27 2008 -0400 +++ b/scripts/general/interp1.m Fri Mar 28 15:53:09 2008 -0400 @@ -200,9 +200,7 @@ yi = mkpp (x, [dy./dx, y(1:end-1)], szy(2:end)); else ## find the interval containing the test point - idx = lookup (x(2:nx-1), xi)+1; - # 2:n-1 so that anything beyond the ends - # gets dumped into an interval + idx = lookup (x, xi, "lr"); ## use the endpoints of the interval to define a line s = (xi - x(idx))./dx(idx); yi(range,:) = s(:,ones(1,nc)).*dy(idx,:) + y(idx,:); @@ -243,7 +241,7 @@ if (nx < 4 || ny < 4) error ("interp1: table too short"); endif - idx = lookup (x(3:nx-2), xi) + 1; + idx = lookup (x(2:nx-1), xi, "lr"); ## Construct cubic equations for each interval using divided ## differences (computation of c and d don't use divided differences @@ -570,3 +568,5 @@ %!assert (interp1(1:2:8,1:2:8,1.4,"*cubic"),1.4); %!error interp1(1:2,1:2,1, "*spline"); %!assert (interp1(1:2:6,1:2:6,1.4,"*spline"),1.4); + +%!assert (interp1([3,2,1],[3,2,2],2.5),2.5)