Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ラグランジュ補間(と等価な多項式補間)
// ラグランジュ補間(と等価な多項式補間)
// 入力 N個の点列 points = [[x0,y0],[x1,x2],...,[xn-1,yn-1]]
// 出力 多項式の係数配列c
// y = c[0]*x^N-1 + c[1]*x^N-2 + ... + c[N-2]*x + c[N-1]
function lagrangeInterpolation(points) {
var dim=points.length;
var A=numeric.rep([dim, dim], 0);
var b=numeric.rep([dim], 0);
for(var i=0; i<dim; ++i) {
for(var j=0; j<dim; ++j) {
A[i][j]=Math.pow(points[i][0], dim-1-j);
}
b[i]=points[i][1];
}
return numeric.solve(A, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.