1 文本格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// 分段线性插值
/// Piecewise linear interpolation object.
/// Construct with x and y vectors, then call interp for interpolated values.
/// </summary>
public class Linear_interp : Base_interp
{
public Linear_interp(double[] xv, double[] yv) : base(xv, yv[0], 2)
{
}
public override double rawinterp(int j, double x)
{
if (xx[j] == xx[j + 1])
{
return yy[j];
}
else
{
return yy[j] + ((x - xx[j]) / (xx[j + 1] - xx[j])) * (yy[j + 1] - yy[j]);
}
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// 分段线性插值
/// Piecewise linear interpolation object.
/// Construct with x and y vectors, then call interp for interpolated values.
/// </summary>
public class Linear_interp : Base_interp
{
public Linear_interp(double[] xv, double[] yv) : base(xv, yv[0], 2)
{
}
public override double rawinterp(int j, double x)
{
if (xx[j] == xx[j + 1])
{
return yy[j];
}
else
{
return yy[j] + ((x - xx[j]) / (xx[j + 1] - xx[j])) * (yy[j + 1] - yy[j]);
}
}
}
}