For what it's worth, here's an example of a "quite straightforward"
translation of the original 'np' to tacit form (assuming that the
newton matrix is always square -- I didn't spend enough time studying
here to feel comfortable leaving that assumption unstated, though I
did force a length error should that not be a valid assumption):

NB. divided differences
dd=: (2 -~/\ ]) % [ ({: - {.)\~ 2 + -&#

NB. Coefficients are the topmost entries
np=: [: {."1 dd ^:(i.@#@+)

X=: _3r2 _3r4 0 3r4 3r2
Y=: 3 o. X
load'plot stats'
plot(;(X np Y)&p.) steps _1.5 1.5 30

I hope this helps,

-- 
Raul

On Sat, Oct 17, 2020 at 2:14 PM 'Michael Day' via Programming
<[email protected]> wrote:
>
> This thread seems to have gone quiet,  but for what it's worth:
>
> Stefan Baumann had said - see below - that he had not found a way to
> avoid loops in deriving the coefficients.  I showed on 15/9 one way to
> derive
> the matrix described at
> https://en.wikipedia.org/wiki/Newton_polynomial#Main_idea
>
> Here's an implementation of the other approach,  described at
> https://en.wikipedia.org/wiki/Newton_polynomial#Application
>
> It uses power,  ^:  ,  which I suppose is a kind of loop,  so perhaps
> doesn't quite
> fit the bill!   ... and it's not fully tacit.
>
>     coeffs =: 4 : '{."1 }:@((x&(-/@([ }."0 1~ 1 _1 * >:@-&#)) %~ 2 -~/\
> ]) ^:a:) y'
>
> Using his example,
>
>     x coeffs y
> _14.10142 17.559765 _10.878424 4.8348551 0
>
> cf this tacitised version of what I sent earlier:
>
>     mat2coeffs =:     (%.(1 ,. }:"1@(*/\"1)@(-/~ * +/\@=@i.@#)))~
>
>     x mat2coeffs y
> _14.10142 17.559765 _10.878424 4.8348551 0
>
> It might be worth pointing out that this section of code,  (-/~ *
> +/\@=@i.@#) ,
> does the main work,  setting up an initial matrix:
>
>     (-/~ * +/\@=@i.@#) x   NB. fixed font looks ok as sent!
>    0   0   0   0 0
> 3r4   0   0   0 0
> 3r2 3r4   0   0 0
> 9r4 3r2 3r4   0 0
>    3 9r4 3r2 3r4 0
>
> There's probably a neater way to achieve this....
>
> Cheers,
>
> Mike
>
> On 15/10/2020 19:21, 'Michael Day' via Programming wrote:
> > It took me a while to see what was required using the matrix, M and
> > the derived coefficients, a.
> >
> > But this works ok.  I haven't turned the explicit code into a
> > function,  but that should be quite
> > straightforward.
> >
> > NB. fixed point font best past here....
> >    a =. y %. M =. 1,. }:"1 */\"1 (-/~ * +/\@:=@i.@#) x
> >    M
> > 1   0    0     0      0
> > 1 3r4    0     0      0
> > 1 3r2  9r8     0      0
> > 1 9r4 27r8 81r32      0
> > 1   3 27r4  81r8 243r32
> >    a
> > _14.10142 17.559765 _10.878424 4.8348551 0
> >
> >    6{."1 [n =: 1,}:*/\ x-~/steps _1.5 1.5 30  NB. n is Newton basis
> > form of new x
> > 1        1        1       1       1        1
> > 0      0.1      0.2     0.3     0.4      0.5
> > 0   _0.065    _0.11  _0.135   _0.14   _0.125
> > 0    0.091    0.143   0.162   0.154    0.125
> > 0 _0.19565 _0.29315 _0.3159 _0.2849 _0.21875
> >
> >    plot a +/ . * n
> >
> > Earlier,  I'd overlooked the (rather obvious!) fact that you need to
> > apply a to the Newton
> > basis form,  n here,  of your required prediction points,  not the
> > untransformed points.
> >
> > Mike
> >
> >
> > On 15/10/2020 14:50, Stefan Baumann wrote:
> >> Dear all.
> >> Recently I stumbled upon the Newton polynomial and took it as a
> >> practice to
> >> implement it without using loops, but failed. I first didn't get a
> >> grab on
> >> how to create the matrix used in
> >> https://en.wikipedia.org/wiki/Newton_polynomial#Main_idea, and
> >> eventually
> >> came up with code following
> >> https://en.wikipedia.org/wiki/Newton_polynomial#Application:
> >>
> >> NB. Newton polynomial
> >>
> >> np=: 4 : 0
> >>
> >> a=. {. y
> >>
> >> for_i. }.>:i.#x do.
> >>
> >> y=. (2 (-~)/\ y) % i ({:-{.)\ x NB. Divided differences
> >>
> >> a=. a, {. y NB. Coefficients are the topmost entries
> >>
> >> end.
> >>
> >> NB. Convert the summands aᵢ(x-x₀)…(x-xᵢ₋₁) of the polynomial
> >>
> >> NB. from multiplier-and-roots to coefficients form and add them up
> >>
> >> +/@,:/ p."1 (;/a) ,. (<''), }:<\ x
> >>
> >> )
> >>
> >> x=: _3r2 _3r4 0 3r4 3r2
> >>
> >> y=: 3&o. x
> >>
> >> load'plot'
> >>
> >> load'stats'
> >>
> >> plot (];(x np y)&p.) steps _1.5 1.5 30
> >>
> >> I also tried replacing the loop with fold F:. but again was not able
> >> to do
> >> so. Anyone out there who can enlighten me?
> >>
> >> Many thanks. Stefan.
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >
> >
>
>
> --
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to