Interpolate valueson the go
npm install @theiliad/interpolatejs
Lagrange interpolation to the rescue!
p(x) for your provided set of x and y-values, using the Lagrange basis polynomials.Using .evaluate() you can then provide an x-value to the function, and get an interpolated y-value.
bash
npm i --save @theiliad/interpolatejs
`Usage
import/require:
`js
import { interpolation, fraction } from "@theiliad/interpolatejs/index";const xValues = [fraction(1, 3), fraction(1, 4), 1];
const yValues = [2, -1, 7];
const pOfx = interpolation(xValues, yValues);
console.log("p(1/3) =", pOfx.evaluate(fraction(1, 3)));
// ==> p(1/3) = 2
`In-browser CDN Usage:
`html
``