Hi,
I believe I made a nice verb, called ffrom. It acts like { (from) :
1 3 ffrom i.10
1 3
(<1 3) ffrom i.3 5
8
(<1 3) ffrom i.3 5 6
48 49 50 51 52 53
but it also does:
1.4 3.2 ffrom i.10
1.4 3.2
(<1.4 3.2) ffrom i.3 5
10.2
(<1.4 3.2) ffrom i.3 5 6
61.2 62.2 63.2 64.2 65.2 66.2
It does that by multi-linear interpolation in any-dimensional grids:
(<0.5 0.5) ffrom 2 2$0 0 0 10
2.5
(<1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8) ffrom i. 3 3 3 3 3 3 3 3
3771.6
Here it is:
ffrom
4 : 0"0 _
vect =. _1e_7 + >x
n =. 2^#vect
bin =. #:i.n
pos =. <.vect
frac =. vect-pos
+/(*/(,./bin){"0 1 (1-frac),.frac) * (;/"2 pos +"1 1 bin) { y
)
I have no doubts that members in this forum can make it nicer.
What i particularly do not like is the _e_7 at the beginning.
Its only purpose is to allow for
(n-1) ffrom i.n=.4
3
which otherwise would interpolate between the 3rd and 4th element
causing an index error. If I want to solve that in another way it
gets messy. By the way,
_1 _1.5 _2 ffrom i.4
3 2.5 1
looks okay to me, and
_0.3 ffrom i.4
0.9
interpolates between the last and the first value, which also seems
reasonable.
Finally,
(<?20$0) ffrom i.20#2
281616
interpolates between the 1,048,576 vertices of a 20-dimensional hypercube :-)
Of course improvements and other suggestions will be greatly appreciated.
Perhaps it can end up in the wiki?
Greetings,
Ben
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm