Let's say that you have a set of experimental values in the variable
'pairs', such that the X values are in the first row, and the Y values
are in the second row.

You could plot them like this:
   require'plot'
   plot j.//:~&.|: pairs

And, let's say that you want to find a line which best approximates
these pairs. For that, you could use:
   'X Y'=: pairs
   P=: Y %. X^/i.2

To compare the fit of the resulting line with your original data, you could use:
   plot (j.//:~&.|:pairs),: (/:~X) j. P p./:~X

(If your X values were ordered, you would not have to sort things each
time you wanted to plot them, but I wanted to show that that's not
necessary for the interpolation.)

If you wanted to fit to a higher order polynomial, you could do that
instead, for example:
   P3=: Y %. X^/i.3

However, beware that high order polynomials tend to "overfit" -- they
tend to emphasize irrelevant details. There's things you can do, if
you could collect sample Y values at specific X values, to get decent
complex approximations, but that's getting out of scope for what I
think you're asking for.

I hope this helps,

-- 
Raul


On Fri, May 7, 2021 at 3:48 AM 'Rudolf Sykora' via General
<[email protected]> wrote:
>
> Dear list,
>
>
> I tried to search for some implementation of 'interpolation', but
> failed...
>
> I have a series of (experimentally) measured values (pairs) like
> (x1,y1), (x2,y2), ..., (xN,yN). The x values are not equidistant. I need
> to create a new set (u1,v1), (u2,v2), ..., (uM, vM), with u values being
> equidistant, and interpolate (linearly, say; or more elaborately later)
> in between. Does anybody have a code snippet doing this?
>
> Thanks!
>
>
> Best regards
> Ruda
> ----------------------------------------------------------------------
> 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