Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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);
return numeric.solve(A, b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment