只是搞乱了F#,我试图创建一个基于这个C#版本的基本拉格朗日插值函数(从C++ wiki条目复制):
double Lagrange(double[] pos, double[] val, double desiredPos)
{
double retVal = 0;
for (int i = 0; i < val.Length; ++i)
{
double weight = 1;
for (int j = 0; j < val.Length; ++j)
{
// The i-th term has to be skipped
if (j != i)
{
weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]);
}
}
retVal += weight * val[i];
}
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
使用我对F#和函数式编程的有限知识,我能想到的最好的是:
let rec GetWeight desiredPos i j (pos : …Run Code Online (Sandbox Code Playgroud)