For some reason my mail program doesn't like the isolated ")"
that ends lintrp - it should of course be
--->(n{u)+ y*n{g1-g0
--->)
On Mon, 16 Jun 2008, J. Patrick Harrington wrote:
This is what I've used for linear interpolation in large arrays. I
tried it on the example below and it took ~0.002 sec on my machine.
---------------------------------------------------------------------
NB. linear interpolation: (x;y) lintrp x0 --> y(x0)
NB. x & y boxed, x0 may be a vector, extrapolate off ends.
lintrp=: 4 : 0
'xx yy'=. x
g0=. (}: yy)% d=. DEL xx
g1=. (}. yy)% d
u=. (g0* }.xx) - g1* }:xx
n=. xx IdX y
(n{u)+ y*n{g1-g0 )
NB. x IdX x0 --> index where x0 fits in x-array, e.g.:
NB. 0 1 2 3 4 5 6 <- x values
NB. | | | | | | |
NB. <-- 0 | 1 | 2 | 3 | 4 | 5 ---> IdX values
IdX=: ] I.~ [: }: [: }. [
DEL =: }. - }:
------------------------------------------------------------------------
Patrick
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm