Thanks for the help, everyone!
Using Mike's solution - solving the linear system for the coefficients - I
rewrote np as follows and learned that I need more practice with \ on
matrices
NB. Calculate the coefficients aᵢ of the Newton basis polynomials
NB. by solving system of linear equations
nc=: (%. 1 ,. [: }:"1 [: */\"1 -/~ * +/\@=@i.@#)~
NB. Calculate the coefficients of the Newton polynomial by
NB. converting the summands aᵢ(x-x₀)…(x-xᵢ₋₁) from
NB. multiplier-and-roots to coefficients form and adding them up
np=: [: +/@,:/ [: p."1 (;/)@nc ,. a:&,@(<\)@}:@[
x=: _3r2 _3r4 0 3r4 3r2
y=: 3&o. x
load'plot'
plot (;(x np y)&p.) %&10 i:15
Raul's solution gave me the replacement for the loop I used in my original
code and I learned that I need more practice with the usage of ^:
NB. Calculate the coefficients aᵢ of the Newton basis polynomials
NB. using the topmost entries of the divided differences
dd=: (2 -~/\ ]) % [ ({: - {.)\~ 2 + -&#
nc=: [: {."1 dd ^:(i.@#@:+)
Btw. Both versions also worked with j701 on my iPhone.
For Hauke's solution I still need time to digest - I have to get more
familiar with (the definition of) adverbs.
Many thanks again for all the help.
Stefan.
On Sun, Oct 18, 2020 at 3:55 PM Raul Miller <[email protected]> wrote:
> One issue is that we need #@:+ instead of #@+ in earlier J versions.
>
> Thanks,
>
> --
> Raul
>
> On Sun, Oct 18, 2020 at 5:45 AM 'Michael Day' via Programming
> <[email protected]> wrote:
> >
> > Looks neat. I think it has to be square, and it doesn't need to be
> > non-singular:
> > eg,
> >
> > Here, y = x is a straight line, and 5 data points overspecify it! ...
> >
> > (,:(X np X)&p.) steps _1.5 1.5 5
> >
> > _1.5 _0.9 _0.3 0.3 0.9 1.5
> >
> > _1.5 _0.9 _0.3 0.3 0.9 1.5
> >
> >
> > Oddly enough, I tried it out first on my iPad, running J701. On that
> >
> > tablet I got :
> >
> >
> > ~. X np Y in J701/iPad !!! ~. to save lines
> > _14.1014
> >
> > I thought that was it for discrepancies. I haven't kept J7.01 on the
> > laptop,
> >
> > but I do still have J8.07. I've just checked and find the same result
> > there!
> >
> >
> > JVERSION
> >
> > Engine: j807/j64/windows
> >
> > Release-e: commercial/2019-11-04T09:51:03
> >
> > Library: 8.07.26
> >
> > Qt IDE: 1.7.9/5.9.6
> >
> > Platform: Win 64
> >
> > Installer: J807 install
> >
> > InstallPath: c:/d/j807
> >
> > Contact: www.jsoftware.com
> >
> >
> > ~. X np Y NB. in J807...
> > _14.1014
> >
> > Old J - odd/old results. I expect others will see why,
> >
> >
> > Cheers,
> >
> >
> > Mike
> >
> >
> >
> > On 17/10/2020 23:10, Raul Miller wrote:
> > > 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,
> > >
> >
> >
> >
> > --
> > 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm