Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

About factored interpolation

0 views
Skip to first unread message

humptydumpty

unread,
Apr 24, 2007, 1:09:23 AM4/24/07
to
Marcel Hendrix wrote:
> I have great difficulty understanding why posters cling on
> to the stack solution for interpolation.

hi marcel,

is not only a stack solution for interpolation, is:
1. FACTORED solution to linear interpolation and that imply a better
FLEXIBILITY and REUSABILITY.
2. ROUNDED solution for linear interpolation with increased precision:

running gforth-0.6.2 with the test program, even for coarse
division for [0,1] interval ( 1024):

\ factored & rounded ----------------------------------------
: round ( a b -- a+b|a-b)
OVER 0> IF + ELSE - THEN ;

: >space ( x1 x0 x -- T) OVER - -ROT - 1024 SWAP */ ;
: space> ( T y0 y1 -- y) OVER - ROT * 512 round 1024 / + ;
: interpl ( y0 y1 x1 x0 x -- y) >space -ROT space> ;


\ jthomas ----------------------------------------
: interp3 ( x x0 y0 x1 y1 -- y)
ROT TUCK - 2>R \ x x0 x1 R: y0 y1-y0
OVER - >R - \ x-x0 R: y0 y1-y0 x1-x0
2R> */ \ (x-x0)*(y1-y0)/(x1-x0) R: y0
R> + ;

\ myneni -----------------------------------------
2variable p0
2variable p1
: interp1 ( x0 y0 x1 y1 x -- y)
>R p1 2! p0 2!
R> p0 2@ DROP - \ (x - x0)
p1 @ p0 @ - * \ (y1 - y0)*(x - x0)
p1 2@ DROP p0 2@ DROP - /
p0 @ + ;

\ floating ----------------------------------------
: -FROT FROT FROT ;
: S>F S>D D>F ;

: >fspace ( fx1 fx0 fx -- fT)
FOVER F- -FROT F- F/ ;
: fspace> ( fT fy0 fy1 -- fy)
FOVER F- FROT F* F+ ;
: finterpl ( fy0 fy1 fx1 fx0 fx -- fy)
>fspace -FROT fspace> ;

1 VALUE x0
51 VALUE y0

34 VALUE x1
2 VALUE y1

: itest ( a --) dup . space >R
y0 y1 x1 x0 R> interpl . ." factored & rounded" cr ;

: jtest ( a --) dup . space
x0 y0 x1 y1 interp3 . ." jthomas" cr ;

: ktest ( a --) dup . space >R
x0 y0 x1 y1 R> interp1 . ." myneni" cr ;

: ftest ( a --) dup . space >R
y0 S>F
y1 S>F
x1 S>F
x0 S>F
R> S>F
finterpl f. ." floating" cr ;

: test x1 1+ x0 DO
i itest
i jtest
i ktest
i ftest
cr
loop ;

test bye


gives the results:

LINEAR INTERPOLATION bo&co

1 51 factored & rounded
1 51 jthomas
1 51 myneni
1 51. floating

2 50 factored & rounded
2 50 jthomas
2 50 myneni
2 49.5151515151515 floating

3 48 factored & rounded
3 49 jthomas
3 49 myneni
3 48.030303030303 floating

4 47 factored & rounded
4 47 jthomas
4 47 myneni
4 46.5454545454545 floating

5 45 factored & rounded
5 46 jthomas
5 46 myneni
5 45.0606060606061 floating

6 44 factored & rounded
6 44 jthomas
6 44 myneni
6 43.5757575757576 floating

7 42 factored & rounded
7 43 jthomas
7 43 myneni
7 42.0909090909091 floating

8 41 factored & rounded
8 41 jthomas
8 41 myneni
8 40.6060606060606 floating

9 39 factored & rounded
9 40 jthomas
9 40 myneni
9 39.1212121212121 floating

10 38 factored & rounded
10 38 jthomas
10 38 myneni
10 37.6363636363636 floating

11 36 factored & rounded
11 37 jthomas
11 37 myneni
11 36.1515151515151 floating

12 35 factored & rounded
12 35 jthomas
12 35 myneni
12 34.6666666666667 floating

13 33 factored & rounded
13 34 jthomas
13 34 myneni
13 33.1818181818182 floating

14 32 factored & rounded
14 32 jthomas
14 32 myneni
14 31.6969696969697 floating

15 30 factored & rounded
15 31 jthomas
15 31 myneni
15 30.2121212121212 floating

16 29 factored & rounded
16 29 jthomas
16 29 myneni
16 28.7272727272727 floating

17 27 factored & rounded
17 28 jthomas
17 28 myneni
17 27.2424242424242 floating

18 26 factored & rounded
18 26 jthomas
18 26 myneni
18 25.7575757575758 floating

19 24 factored & rounded
19 25 jthomas
19 25 myneni
19 24.2727272727273 floating

20 23 factored & rounded
20 23 jthomas
20 23 myneni
20 22.7878787878788 floating

21 21 factored & rounded
21 22 jthomas
21 22 myneni
21 21.3030303030303 floating

0 new messages