The first problem, extrapolating a polynomial (of degree k) through k
points, can be done as follows.
pol=: (+/ . *~[: %.@:|: (^"_ 0 (i...@#)))/
(i.21) p.~ pol (^&2 ,: ]) i.3x
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
Or, slightly more complicated
[X=: _7776 _243 _1 32 3125 59049 ,: _5 _2 0 3 6 10x
_7776 _243 _1 32 3125 59049
_5 _2 0 3 6 10
(i:10) ([ ,. (p.~ pol)) X
_10 _161051
_9 _100000
_8 _59049
_7 _32768
_6 _16807
_5 _7776
_4 _3125
_3 _1024
_2 _243
_1 _32
0 _1
1 0
2 1
3 32
4 243
5 1024
6 3125
7 7776
8 16807
9 32768
10 59049
This extrapolating is much more efficient.
dspl rnkng scores '1000 etcb ^&5[i.6x';'(i.1000) p.~ pol (^&5,:])i.6x'
+----+-----+-----+----+
|rank|et*sz|time |size|
+----+-----+-----+----+
| 1 |2.84 |17.03|1.00|
+----+-----+-----+----+
| 0 |1.00 | 1.00|6.00|
+----+-----+-----+----+
(1000 etcb ^&5[i.6x)-:(i.1000)p.~ pol (^&5,:])i.6x
1
dspl rnkng scores '1000 etcb ^&5[i.6';'(i.1000)p.~ pol (^&5,:])i.6'
+----+------+------+----+
|rank|et*sz |time |size|
+----+------+------+----+
| 1 |609.30|391.06|1.56|
+----+------+------+----+
| 0 | 1.00| 1.00|1.00|
+----+------+------+----+
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens R.E. Boss
> Verzonden: donderdag 10 juni 2010 20:13
> Aan: 'Programming forum'
> Onderwerp: Re: [Jprogramming] Polynomial extrapolation
>
> The first problem I would solve by determining the polynomial through the
> initial points (k points give a pn of degree k) and then calculate the
> other
> points. Elementary math only.
>
>
> As far as your t is concerned, a more efficient solution is
>
> tb=. [: ;@{. [: ([ ((, {.) ; ]) 2 - /\])&>/^:(<:@#@;@{:) ({. ; ])
>
> tb ^&5[i.6
> 0 _1 30 _150 240 _120
>
> t ^&5[i.6
> 0 _1 30 _150 240 _120
>
> tb tb ^&5[i.6
> 0 1 32 243 1024 3125
>
> etcb=.{.&.:(tb :.tb)
>
> ts '1000 etc ^&5[i.6'
> 0.060576443 13902976
>
> ts '1000 etcb ^&5[i.6'
> 0.042477318 35200
>
> dspl rnkng scores '1000 etc ^&5[i.6'; '1000 etcb ^&5[i.6'
> +----+------+----+------+
> |rank|et*sz |time|size |
> +----+------+----+------+
> | 1 |598.25|1.51|394.97|
> +----+------+----+------+
> | 0 | 1.00|1.00| 1.00|
> +----+------+----+------+
>
>
> R.E. Boss
>
>
> > -----Oorspronkelijk bericht-----
> > Van: [email protected] [mailto:programming-
> > [email protected]] Namens Bo Jacoby
> > Verzonden: donderdag 10 juni 2010 10:54
> > Aan: Programming forum
> > Onderwerp: [Jprogramming] Polynomial extrapolation
> >
> > Hello my friends
> >
> > A program for polynomial extrapolation can be written
> >
> > etc=.{.&.:(t :.t=.[: {."1 (2-/\])^:([: i. #))
> >
> > For example, the first 21 square numbers are extrapolated from 3 square
> > numbers like this.
> >
> > 21 etc 0 1 4
> > 0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
> >
> > My first question is this: Can the program be written without naming the
> > intermediate verb (t) ?
> >
> > Note that t is an involution:
> > t t 0 1 4
> > 0 1 4
> > and the etc program just pads zeroes
> > 21 {. t 0 1 4
> > 0 _1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> > before transforming back.
> > t 21 {. t 0 1 4
> > 0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
> >
> > The transformation (t) creates a space-consuming intermediate matrix
> > (2-/\])^:([: i. #) 1 4 9
> > 1 4 9
> > _3 _5 0
> > 2 0 0
> > where only the first row is input and only the first column is output. I
> > want to compute in-place to save space:
> > 1, 4 9 --> 1 _3, _5 --> 1 _3 2
> > My second question: How is that done?
> >
> > Venlig hilsen, Bo
> >
> >
> >
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm