using System;
namespace Legalsoft.Truffer
{
///
/// 分段线性插值
/// Piecewise linear interpolation object.
/// Construct with x and y vectors, then call interp for interpolated values.
///
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]);
}
}
}
}
- using System;
-
- namespace Legalsoft.Truffer
- {
- ///
- /// 分段线性插值
- /// Piecewise linear interpolation object.
- /// Construct with x and y vectors, then call interp for interpolated values.
- ///
- 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]);
- }
- }
- }
- }