Last active
April 28, 2023 20:31
-
-
Save dimdenGD/808ba1a59a23e8bb198285c4fbef9502 to your computer and use it in GitHub Desktop.
Lagrange Interpolation in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lagrangeInterpolation(xs, ys, x) { | |
let y = 0; | |
for(let i = 0; i < xs.length; i++) { | |
let t = 1; | |
for(let j = 0; j < xs.length; j++) { | |
if(j !== i) { | |
t *= (x - xs[j]) / (xs[i] - xs[j]); | |
} | |
} | |
y += t * ys[i]; | |
} | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment