Public
Edited
Aug 1, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
L = (j, n, x, points) => {
let prevLagrange = 1;
for (let k=0; k<n; k++) {
if (k!=j && points[j][0]!=points[k][0] ) {
prevLagrange = prevLagrange*(x-points[k][0])/(points[j][0]-points[k][0])
}
}
return prevLagrange
}
Insert cell
polynomial = (points, x) => {
let poly = 0;
for (let j=0; j < points.length; j++) {
poly += L(j, points.length, x, points)*points[j][1]
}
return poly
}
Insert cell
lagrangePolynom = {
const minX = d3.min(points.map((p) => p[0]));
const maxX = d3.max(points.map((p) => p[0]));
const domain = maxX-minX;
const curvePoints = [];
const startTime = new Date();
for (let x = minX; x <= maxX; x+=domain/fineness) {
curvePoints.push([x, polynomial(points, x)])
}
const endTime = new Date();
mutable calculatePoints = endTime-startTime;
return curvePoints
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more