Last active
August 29, 2015 14:13
-
-
Save sasekazu/2f43b02c100892a4cb52 to your computer and use it in GitHub Desktop.
ラグランジュ補間(と等価な多項式補間)
This file contains 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
// ラグランジュ補間(と等価な多項式補間) | |
// 入力 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