## Spline插值C#实现

pollux 发布于 2014/11/11 14:26

/// <summary>
///  x length=n*m
///  y length=n*m
///  z length=n*m
///  z(i)=f(x(i),y(i)) i=0.....n*m-1
/// </summary>
private void Spline_c()
{
int n = 10, m = 12;
int len = n * m;
double[] x = new double[len];
int xIndex = 0;
double[] y = new double[len];
int yIndex = 0;

double[] f = new double[len];
int fIndex = 0;

for (int i1 = 0; i1 < n; i1++)
{
for (int j1 = 0; j1 < m; j1++)
{
x[xIndex] = j1;
xIndex++;
y[yIndex] =i1*new Random().Next();
yIndex++;
f[fIndex] = 100*new Random().NextDouble();
fIndex++;
}
}
// spline  f(x,y,f)  如何实现Spline插值
}

0
p

/**
* first D elements store D values at (X[0],Y[0])
* next D elements store D values at (X[1],Y[0])
*
* * ...
* next D elements store D values at (X[0],Y[1])
* next D elements store D values at (X[1],Y[1])
*/
double[] x = new double[] { 2,5};
double[] y = new double[] { 1,2};
double[] f = new double[] { 1, 2, 3, 4};
alglib.spline2dinterpolant s;
double[] vr;
alglib.spline2dbuildbicubicv(x, 2, y, 2, f, 1, out s);
alglib.spline2dcalcv(s, 0.5, 0.3, out vr);
System.Console.WriteLine("{0}", alglib.ap.format(vr, 4));

0
p